<?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>occasionally useful &#187; scripts</title>
	<atom:link href="http://blog.maxaller.name/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.maxaller.name</link>
	<description>ruby, ubuntu, etc</description>
	<lastBuildDate>Mon, 06 Sep 2010 03:30:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Accessing GM_xmlhttprequest from event handlers bound by jQuery</title>
		<link>http://blog.maxaller.name/2009/01/accessing-gm_xmlhttprequest-from-event-handlers-bound-by-jquery/</link>
		<comments>http://blog.maxaller.name/2009/01/accessing-gm_xmlhttprequest-from-event-handlers-bound-by-jquery/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 05:42:05 +0000</pubDate>
		<dc:creator>Max</dc:creator>
				<category><![CDATA[jquery]]></category>
		<category><![CDATA[musing]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://giftswappo.com/wordpress/?p=58</guid>
		<description><![CDATA[So I like jQuery. And I like Greasemonkey. I especially like the ability of Greasemonkey's ajax calls to go cross-domain. But how do I get access to this functionality in my event handlers? Calling GM_xmlhttprequest in a method that doesn't execute while the Greasemonkey sandbox is still alive doesn't work. At first I didn't think [...]]]></description>
			<content:encoded><![CDATA[<p>So I like jQuery.  And I like Greasemonkey.  I especially like the ability of Greasemonkey's ajax calls to go cross-domain.  But how do I get access to this functionality in my event handlers?  Calling GM_xmlhttprequest in a method that doesn't execute while the Greasemonkey sandbox is still alive doesn't work.  At first I didn't think it was possible, but I discovered a way...using setInterval.</p>
<p><span id="more-58"></span>So here's the problem.  You want something like this:</p>
<pre lang="Javascript">$(function(){
  $("a").click(function(){
    GM_xmlhttprequest({url: "http://www.google.com/", method: 'GET'});
  });
});</pre>
<p>or something, right?  But that doesn't work because by the time the $'s DOM ready event fired, Greasemonkey is <em>gone</em>.  So what do you do?  Well...keep Greasemonkey around, but in a limited capacity.  Okay okay, here's the code:</p>
<pre lang="Javascript">var ajaxQueue = [];
var processAjaxQueue = function(){
  if (ajaxQueue.length > 0) {
    for (ajax in ajaxQueue) {
      var obj = ajaxQueue[ajax];
      // http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html
      GM_xmlhttpRequest(obj);
    }
    ajaxQueue = [];
  }
}
setInterval(function(){
  processAjaxQueue();
}, 100);

function gmAjax(obj){
  ajaxQueue.push(obj);
}</pre>
<p>So now you call gmAjax instead of GM_xmlhttprequest (with the same argument) and it'll get fired off within the next 100ms.  Neat huh?  And if you're worried about security (which you should be) -- I've tested this myself, and gmAjax isn't acccessible anywhere outside of the Greasemonkey sandbox.  Huzzah, mission accomplished.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxaller.name/2009/01/accessing-gm_xmlhttprequest-from-event-handlers-bound-by-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Reader Commenter script</title>
		<link>http://blog.maxaller.name/2009/01/google-reader-commenter-script/</link>
		<comments>http://blog.maxaller.name/2009/01/google-reader-commenter-script/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 23:55:18 +0000</pubDate>
		<dc:creator>Max</dc:creator>
				<category><![CDATA[just for fun]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://giftswappo.com/wordpress/?p=52</guid>
		<description><![CDATA[At Esther's request, I wrote a script that lets you comment on blogs that are in your Google Reader list. Right now it only works on Blogger and WordPress blogs, but that's actually a fair number of blogs. Requirements: Firefox, Greasemonkey Plugin Check it out here: GitHub repository Here's a picture: Picture]]></description>
			<content:encoded><![CDATA[<p>At Esther's request, I wrote a script that lets you comment on blogs that are in your Google Reader list.  Right now it only works on Blogger and WordPress blogs, but that's actually a fair number of blogs.</p>
<p>Requirements: Firefox, Greasemonkey Plugin</p>
<p>Check it out here: <a href="http://github.com/nanodeath/google-reader-commenter-script/tree/master">GitHub repository</a></p>
<p>Here's a picture: <a href="http://github.com/nanodeath/google-reader-commenter-script/raw/master/doc/Google%20Reader%20Commenter.png" target="_blank">Picture</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxaller.name/2009/01/google-reader-commenter-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>spud! greasemonkey script</title>
		<link>http://blog.maxaller.name/2008/07/spud-greasemonkey-script/</link>
		<comments>http://blog.maxaller.name/2008/07/spud-greasemonkey-script/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 07:04:31 +0000</pubDate>
		<dc:creator>Max</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[spud!]]></category>

		<guid isPermaLink="false">http://giftswappo.com/wordpress/?p=29</guid>
		<description><![CDATA[I've dabbled a little in Greasemonkey, but I've yet to be inspired enough to publish something I've made. Well, I'm tempted to do so now -- it's a script to alter your experience a bit with spud!'s pages. Feature 1) You know how it says Local, which really means &#60;500 miles? What if you don't [...]]]></description>
			<content:encoded><![CDATA[<p>I've dabbled a little in Greasemonkey, but I've yet to be inspired enough to publish something I've made.  Well, I'm tempted to do so now -- it's a script to alter your experience a bit with spud!'s pages.</p>
<p><span id="more-29"></span></p>
<p>Feature 1) You know how it says Local, which really means &lt;500 miles?  What if you don't think that's really all that local?  Isn't it a hassle to click on a bunch of links that generate popups to see how far away something actually is?  I thought so too, which is why I have the following feature:</p>
<p><a href="http://giftswappo.com/wordpress/wp-content/uploads/2008/07/before_and_after.png"><img class="aligncenter size-full wp-image-30" title="How local?" src="http://giftswappo.com/wordpress/wp-content/uploads/2008/07/before_and_after.png" alt="\" width="477" height="80" /></a></p>
<p>In other words, it inserts a link that, upon being clicked, will reveal in a fraction of a second how far the product actually came.  I'm requiring the user to click because otherwise you have like 4 dozen AJAX requests every time you load the page -- not nice for you, spud!, or your ISP.</p>
<p>Feature 2) Price per unit calculations.</p>
<p>Before: <a href="http://giftswappo.com/wordpress/wp-content/uploads/2008/07/price_ratio_before1.png"><img class="alignnone size-full wp-image-32" title="price_ratio_before1" src="http://giftswappo.com/wordpress/wp-content/uploads/2008/07/price_ratio_before1.png" alt="Price ratio before script" width="435" height="150" /></a></p>
<p>After: <a href="http://giftswappo.com/wordpress/wp-content/uploads/2008/07/price_ratio_after.png"><img class="alignnone size-full wp-image-33" title="price_ratio_after" src="http://giftswappo.com/wordpress/wp-content/uploads/2008/07/price_ratio_after.png" alt="Price ratio after script" width="435" height="159" /></a></p>
<p>As you can see, it calculates the price per ounce in these two cases.  The calculations don't work across the entire website because spud! isn't that consistent, but it should work in the most common cases.</p>
<p>Feature 3) The third and final feature is a link that omits any entries on the page that are not local (by spud!'s standards).  I'm not going to include a picture because it's not that interesting.  If you want to give it a try, click <a href="http://nutriscan.org/blog/spud.user.js">here</a>. You need a recent version of Greasemonkey installed.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxaller.name/2008/07/spud-greasemonkey-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
