Greasy Fork

Greasy Fork is available in English.

自动关闭张鑫旭博客ADBlock用户特供广告

张鑫旭是前端界的大佬,他写的几本书我全买了,他的博客可谓业界良心,但他很不厚道的为ADBlock用户提供了专属广告,对此我表示非常理解,所以要自动将其关闭。

// ==UserScript==
// @name         自动关闭张鑫旭博客ADBlock用户特供广告
// @namespace    http://tampermonkey.net/
// @version      0.2
// @author       Taiyuuki
// @match      *://www.zhangxinxu.com/*
// @description  张鑫旭是前端界的大佬,他写的几本书我全买了,他的博客可谓业界良心,但他很不厚道的为ADBlock用户提供了专属广告,对此我表示非常理解,所以要自动将其关闭。
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zhangxinxu.com
// @grant        none
// @license      MIT 
// ==/UserScript==


function filter(node){
    // 方便以后修改
    return node.tagName.match(/^[a-zA-Z]{4}-[a-zA-Z]{2}$/)
}

(function() {
    'use strict';
    // Your code here...
    var root = document.querySelector('body');
    var iterator = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, {
        acceptNode: function(node) {
            var style = getComputedStyle(node)
            if (style.position === 'fixed') {
                return NodeFilter.FILTER_ACCEPT;
            } else {
                return NodeFilter.FILTER_REJECT;
            }
        }
    }, false);
    var node = iterator.nextNode();
    while (node != null) {
        if (filter(node)) {
            return node.remove();
        }
        node = iterator.nextNode();
    }
})();