<?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>umkk.eu &#187; mousehunt</title>
	<atom:link href="http://umkk.eu/tag/mousehunt/feed/" rel="self" type="application/rss+xml" />
	<link>http://umkk.eu</link>
	<description>you can also go there !</description>
	<lastBuildDate>Fri, 25 Jun 2010 16:00:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Greasemonkey, create a options panel using jQuery</title>
		<link>http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/</link>
		<comments>http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 07:06:20 +0000</pubDate>
		<dc:creator>sergiu</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript cookie]]></category>
		<category><![CDATA[javascript json]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[mousehunt]]></category>

		<guid isPermaLink="false">http://umkk.eu/?p=181</guid>
		<description><![CDATA[Hi, this tutorial is also based on the mouse hunt script "facebook mousehunt improvements" created by me, and in this one i will explain how to create an options panel (only check boxes at this time) and save it.
Here is my final result with this script :
If you want to try this, remember to load [...]


Related posts:<ol><li><a href='http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/' rel='bookmark' title='Permanent Link: GreaseMonkey, Jquery and the greatest mouse hunt script.'>GreaseMonkey, Jquery and the greatest mouse hunt script.</a></li>
<li><a href='http://umkk.eu/autoupdate-on-greasemonkey-script/10/' rel='bookmark' title='Permanent Link: Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.'>Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.</a></li>
<li><a href='http://umkk.eu/jquery-popups-wizard-web-2-0-ideea-and-usability/10/' rel='bookmark' title='Permanent Link: jQuery popups wizard, web 2.0 ideea and usability'>jQuery popups wizard, web 2.0 ideea and usability</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div id="attachment_197" class="wp-caption aligncenter" style="width: 263px"><a href="http://umkk.eu/wp-content/uploads/2009/10/2009-10-22_1010.png"><img class="size-full wp-image-197" title="2009-10-22_1010" src="http://umkk.eu/wp-content/uploads/2009/10/2009-10-22_1010.png" alt="greasemonkey options panel with jquery" width="253" height="222" /></a><p class="wp-caption-text">greasemonkey options panel with jquery</p></div>
<p>Hi, this tutorial is also based on the mouse hunt script "facebook mousehunt improvements" created by me, and in this one i will explain how to create an options panel (only check boxes at this time) and save it.</p>
<p>Here is my final result with this script :</p>
<p>If you want to try this, remember to load jquery correctly as described in <a title="how to load jquery in greasemonkey" href="http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/" target="_self">this post</a> at number #4.</p>
<p>First of all, the data is saved in a cookie as JSON, i have an object where i save all my data and i save that object as JSON on a cookie. Because javascript does not know to convert an object to a json string i used a class which does that, the class is not created by me, I just use it as it is, here is the fie : <a href="http://umkk.eu/wp-content/uploads/2009/10/json.js">json </a><br />
I copied the content of the file inside my script so i don't have to load it remotely, anyway it's just a line <img src='http://umkk.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , so you should also copy this at the beginning of your greasemonkey script.</p>
<p>As i said the data is saved as cookie, here is the functions which will create, and read a cookie :</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> createCookie<span style="color: #66cc66;">&#40;</span><span style="color: #000066;">name</span>,value,days<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>days<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> date = <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		date.<span style="color: #006600;">setTime</span><span style="color: #66cc66;">&#40;</span>date.<span style="color: #006600;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #66cc66;">&#40;</span>days*<span style="color: #CC0000;">24</span>*<span style="color: #CC0000;">60</span>*<span style="color: #CC0000;">60</span>*<span style="color: #CC0000;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #003366; font-weight: bold;">var</span> expires = <span style="color: #3366CC;">&quot;; expires=&quot;</span>+date.<span style="color: #006600;">toGMTString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #003366; font-weight: bold;">var</span> expires = <span style="color: #3366CC;">&quot;&quot;</span>;
	document.<span style="color: #006600;">cookie</span> = <span style="color: #000066;">name</span>+<span style="color: #3366CC;">&quot;=&quot;</span>+value+expires+<span style="color: #3366CC;">&quot;; path=/&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> readCookie<span style="color: #66cc66;">&#40;</span><span style="color: #000066;">name</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> nameEQ = <span style="color: #000066;">name</span> + <span style="color: #3366CC;">&quot;=&quot;</span>;
	<span style="color: #003366; font-weight: bold;">var</span> ca = document.<span style="color: #006600;">cookie</span>.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">';'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i=<span style="color: #CC0000;">0</span>;i &amp;lt; ca.<span style="color: #006600;">length</span>;i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> c = ca<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
		<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #66cc66;">&#40;</span>c.<span style="color: #006600;">charAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#41;</span>==<span style="color: #3366CC;">' '</span><span style="color: #66cc66;">&#41;</span> c = c.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">1</span>,c.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>c.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span>nameEQ<span style="color: #66cc66;">&#41;</span> == <span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> c.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span>nameEQ.<span style="color: #006600;">length</span>,c.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">null</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Also in my program i read the cookie when the script starts so the data object "myData" in my case will be populated and available in the entire script :</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> myData = <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>readCookie<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;gm_pl_data&quot;</span><span style="color: #66cc66;">&#41;</span>!=<span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		myData = JSON.<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span>readCookie<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;gm_pl_data&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #009900; font-style: italic;">//if there is no cookie we initialize it</span>
		initCookie<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span>err<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	initCookie<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>In my case gm_pl_data is the name of the cookie in which i save the data. Here is the initCookie() function, this will just initialize the objects inside the myData object :</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> initCookie <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	myData = <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	myData.<span style="color: #006600;">allLogs</span> = <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	myData.<span style="color: #006600;">allChese</span> = <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	savePersistentData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//will be valid 1000000 days</span>
<span style="color: #003366; font-weight: bold;">function</span> savePersistentData <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	createCookie<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;gm_pl_data&quot;</span>,JSON.<span style="color: #006600;">stringify</span><span style="color: #66cc66;">&#40;</span>myData<span style="color: #66cc66;">&#41;</span>,<span style="color: #CC0000;">1000000</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>I let in there all my init objects so io can see how to initialize them if you have more.  You can also notice the savePersistentData function which will update the cookie and save the persistent data <img src='http://umkk.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Until here we only had generic information about how data is saved and the functions which save the data. Now I'll go in more details for the actual options panel. The panel is actually a div in which you can enter any thing you want, but the values of the check boxes will be saved  and their status restored when the page reloads.</p>
<p>So here is how my panel looks like :</p>
<pre class="javascript">jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_options_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Show the timer
&lt;input id=&quot;</span>gm_pl_check_show_timer<span style="color: #3366CC;">&quot; type=&quot;</span>checkbox<span style="color: #3366CC;">&quot; /&gt;
&quot;</span><span style="color: #66cc66;">&#41;</span>;
	jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_options_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Automaticaly sound the horn
&lt;input id=&quot;</span>gm_pl_check_sound_horn<span style="color: #3366CC;">&quot; type=&quot;</span>checkbox<span style="color: #3366CC;">&quot; /&gt;
&quot;</span><span style="color: #66cc66;">&#41;</span>;
	jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_options_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;&lt;strong&gt;Kings rewared options&lt;/strong&gt;
&quot;</span><span style="color: #66cc66;">&#41;</span>;
	jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_options_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Play youtube on kings reward
&lt;input id=&quot;</span>gm_pl_play_sound_on_reward<span style="color: #3366CC;">&quot; type=&quot;</span>checkbox<span style="color: #3366CC;">&quot; /&gt;
&quot;</span><span style="color: #66cc66;">&#41;</span>;
	jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_options_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Play midi on kings reward
&lt;input id=&quot;</span>gm_pl_play_sound_midi_on_reward<span style="color: #3366CC;">&quot; type=&quot;</span>checkbox<span style="color: #3366CC;">&quot; /&gt;
&quot;</span><span style="color: #66cc66;">&#41;</span>;
	jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_options_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Show alert on kings rewared
&lt;input id=&quot;</span>gm_pl_show_alert_on_reward<span style="color: #3366CC;">&quot; type=&quot;</span>checkbox<span style="color: #3366CC;">&quot; /&gt;
&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	setOptions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_options_container input&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>saveOptions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>in this case the id of the div inside which i enter the options is "gm_pl_options_container", and i you can see that setOptions() is called, this will set the default options for the check boxes based on the myData object, here's the code :</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> setOptions <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> myData<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;options&quot;</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #66cc66;">&#40;</span>i <span style="color: #000066; font-weight: bold;">in</span> myData<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;options&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span>+i<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">attr</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;checked&quot;</span>,myData<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;options&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>In my case the options are saved in myData["options"] the myData object is the main script object and all the scripts data is saved there, not just the options.</p>
<p>And after the setOptions function is called we also have an intresting line, this will add an onclick function to each input on that div, and in this function we call saveOptions(), this function will get all the inputs in that div, and save the values in myData['options'] object, and also write the cookie to make sure that the values are not lost on page refresh :</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> saveOptions <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> myData<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;options&quot;</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		myData<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;options&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	jQuery.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span>jQuery<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_options_container input&quot;</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">checked</span> == <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			myData<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;options&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #003366; font-weight: bold;">true</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #66cc66;">&#123;</span>
			myData<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;options&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #003366; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	savePersistentData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Every thing you have to do now is use those options, there are 2 ways to do this, you can check the status of the check box or you can get the value from the myData['options'] object, they are the same, i use the object :</p>
<pre class="javascript"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>myData<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">&quot;options&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">'gm_pl_show_alert_on_reward'</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;You have a king's reward!&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span></pre>
<p>And this is it, if you have any questions let me know, and remember, if you use mouse hunt don't forget to use my script :<a href="http://userscripts.org/scripts/show/57446" target="_blank"> Facebook mousehunt improvements</a></p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-caring">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;title=Greasemonkey%2C+create+a+options+panel+using+jQuery" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;title=Greasemonkey%2C+create+a+options+panel+using+jQuery" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;title=Greasemonkey%2C+create+a+options+panel+using+jQuery&amp;desc=%0D%0A%0D%0AHi%2C%20this%20tutorial%20is%20also%20based%20on%20the%20mouse%20hunt%20script%20%22facebook%20mousehunt%20improvements%22%20created%20by%20me%2C%20and%20in%20this%20one%20i%20will%20explain%20how%20to%20create%20an%20options%20panel%20%28only%20check%20boxes%20at%20this%20time%29%20and%20save%20it.%0D%0A%0D%0AHere%20is%20my%20final%20result%20with%20this%20script%20%3A%0D%0A%0D%0AIf%20you%20want%20to%20try%20this%2C%20remember%20" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;t=Greasemonkey%2C+create+a+options+panel+using+jQuery" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=Greasemonkey%2C+create+a+options+panel+using+jQuery&amp;body=Link: http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A %0D%0A%0D%0AHi%2C%20this%20tutorial%20is%20also%20based%20on%20the%20mouse%20hunt%20script%20%22facebook%20mousehunt%20improvements%22%20created%20by%20me%2C%20and%20in%20this%20one%20i%20will%20explain%20how%20to%20create%20an%20options%20panel%20%28only%20check%20boxes%20at%20this%20time%29%20and%20save%20it.%0D%0A%0D%0AHere%20is%20my%20final%20result%20with%20this%20script%20%3A%0D%0A%0D%0AIf%20you%20want%20to%20try%20this%2C%20remember%20" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;title=Greasemonkey%2C+create+a+options+panel+using+jQuery" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;bm_description=Greasemonkey%2C+create+a+options+panel+using+jQuery&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;title=Greasemonkey%2C+create+a+options+panel+using+jQuery" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;title=Greasemonkey%2C+create+a+options+panel+using+jQuery" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/&amp;title=Greasemonkey%2C+create+a+options+panel+using+jQuery" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Greasemonkey%2C+create+a+options+panel+using+jQuery+-+http://b2l.me/6hn7t&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>



<p>Related posts:<ol><li><a href='http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/' rel='bookmark' title='Permanent Link: GreaseMonkey, Jquery and the greatest mouse hunt script.'>GreaseMonkey, Jquery and the greatest mouse hunt script.</a></li>
<li><a href='http://umkk.eu/autoupdate-on-greasemonkey-script/10/' rel='bookmark' title='Permanent Link: Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.'>Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.</a></li>
<li><a href='http://umkk.eu/jquery-popups-wizard-web-2-0-ideea-and-usability/10/' rel='bookmark' title='Permanent Link: jQuery popups wizard, web 2.0 ideea and usability'>jQuery popups wizard, web 2.0 ideea and usability</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.</title>
		<link>http://umkk.eu/autoupdate-on-greasemonkey-script/10/</link>
		<comments>http://umkk.eu/autoupdate-on-greasemonkey-script/10/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 09:29:34 +0000</pubDate>
		<dc:creator>sergiu</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[auto update]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mousehunt]]></category>

		<guid isPermaLink="false">http://umkk.eu/?p=153</guid>
		<description><![CDATA[As you can see on my previews post, i created a great mouse hunt script using grease monkey and jQuery, in this post i will explain how the update is done.
The idea behind this is, that the user will install the script and most probably will never go back and check if there is an [...]


Related posts:<ol><li><a href='http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/' rel='bookmark' title='Permanent Link: GreaseMonkey, Jquery and the greatest mouse hunt script.'>GreaseMonkey, Jquery and the greatest mouse hunt script.</a></li>
<li><a href='http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/' rel='bookmark' title='Permanent Link: Greasemonkey, create a options panel using jQuery'>Greasemonkey, create a options panel using jQuery</a></li>
<li><a href='http://umkk.eu/jquery-popups-wizard-web-2-0-ideea-and-usability/10/' rel='bookmark' title='Permanent Link: jQuery popups wizard, web 2.0 ideea and usability'>jQuery popups wizard, web 2.0 ideea and usability</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>As you can see on my previews post, i created a great mouse hunt script using grease monkey and jQuery, in this post i will explain how the update is done.</p>
<p>The idea behind this is, that the user will install the script and most probably will never go back and check if there is an update to that script, so you, the developer, will have to fix this problem for the user. I didn't wanted to automatically install software or updates on a users PC so i'm notifying the user that there is an update available, so he can install it by hand (only click on the link).</p>
<p>There are 2 parts for this, the Javascript part (inside the greasemokney script) and the server part (php in my case). The principle is simple, we have a variable inside the gresemonkey script which will contain the version of that script :</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> cVersion = <span style="color: #3366CC;">&quot;1.14b&quot;</span>;</pre>
<p>and we have a function which will call an url giving that version as a parameter :</p>
<pre class="javascript"><span style="color: #009900; font-style: italic;">//check if a new version is availble.</span>
	GM_xmlhttpRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>
method: <span style="color: #3366CC;">'GET'</span>,
url: <span style="color: #3366CC;">'http://path.to.your.script.php?version='</span>+cVersion,
headers: <span style="color: #66cc66;">&#123;</span>
<span style="color: #3366CC;">'User-agent'</span>: <span style="color: #3366CC;">'Mozilla/4.0 (compatible) Greasemonkey'</span>,
<span style="color: #3366CC;">'Accept'</span>: <span style="color: #3366CC;">'application/atom+xml,application/xml,text/xml'</span>,
<span style="color: #66cc66;">&#125;</span>,
<span style="color: #000066;">onload</span>: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>responseDetails<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_version_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>responseDetails.<span style="color: #006600;">responseText</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>What this function does is pretty straight forward, will call an url (passing the script's version as a parameter) and put all the returning content (presumed html) inside a div.</p>
<p>Now, we have the server script, which we called earlier. This script also has a variable inside :</p>
<pre class="php"><span style="color: #0000ff;">$local_version</span> = <span style="color: #ff0000;">&quot;1.14b&quot;</span>;</pre>
<p>which contains the latest version of the script. This script is also pretty straight forward, will compare the latest version of the script, defined here, with the version provided as a parameter, and based on that will return an html, here is the entire script :</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #0000ff;">$local_version</span> = <span style="color: #ff0000;">&quot;1.14b&quot;</span>;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'version'</span><span style="color: #66cc66;">&#93;</span>!= <span style="color: #0000ff;">$local_version</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;
&lt;div style='padding:3px'&gt;
	A new version of this script is available.&lt;br&gt;
	Click &lt;a href='http://userscripts.org/scripts/source/57446.user.js'&gt;here to upgrade&lt;/a&gt;
	&lt;/div&gt;
&nbsp;
	&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;your script is up to date ($local_version)&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>And this is it.<br />
If you don't want to use Jquery, no problem you will have to replace this :</p>
<pre class="javascript"> $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#gm_pl_version_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>responseDetails.<span style="color: #006600;">responseText</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>with :</p>
<pre class="javascript">document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;gm_pl_version_container&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span><span style="color: #66cc66;">&#40;</span>responseDetails.<span style="color: #006600;">responseText</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>where gm_pl_version_container is the id of the element where you want to insert the content.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-caring">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://umkk.eu/autoupdate-on-greasemonkey-script/10/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;title=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script." rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;title=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script." rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;title=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script.&amp;desc=As%20you%20can%20see%20on%20my%20previews%20post%2C%20i%20created%20a%20great%20mouse%20hunt%20script%20using%20grease%20monkey%20and%20jQuery%2C%20in%20this%20post%20i%20will%20explain%20how%20the%20update%20is%20done.%0D%0A%0D%0AThe%20idea%20behind%20this%20is%2C%20that%20the%20user%20will%20install%20the%20script%20and%20most%20probably%20will%20never%20go%20back%20and%20check%20if%20there%20is%20an%20update%20to%20that%20s" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;t=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script." rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script.&amp;body=Link: http://umkk.eu/autoupdate-on-greasemonkey-script/10/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A As%20you%20can%20see%20on%20my%20previews%20post%2C%20i%20created%20a%20great%20mouse%20hunt%20script%20using%20grease%20monkey%20and%20jQuery%2C%20in%20this%20post%20i%20will%20explain%20how%20the%20update%20is%20done.%0D%0A%0D%0AThe%20idea%20behind%20this%20is%2C%20that%20the%20user%20will%20install%20the%20script%20and%20most%20probably%20will%20never%20go%20back%20and%20check%20if%20there%20is%20an%20update%20to%20that%20s" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;title=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script." rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;bm_description=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script.&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;title=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script." rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;title=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script." rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://umkk.eu/autoupdate-on-greasemonkey-script/10/&amp;title=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script." rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://umkk.eu/autoupdate-on-greasemonkey-script/10/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Autoupdate+on+greasemonkey+script%2C+example+from+%22mousehunt+improvements%22+script.%5B..%5D+-+http://b2l.me/6hmcD&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>



<p>Related posts:<ol><li><a href='http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/' rel='bookmark' title='Permanent Link: GreaseMonkey, Jquery and the greatest mouse hunt script.'>GreaseMonkey, Jquery and the greatest mouse hunt script.</a></li>
<li><a href='http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/' rel='bookmark' title='Permanent Link: Greasemonkey, create a options panel using jQuery'>Greasemonkey, create a options panel using jQuery</a></li>
<li><a href='http://umkk.eu/jquery-popups-wizard-web-2-0-ideea-and-usability/10/' rel='bookmark' title='Permanent Link: jQuery popups wizard, web 2.0 ideea and usability'>jQuery popups wizard, web 2.0 ideea and usability</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://umkk.eu/autoupdate-on-greasemonkey-script/10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GreaseMonkey, Jquery and the greatest mouse hunt script.</title>
		<link>http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/</link>
		<comments>http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 06:35:09 +0000</pubDate>
		<dc:creator>sergiu</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mousehunt]]></category>

		<guid isPermaLink="false">http://umkk.eu/?p=145</guid>
		<description><![CDATA[I started using mouse hunt a while ago... and really enjoy it, i loved when i got a new trap and i could buy more cheese, more traps... and craft more items, but as time passed along i got bored with that and I just wanted to catch as many mice as possible, and be [...]


Related posts:<ol><li><a href='http://umkk.eu/autoupdate-on-greasemonkey-script/10/' rel='bookmark' title='Permanent Link: Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.'>Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.</a></li>
<li><a href='http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/' rel='bookmark' title='Permanent Link: Greasemonkey, create a options panel using jQuery'>Greasemonkey, create a options panel using jQuery</a></li>
<li><a href='http://umkk.eu/jquery-popups-wizard-web-2-0-ideea-and-usability/10/' rel='bookmark' title='Permanent Link: jQuery popups wizard, web 2.0 ideea and usability'>jQuery popups wizard, web 2.0 ideea and usability</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I started using mouse hunt a while ago... and really enjoy it, i loved when i got a new trap and i could buy more cheese, more traps... and craft more items, but as time passed along i got bored with that and I just wanted to catch as many mice as possible, and be fast in what i do, also i wanted to have a script that sounds the horn and let me know when a king's reward has appeared, so i decided to create my own mouse hunt script, the greatest mouse hunt script ever created...</p>
<p>I started working on ma spare time in this... was not easy because some things ware hard to test... bunt eventually i did it.</p>
<p>You can see the script here : http://userscripts.org/scripts/show/57446 the script has been around  for about a month and already has 1200 installs and going up, and it's becoming "the mouse hunt script" <img src='http://umkk.eu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
<p>Now i will explain some of the problems i encountered on creating the script.</p>
<p>1. Saving persistent data, grease monkey does not have a very good way for this, so i decided to create an object where i save all the data and then save the object as JSON in a cookie</p>
<p>2. Updates, i was thinking that it would be nice to notify users when an update is available,  so i did this by creating a .php file in a server and store there the latest version number, the script checks that version with it's current version and if is different will show a message</p>
<p>3. Passing parameters on a function attached to an event, this was the most tricky one... was pretty complicated... here is the solution :</p>
<pre class="javascript">$.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;.huntername&quot;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>i,o<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> id = <span style="color: #CC0000;">0</span>;
			<span style="color: #003366; font-weight: bold;">var</span> childs = $<span style="color: #66cc66;">&#40;</span>o<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #003366; font-weight: bold;">var</span> link = $<span style="color: #66cc66;">&#40;</span>childs<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">attr</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> = $<span style="color: #66cc66;">&#40;</span>childs<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			id = link.<span style="color: #006600;">substr</span><span style="color: #66cc66;">&#40;</span>link.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #CC0000;">+1</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			$<span style="color: #66cc66;">&#40;</span>o<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span>o<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #3366CC;">&quot;&lt;a id=&quot;</span>gmpl_af_&amp;quot;+i+&amp;quot;<span style="color: #3366CC;">&quot; onclick=&quot;</span><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #3366CC;">&quot; href=&quot;</span>#<span style="color: #3366CC;">&quot;&gt;(add to links)&lt;/a&gt;&quot;</span><span style="color: #66cc66;">&#41;</span>;
			_e<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;gmpl_af_&quot;</span>+i+<span style="color: #3366CC;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span>,<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>gmpl_addFriend<span style="color: #66cc66;">&#40;</span>id,<span style="color: #000066;">name</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#125;</span>,<span style="color: #003366; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>4. How to use jquery in a grese monkey script, actually for this i fond the solution somewhere on the internet... : http://joanpiedra.com/jquery/greasemonkey/</p>
<pre class="javascript"><span style="color: #009900; font-style: italic;">// Add jQuery</span>
    <span style="color: #003366; font-weight: bold;">var</span> GM_JQ = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #66cc66;">&#41;</span>;
    GM_JQ.<span style="color: #006600;">src</span> = <span style="color: #3366CC;">'http://jquery.com/src/jquery-latest.js'</span>;
    GM_JQ.<span style="color: #006600;">type</span> = <span style="color: #3366CC;">'text/javascript'</span>;
    document.<span style="color: #006600;">getElementsByTagName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>GM_JQ<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// Check if jQuery's loaded</span>
    <span style="color: #003366; font-weight: bold;">function</span> GM_wait<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> unsafeWindow.<span style="color: #006600;">jQuery</span> == <span style="color: #3366CC;">'undefined'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> window.<span style="color: #006600;">setTimeout</span><span style="color: #66cc66;">&#40;</span>GM_wait,<span style="color: #CC0000;">100</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span> $ = unsafeWindow.<span style="color: #006600;">jQuery</span>; letsJQuery<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
    GM_wait<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// All your GM code must be inside this function</span>
    <span style="color: #003366; font-weight: bold;">function</span> letsJQuery<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">// check if the dollar (jquery) function works</span>
    <span style="color: #66cc66;">&#125;</span></pre>
<p>And all your code should go where the alert($) is. Only if you have some functions you should put them outside that function.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-caring">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;title=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script." rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;title=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script." rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;title=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script.&amp;desc=I%20started%20using%20mouse%20hunt%20a%20while%20ago...%20and%20really%20enjoy%20it%2C%20i%20loved%20when%20i%20got%20a%20new%20trap%20and%20i%20could%20buy%20more%20cheese%2C%20more%20traps...%20and%20craft%20more%20items%2C%20but%20as%20time%20passed%20along%20i%20got%20bored%20with%20that%20and%20I%20just%20wanted%20to%20catch%20as%20many%20mice%20as%20possible%2C%20and%20be%20fast%20in%20what%20i%20do%2C%20also%20i%20wanted%20to" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;t=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script." rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script.&amp;body=Link: http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%20started%20using%20mouse%20hunt%20a%20while%20ago...%20and%20really%20enjoy%20it%2C%20i%20loved%20when%20i%20got%20a%20new%20trap%20and%20i%20could%20buy%20more%20cheese%2C%20more%20traps...%20and%20craft%20more%20items%2C%20but%20as%20time%20passed%20along%20i%20got%20bored%20with%20that%20and%20I%20just%20wanted%20to%20catch%20as%20many%20mice%20as%20possible%2C%20and%20be%20fast%20in%20what%20i%20do%2C%20also%20i%20wanted%20to" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;title=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script." rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;bm_description=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script.&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;title=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script." rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;title=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script." rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/&amp;title=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script." rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=GreaseMonkey%2C+Jquery+and+the+greatest+mouse+hunt+script.+-+http://b2l.me/6hkkv&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>



<p>Related posts:<ol><li><a href='http://umkk.eu/autoupdate-on-greasemonkey-script/10/' rel='bookmark' title='Permanent Link: Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.'>Autoupdate on greasemonkey script, example from &#8220;mousehunt improvements&#8221; script.</a></li>
<li><a href='http://umkk.eu/greasemonkey-create-a-options-panel-using-jquery/10/' rel='bookmark' title='Permanent Link: Greasemonkey, create a options panel using jQuery'>Greasemonkey, create a options panel using jQuery</a></li>
<li><a href='http://umkk.eu/jquery-popups-wizard-web-2-0-ideea-and-usability/10/' rel='bookmark' title='Permanent Link: jQuery popups wizard, web 2.0 ideea and usability'>jQuery popups wizard, web 2.0 ideea and usability</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://umkk.eu/greasemonkey-jquery-and-the-greatest-mouse-hunt-script/10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
