• 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) {}
    	});
    })();


  • 相关阅读:
    贝塞尔曲线应用(贝塞尔插值)
    贝塞尔曲线原理(简单阐述)
    STL头文件有哪些及简单介绍
    句柄与MFC对象关系和相互获取
    Reflect
    Set 和 Map 数据结构
    Symbol
    对象的新增方法
    对象的扩展
    数组的扩展
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3137627.html
Copyright © 2020-2023  润新知