-
-
Save ssig33/964001 to your computer and use it in GitHub Desktop.
This file contains 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 fldr_show_fc2_images.user.js | |
// @namespace http://d.hatena.ne.jp/os0x/ | |
// @description Make fc2 images viewable on LDR/Fastladder | |
// @include http://reader.livedoor.com/reader/ | |
// @include http://reader.livedoor.com/public/* | |
// @include http://fastladder.com/reader/ | |
// @include http://openfl.ssig33.com/reader/ | |
// ==/UserScript== | |
// via http://gist.github.com/48621 | |
(function(){ | |
var index = 0; | |
function openImg(img){ | |
var iframe = document.createElement('iframe'); | |
var id = iframe.id = 'ref-id-' + index++; | |
var src = img.src + (img.src.indexOf('?') > 0 ? '&' : '?') + index; | |
iframe.frameborder = '0'; | |
iframe.scrolling = 'no'; | |
iframe.marginwidth = '0'; | |
iframe.marginheight = '0'; | |
iframe.style.border='none'; | |
iframe.style.display='inline-block'; | |
var size = ''; | |
if (img.hasAttribute('width')) { | |
size += ' width="' + img.getAttribute('width') + '"'; | |
iframe.width = img.getAttribute('width'); | |
} else { | |
iframe.width = '16'; | |
} | |
if (img.hasAttribute('height')) { | |
size += ' height="' + img.getAttribute('height') + '"'; | |
iframe.height = img.getAttribute('height'); | |
} else { | |
iframe.height = '16'; | |
} | |
iframe.src = 'data:text/html,' + | |
'<html><head><script>' + | |
'function img_load(img){' + | |
'var data = {width:img.width,height:img.height,id:"' + id + '"};' + | |
'window.parent.postMessage(JSON.stringify(data),"' + location.protocol + '//' + location.host + '");' + | |
'};' + | |
'</script><style>*{margin:0;padding:0;}</style></head><body>' + | |
'<img src="' + src + '" '+size+' onload="img_load(this)" onerror="img_load(this)"></body></html>'; | |
img.parentNode.insertBefore(iframe, img); | |
} | |
document.body.addEventListener('error',function(evt){ | |
if (evt.target.tagName === 'IMG') { | |
openImg(evt.target); | |
evt.target.parentNode.removeChild(evt.target); | |
} | |
},true); | |
window.addEventListener('message', function(evt){ | |
if (evt.origin==="null") { | |
var data = JSON.parse(evt.data); | |
var ifm = document.getElementById(data.id); | |
if (ifm) { | |
ifm.width = data.width; | |
ifm.height = data.height; | |
} | |
} | |
},false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment