Created
January 29, 2009 21:47
-
-
Save snaka/54775 to your computer and use it in GitHub Desktop.
Fetch gist source then inject to ldr feeds. GistからコードをとってきてLDRでコードが読めるようにします。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ldr_gist_fullfeed | |
// @namespace http://d.hatena.ne.jp/snaka72/ | |
// @include http://reader.livedoor.com/reader/ | |
// ==/UserScript== | |
(function() { | |
var cache = {}; | |
(unsafeWindow||window).entry_widgets.add("ldr_gist_fullfeed", function(feed, item) { | |
if (!item.link.match(/http:\/\/gist\.github\.com/)) return; | |
// placeholder id | |
var id = "GIST_HERE_" + item.id; | |
// use cache if exists | |
if (cache[id]) { | |
item.body = item.body.replace(/#gist .+ now loading#/, cache[id]); | |
return; | |
} | |
item.body += ['<div id="', id, '"> #gist ', item.id, ' now loading# </div>'].join(''); | |
item.body.added = true; | |
// fetch gist code then inject to placeholder | |
setTimeout(function(){ | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: item.link + '.txt', | |
onload: function(data) { | |
var code = document.getElementById(id); | |
cache[id] = ['<pre><code>', data.responseText, '</code></pre>'].join(''); | |
code.innerHTML = cache[id]; | |
} | |
})}, 0); | |
}, "Fetch & inject gist code."); | |
})(); | |
// vim: ts=2 expandtab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment