FireFox、Chrome油猴脚本:查杀浮动广告。可参考置顶文章!
// ==UserScript==
// @name jsKillAD
// @namespace jsKillAD
// @include http://*
// @include https://*
// @grant none
// @version 1
// ==/UserScript==
(function () {
var bc = Array.prototype.forEach;//Callback
function getStyle(o, s) {
if(o.style[s])//内联样式
return o.style[s];
else if(document.defaultView && document.defaultView.getComputedStyle){//DOM
//s = s.replace(/([A-Z])/g,'-$1').toLowerCase();
var x = document.defaultView.getComputedStyle(o,'');
return x.getPropertyValue(s);
}
}
function testStyle(o) {
var s = getStyle(o, "position");
return s === "fixed" || s === "absolute";
}
/*
function sameDomain(o) {
try {
return o.document.body;
} catch (e) {
return 0;
}
}
*/
function isFloatLay(o) {
var x = o.offsetParent;
return !x || x.tagName === "BODY" || x.tagName === "HTML";
}
function delNode(x) {
x.parentNode.removeChild(x);
}
function scan(el) {
["iframe", "img", "object", "embed", "video"].forEach(function(s) {
bc.call(el.getElementsByTagName(s), function(x) {
while (x) {
if (isFloatLay(x)) {
//要删除的层得同时满足二个条件
if (testStyle(x)) delNode(x);
break;
}
x = x.offsetParent;
}
});
});
}
/*
//扫描广告脚本
bc.call(document.getElementsByTagName("script"), function(o) {
if (o.src && o.readyState !== "complete") delNode(o);
});
//没用哦,因为DIV中可能已经生成了元素
bc.call(document.querySelectorAll ? document.querySelectorAll("div>script") : document.getElementsByTagName("script"), function(x) {
x = x.parentNode;
if (x.childNodes.length === 1) delNode(x);
});
*/
document.addEventListener("DOMContentLoaded", function(){scan(document);}, false);
bc.call(frames, function(x) {
try {
scan(x.contentDocument);
} catch (e) {}
});
})();

浙公网安备 33010602011771号