Skip to content

Instantly share code, notes, and snippets.

@miya2000
Created November 29, 2008 10:16
Show Gist options
  • Save miya2000/30222 to your computer and use it in GitHub Desktop.
Save miya2000/30222 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name flash - disable script access
// @author miya2000
// @namespace http://d.hatena.ne.jp/miya2000/
// @version 1.0.1
// @include http://www.nttsolmare.com/*
// @exclude http://*http*
// ==/UserScript==
(function() {
function evaluate(xpath, context) {
var eles = document.evaluate(xpath, context || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var arr = [];
for (var i = 0, len = eles.snapshotLength; i < len; i++) {
arr.push(eles.snapshotItem(i));
}
return arr;
}
// http://developer.mozilla.org/ja/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:forEach#Compatibility
function fe(array) {
if (array.forEach) return;
array.forEach = function(fun /*, thisp*/) {
var len = this.length;
if (typeof fun != "function") throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in this) fun.call(thisp, this[i], i, this);
}
};
}
// http://mayokara.info/note/view/269
var defer = function(/* f1, f2, ... */){
var self = this, fn = Array.prototype.slice.call(arguments);
(function(/* arg2, arg3, ... */){
var args = Array.prototype.slice.call(arguments);
(fn.shift()).apply(self, [arguments.callee].concat(args));
})();
};
var replace = function(x, y) {
if (!y || x === y) {
var p = x.parentNode;
var n = x.nextSibling;
p.removeChild(x);
p.insertBefore(x, n);
}
else {
x.parentNode.replaceChild(y, x);
}
}
// set wmode="opaque" to flash element.
function hogeEm(fl) {
if (fl.offsetWidth * fl.offsetHeight == 0) return;
fl.setAttribute('allowScriptAccess ', 'never');
var dv = document.createElement('div');
dv.innerHTML = fl.outerHTML;
var dfl = dv.firstChild;
replace(fl, dfl);
}
function hogeOb(fl) {
if (fl.offsetWidth * fl.offsetHeight == 0) return;
var prm = document.createElement('param');
prm.setAttribute('name','allowScriptAccess');
prm.setAttribute('value','never');
fl.appendChild(prm);
replace(fl);
}
function doHogeHoge(target) {
var embedFlash = evaluate('//embed[@type="application/x-shockwave-flash"]', target);
var objectFlash = evaluate('//object[@type="application/x-shockwave-flash" or @classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"]', target);
if (embedFlash.length == 0 && objectFlash.length == 0) {
return;
}
fe(embedFlash); fe(objectFlash);
embedFlash.forEach(hogeEm);
objectFlash.forEach(hogeOb);
}
function main() {
if (!document.body) return;
defer(
function(next) {
// for Eolas's patent.
var ex_script = document.createElement('script');
ex_script.style.display = 'none';
ex_script.src = 'data:text/javascript,window.___tmp2=' + encodeURIComponent(replace.toString());
var bak_tmp = window.___tmp2;
document.body.appendChild(ex_script);
setTimeout(function() {
replace = window.___tmp2;
document.body.removeChild(ex_script);
window.___tmp2 = bak_tmp;
next();
}, 0);
},
function() {
doHogeHoge(document.body);
document.addEventListener('DOMNodeInserted', function(e) {
document.removeEventListener('DOMNodeInserted', arguments.callee, false);
doHogeHoge(e.target);
document.addEventListener('DOMNodeInserted', arguments.callee, false);
}, false);
}
);
}
document.addEventListener('DOMContentLoaded', main, false);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment