<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>David Pratt &#187; jquery</title> <atom:link href="http://daipratt.co.uk/tag/jquery/feed/" rel="self" type="application/rss+xml" /><link>http://daipratt.co.uk</link> <description>Concerned about Website Construction &#38; SEO</description> <lastBuildDate>Wed, 25 Jan 2012 07:16:58 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.4</generator> <item><title>Notes about combining jQuery and Greasemonkey</title><link>http://daipratt.co.uk/notes-about-combining-jquery-and-greasemonkey/</link> <comments>http://daipratt.co.uk/notes-about-combining-jquery-and-greasemonkey/#comments</comments> <pubDate>Thu, 05 Nov 2009 16:10:32 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[greasemonkey]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=595</guid> <description><![CDATA[Greasemonkey doesn't inherit the jQuery library if it is just loaded onto the web page as normal. To use jQuery methods from GreaseMonkey code, you need to do this bit of coding magic...]]></description> <content:encoded><![CDATA[<p>Having just written my first Greasemonkey script in a while, I thought I might share some of my learning&#8217;s!</p><h4>Include jQuery by using the @require statement</h4><p>Greasemonkey doesn&#8217;t inherit the jQuery library if it is just loaded onto the web page as normal, you need to figure out a way of allowing your Greasemonkey script to use it another way.  If I had read the Greasemonkey docs from the off, I would have stumbled across the correct method within about 5 minutes, but I didn&#8217;t, I just dived straight on in and it took a lot longer&#8230;</p><p>To add jQuery, include the @require line in your script header.  This needs to be done before you install the script and cannot be done retrospectively.</p><pre class="brush: javascript">
// ==UserScript==
// @name          Awesome Tool
// @namespace     http://daipratt.co.uk
// @description   Top Secret
// @include       http://daipratt.co.uk/*
// @require       http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
// ==/UserScript==
</pre><h4>Make sure that your Greasemonkey script ends in <em>.user.js</em></h4><p>If it doesn&#8217;t, you&#8217;ll spend ages wondering why it won&#8217;t let you install a local script.</p><h4>Store session data</h4><p>You don&#8217;t need an elaborate method of storing data for retrieval between sessions and pages, there are a pair of functions built into Greasemonkey that do the job nicely:</p><pre class="brush: javascript">
//Sets a key value pair that Greasemonkey should store
GM_setValue(key, value);
//Retrieves a value, given an existing key
var v = GM_getValue(key);
</pre>]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/notes-about-combining-jquery-and-greasemonkey/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
