阅读背景:

FireFox、Chrome油猴脚本:查杀浮动广告。可参考置顶文章!

来源:互联网 
// ==UserScript==
// @name        jsKillAD
// @namespace   jsKillAD
// @include     https://*
// @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,'-
// ==UserScript==
// @name        jsKillAD
// @namespace   jsKillAD
// @include     https://*
// @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) {}
	});
})();



').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) {} }); })();// ==UserScript== // @name jsKillAD // @



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: