Greasy Fork is available in English.

去除电信运营商劫持广告

去除中国电信等运营商的劫持内嵌广告

Fra 24.06.2017. Se den seneste versjonen.

// ==UserScript==
// @name         去除电信运营商劫持广告
// @namespace    hoothin
// @version      1.0
// @description  去除中国电信等运营商的劫持内嵌广告
// @author       hoothin
// @include      http://*/*
// @grant        none
// @license      MIT License
// ==/UserScript==

(function() {
    'use strict';
    function killFrameAD(){
        var hasAD=false;
        [].every.call(document.querySelectorAll("iframe"),function(i){
            if(i.src.indexOf(location.href)===0 && i.src!=location.href && i.src.replace(location.href,"").indexOf("?")===0){
                console.info("检测到劫持广告!");
                alert("检测到劫持广告!");
                hasAD=true;
                var ad=document.querySelector("iframe#a");
                if(ad)ad.parentNode.removeChild(ad);
                i.onload=function(){
                    try{
                        document.querySelector("html").innerHTML=i.contentWindow.document.querySelector("html").innerHTML;
                    }catch(e){
                        location.reload();
                    }
                };
                return false;
            }
            return true;
        });
        return hasAD;
    }
    if(!killFrameAD())
    setTimeout(function(){
        killFrameAD();
    },500);
})();