<?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"
	>

<channel>
	<title>Felix Hunecker</title>
	<atom:link href="http://www.hunecker.de/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.hunecker.de</link>
	<description>Personal Website</description>
	<pubDate>Thu, 13 May 2010 13:19:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Greasemonkey Newzbin Poster Script</title>
		<link>http://www.hunecker.de/?p=58</link>
		<comments>http://www.hunecker.de/?p=58#comments</comments>
		<pubDate>Wed, 03 Dec 2008 20:07:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hunecker.de/?p=58</guid>
		<description><![CDATA[As promised, I&#8217;m posting my Greasemonkey Script for NewzBin. This one displays poster images, ratings and movie descriptions.

	var flattr_url = 'http://www.hunecker.de/?p=58';
	var flattr_btn='compact';



Feature list:

Puts reports of the same movie into one group
Shows poster image for each movie
Loads movie description, rating and genre and displays them
Sorts movies according to rating
Compatible with Newzbin Normal and Lite Mode

Screenshots










Instructions
If you [...]]]></description>
			<content:encoded><![CDATA[<p>As promised, I&#8217;m posting my Greasemonkey Script for NewzBin. This one displays poster images, ratings and movie descriptions.<br />
<script type="text/javascript">
	var flattr_url = 'http://www.hunecker.de/?p=58';
	var flattr_btn='compact';
</script><br />
<script src="http://api.flattr.com/button/load.js" type="text/javascript"></script><br />
<span id="more-58"></span></p>
<h2>Feature list:</h2>
<ul>
<li>Puts reports of the same movie into one group</li>
<li>Shows poster image for each movie</li>
<li>Loads movie description, rating and genre and displays them</li>
<li>Sorts movies according to rating</li>
<li>Compatible with Newzbin Normal and Lite Mode</li>
</ul>
<h2>Screenshots</h2>
<table border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_59" class="wp-caption alignnone" style="width: 310px"><a href="http://www.hunecker.de/wp-content/uploads/2008/12/before.png"><img class="size-medium wp-image-59" title="Before" src="http://www.hunecker.de/wp-content/uploads/2008/12/before-300x214.png" alt="Before" width="300" height="214" /></a><p class="wp-caption-text">Before</p></div></td>
<td>
<p><div id="attachment_60" class="wp-caption alignnone" style="width: 310px"><a href="http://www.hunecker.de/wp-content/uploads/2008/12/after.png"><img class="size-medium wp-image-60" title="after" src="http://www.hunecker.de/wp-content/uploads/2008/12/after-300x216.png" alt="After" width="300" height="216" /></a><p class="wp-caption-text">After</p></div></td>
</tr>
</tbody>
</table>
<h2>Instructions</h2>
<p>If you don&#8217;t have GreaseMonkey, get it <a href="https://addons.mozilla.org/de/firefox/addon/748" target="_blank">here</a>. This is an extension for Firefox that allows you to modify foreign pages.</p>
<p>Install the script from <a href="http://userscripts.org/scripts/show/38054" target="_blank">here</a>.</p>
<p>Go to Newzbin and open a page containing movie reports. The script should automatically detect the movie links and load the information. After loading is complete, the movies will be reordered according to their rating. Reports marked as new will stay on top. Reports, that have no IMDB link, will be displayed at the bottom of the page.</p>
<p>If you want to see the reports for a movie, click on the poster image on the left side. The original Newzbin Entries will be displayed.</p>
<p>If you&#8217;ve been using other Greasemonkey scripts for Newzbin before, please make sure they do not interfere with each other. If you encounter problems, please deactivate the other scripts.</p>
<h2>How it was done</h2>
<p>After using <a href="http://jameswilson.name/content/ULTIMATE-Newzbin-IMDB-Suite">James Wilsons Ultimate Newzbin Suite</a> for a while, which is actually a very cool script, I thought it would be nice to have the poster images displayed for the movies. But this was pretty hard to establish, because IMDB doesn&#8217;t allow to cross-link their images on other sites. After wasting lot of time trying to overcome this restriction, I finally managed it to load the poster images with a workaround described <a href="/?p=47">here</a>. But then I found it looked ugly, because often Newzbin has multiple reports of the same movie, which resulted in showing the same poster over and over again. This also lead to unnecessary bandwidth usage, because the same movie information was loaded again with each report. This lead me to the idea to group same movies.But this requiered a completely different data handling than was done in the other scripts, so I had to write the script from scratch.</p>
<h2>Feedback</h2>
<p>Please discuss the script on the <a href="http://userscripts.org/scripts/show/38054">UserScript Site</a>.<br />
<script src="http://api.flattr.com/button/load.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hunecker.de/?feed=rss2&amp;p=58</wfw:commentRss>
		</item>
		<item>
		<title>Loading binary data from different sites in GreaseMonkey</title>
		<link>http://www.hunecker.de/?p=47</link>
		<comments>http://www.hunecker.de/?p=47#comments</comments>
		<pubDate>Tue, 02 Dec 2008 17:54:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hunecker.de/?p=47</guid>
		<description><![CDATA[One benefit of the GreaseMonkey function GM_xmlhttpRequest over the regular XMLHttpRequest is the ability to load content from different domains. This feature allows creating scripts that load information from third-party sites and display them on a different site. This feature can also be used to load binary data like images from other sites, for example [...]]]></description>
			<content:encoded><![CDATA[<p>One benefit of the GreaseMonkey function GM_xmlhttpRequest over the regular XMLHttpRequest is the ability to load content from different domains. This feature allows creating scripts that load information from third-party sites and display them on a different site. This feature can also be used to load binary data like images from other sites, for example to get around referer restrictions.<br />
<span id="more-47"></span><br />
Recently I tried to extend the <a href="http://jameswilson.name/content/ULTIMATE-Newzbin-IMDB-Suite" target="_blank">ULTIMATE Newzbin IMDB Suite</a> to display poster images from IMDB on Newzbin. The basics are simple: I created a regular expression that parsed the output from IMDB for the poster URL, and created a JavaScript Image object to load the image. It looked like this:</p>
<p><code> </code></p>
<pre>var posterURL = responseDetails.responseText.match(posterRegex);
var poster = document.createElement("img");
poster.src = posterURL[1];</pre>
<p>But the loading of the image always failed. It seems that IMDB doesn&#8217;t not allow embedding their images on other sites. Obviously, they check the referer when the image is loaded.</p>
<p>To overcome this restriction, you have to do three things:</p>
<ol>
<li>Use GM_xmlhttpRequest to load the image with a fake referrer while preserving the byte values. This was the hardest part, since it seems that GreaseMonkey is mangling binary data. There is a <a href="http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html" target="_blank">way to deal with it</a>, though</li>
<li>Convert the result to <a href="http://en.wikipedia.org/wiki/Base64" target="_blank">Base64</a></li>
<li>Use the <a href="http://en.wikipedia.org/wiki/Data_URI_scheme" target="_blank">data URI scheme</a> to display the image</li>
</ol>
<p>So here’s the code to load an image from IMDB. Note the line defining the overrideMimeType. This one is crucial to get proper binary data. The parameter imdbURL can be any URL starting with &#8220;http://www.imdb.com&#8221;. The parameter poster should be the img-element that was created above.</p>
<p><code> </code></p>
<pre>function loadPosterImage(poster, posterURL, imdbURL) {
	GM_xmlhttpRequest( {
		method:"GET",url:posterURL,headers: { Referer:imdbURL,"User-agent":"Mozilla/4.0 (compatible)"},
		overrideMimeType:'text/plain; charset=x-user-defined',
		onload:function(response) {
			if(response.status==200) {
				var text = response.responseText;
				var b64 = Base64.encode(text);
				poster.src = "data:image/jpeg;base64,"+b64;
			}
			else {
				alert("failed loading image " + response.status);
			}
		}
	});
}</pre>
<p>For the Base64 encoding, I used a modified version of the <a href="http://www.webtoolkit.info/javascript-base64.html" target="_blank">webtoolkit.base64.js</a> to deal with the restrictions described in <a href="http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html" target="_blank">http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html</a>. Here’s the code for that:<br />
<code> </code></p>
<pre>var Base64 = {
    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        while (i &lt; input.length) {

            chr1 = input.charCodeAt(i++) &amp; 0xff;
            chr2 = input.charCodeAt(i++) &amp; 0xff;
            chr3 = input.charCodeAt(i++) &amp; 0xff;

            enc1 = chr1 &gt;&gt; 2;
            enc2 = ((chr1 &amp; 3) &lt;&lt; 4) | (chr2 &gt;&gt; 4);
            enc3 = ((chr2 &amp; 15) &lt;&lt; 2) | (chr3 &gt;&gt; 6);
            enc4 = chr3 &amp; 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }
        return output;
    }
}</pre>
<p>I’ll provide the complete script soon.</p>
<p>This approach allows basically loading everything from everywhere, but also has some downsides. One of them is the missing caching functionality. Images that are loaded this way, are not stored in the browser cache. Keep that in mind, if you&#8217;re planning to load lots of images from different sites.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hunecker.de/?feed=rss2&amp;p=47</wfw:commentRss>
		</item>
	</channel>
</rss>
