Skip to content

Instantly share code, notes, and snippets.

@tarao
Created April 10, 2010 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarao/362325 to your computer and use it in GitHub Desktop.
Save tarao/362325 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name preventLargeFlash
// @namespace http://orezdnu.org/
// @include http://*
// ==/UserScript==
(function(d) {
var tags = [ 'object', 'embed' ];
var t = 0.95; // threshold
var wait = 300;
setTimeout(function() {
var c = {
w: window.innerWidth || document.documentElement.clientWidth,
h: window.innerHeight || document.documentElement.clientHeight
};
if (!c.w && !c.h) return;
var resize = function(node, which) {
var size = c[which.substring(0, 1).toLowerCase()]*t;
if (node['offset'+which] <= size) return;
if (!size) return;
node[which.toLowerCase()] = size + 'px';
node.style[which.toLowerCase()] = size + 'px';
return size;
};
var remove = function(node) {
var parent = node.parentNode;
var p = d.createElement('p');
p.style.borderStyle = 'dashed';
p.style.borderWidth = '0.2em';
p.style.borderColor = '#cc3333';
p.style.backgroundColor = '#ff99cc';
p.style.color = '#333333';
p.style.textAlign = 'center';
p.style.fontWeight = 'bold';
p.style.margin = '1em';
var msg = 'A flash has been removed.';
var a = d.createElement('a');
a.appendChild(d.createTextNode('>> restore'));
a.addEventListener('click', function() {
parent.replaceChild(node, p);
}, false);
a.style.marginLeft = '2em';
a.style.cursor = 'pointer';
p.appendChild(d.createTextNode(msg));
p.appendChild(a);
parent.replaceChild(p, node);
return true;
}
var r = {};
tags.forEach(function(x) {
r[x] = {};
var arr = d.getElementsByTagName(x);
for (var i=0; i < arr.length; i++) {
var f = function(which){ return resize(arr[i], which); };
var w = f('Width'); var h = f('Height');
if (w||h) r[x][i] = w || h;
}
});
tags.forEach(function(x) {
var arr = d.getElementsByTagName(x);
for (var i=0; i < arr.length; i++) {
if (r[x][i]) remove(arr[i]);
}
});
}, wait);
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment