Greasy Fork

Greasy Fork is available in English.

jsKillAD

查杀页面浮动广告

当前为 2015-02-09 提交的版本,查看 最新版本

// ==UserScript==
// @name        jsKillAD
// @namespace   jsKillAD
// @description 查杀页面浮动广告
// @description:en Kill AD on page
// @author	    xinggsf~gmail。com
// @homepageURL http://greasyfork.icu/scripts/7410
// updateURL    http://greasyfork.icu/scripts/7410/code/jsKillAD.user.js
// downloadURL  http://greasyfork.icu/scripts/7410/code/jsKillAD.user.js
// @encoding    utf-8
// @license     GPL version 3
// @modified    02/09/2015
// @include     http://*
// @include     https://*
// @exclude     http://*.mail.*/*
// @exclude     http://*mimg.127.net/*
// @exclude     http://greasyfork.icu/*
// @exclude     http://*.csdn.net/postedit/*
// @exclude     https://mail.google.com/*
// @exclude     http*://www.google.*/search?*
// @exclude     http://www.baidu.com/s?*
// @exclude     http://115.com/*
// @exclude     http://*.115.com/*
// @exclude     http://*.1ting.com/*
// @exclude     http://www.360doc.com/*
// @exclude     http://www.cnblogs.com/*
// @exclude     http://*.gsmn.com.cn/*
// @exclude     http://quote.futures.hexun.com/price.aspx?*
// @exclude     http://user.qzone.qq.com/*
// @exclude     http://*share*.qq.com/*
// @exclude     http://video.sina.com.cn/*
// @run-at      document-end
// @grant       none
// @version     1.3.2
// ==/UserScript==
(function () {
  var bc = Array.prototype.forEach; //Callback

  function getStyle(o, s) {
    if (o.style[s]) { //内联样式
      return o.style[s];
    }
    if (document.defaultView && document.defaultView.getComputedStyle) { //DOM
      //s = s.replace(/([A-Z])/g,'-$1').toLowerCase();
      var x = document.defaultView.getComputedStyle(o, '');
      return x && x.getPropertyValue(s);
    }
  }

  function testStyle(o) {
    var s = getStyle(o, 'position');
    return s === 'fixed' || s === 'absolute';
  }
  function isFloatLay(o) {
    var x = o.offsetParent;
    return !x || x.tagName === 'BODY' || x.tagName === 'HTML';
  }
  function scan(el) {
    ['iframe','img','object','embed'].forEach(function (s) {
      bc.call(el.getElementsByTagName(s), function (x) {
        while (x) {
          if (isFloatLay(x)) {
            //要删除的层得同时满足二个条件
            testStyle(x) && x.parentNode.removeChild(x);
            break;
          }
          x = x.offsetParent;
        }
      });
    });
  }

  //document.addEventListener("DOMContentLoaded", function(){scan(document);}, false);
  scan(document);
  bc.call(frames, function (x) {
    try {scan(x.contentDocument);}
    catch (e) {}
  });
})();