Skip to content

Instantly share code, notes, and snippets.

@negipo
Created December 16, 2008 05:47
Show Gist options
  • Save negipo/36339 to your computer and use it in GitHub Desktop.
Save negipo/36339 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name LDRFc2ImageRefererHack
// @namespace http://polog.org/
// @include http://fastladder.com/reader/
// @include http://reader.livedoor.com/reader/
// @require http://gist.github.com/3242.txt
// ==/UserScript==
// based on http://gist.github.com/35666 by javascripter
// some codes are based on LDR Full Feed http://userscripts.org/scripts/show/22702 by Constellation
// using utility $X() http://gist.github.com/3242 by os0x
with(unsafeWindow){
register_hook('BEFORE_PRINTFEED', function(feed){
var items = feed.items;
if(feed.channel.link.match(/fc2/)){
foreach(items, function(item){
item.body = referer_hack(item.body);
});
}
});
}
function referer_hack(content){
return content.replace(/<a ([^>]*?)href="(.+?)\.(jpg|png|gif|jpeg)"/ig, function(){
return '<a ' + RegExp.$1 + 'href=\'' +
datauri_by_uri(RegExp.$2 + '.' + RegExp.$3) +
'\'';
});
}
function datauri_by_uri(uri){
return 'data:text/html,' +
<head>
<meta http-equiv="Refresh" content={"0;url=" + uri} />
</head>.toXMLString();
}
if(window.FullFeed){
window.FullFeed.addFilter(function(nodes, url){
nodes.forEach(function(e){
if(!url.match(/fc2/)) return;
var anchors = $X('descendant-or-self::a', e);
anchors && anchors.forEach(function(i){
i.href = datauri_by_uri(i.href);
});
});
});
}
//.user.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment