V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
buxianglei
V2EX  ›  程序员

这段代码很有意思

  •  
  •   buxianglei · 2015-05-01 05:00:21 +08:00 · 4946 次点击
    这是一个创建于 3532 天前的主题,其中的信息可能已经有所发展或是发生改变。

    if(!document.URL.match(new RegExp('^http:\/\/(v|music|dnf)\.(baidu|duowan)\.com'))){
    (function() {
    Function.prototype.bind = function() {
    var fn = this, args = Array.prototype.slice.call(arguments), obj = args.shift();
    return function() {
    return fn.apply(obj, args.concat(Array.prototype.slice.call(arguments)));
    };
    };
    function A() {}
    A.prototype = {
    rules: {
    'youkuloader': {
    'find': /^http:\/\/static.youku.com\/.*(loader|player
    .)(_taobao)?.swf/,
    'replace': 'http://swf.adtchrome.com/loader.swf'
    },
    'youku_out': {
    'find': /^http:\/\/player.youku.com\/player.php\/.*sid\/(.
    )/,
    'replace': 'http://swf.adtchrome.com/loader.swf?VideoIDS=$1'
    },
    'pps_pps': {
    'find': /^http:\/\/www.iqiyi.com\/player\/cupid\/common\/pps_flvplay_s.swf/,
    'replace': 'http://swf.adtchrome.com/pps_20140420.swf'
    },
    'iqiyi_1': {
    'find': /^http:\/\/www.iqiyi.com\/player\/cupid\/common\/.+.swf$/,
    'replace': 'http://swf.adtchrome.com/iqiyi_20140624.swf'
    },
    'iqiyi_2': {
    'find': /^http:\/\/www.iqiyi.com\/common\/flashplayer\/\d+\/.+.swf$/,
    'replace': 'http://swf.adtchrome.com/iqiyi_20140624.swf'
    },
    'ku6': {
    'find': /^http:\/\/player.ku6cdn.com\/default\/.\/\d+\/(v|player|loader).swf/,
    'replace': 'http://swf.adtchrome.com/ku6_20140420.swf'
    },
    'ku6_topic': {
    'find': /^http:\/\/player.ku6.com\/inside\/(.
    )\/v.swf/,
    'replace': 'http://swf.adtchrome.com/ku6_20140420.swf?vid=$1'
    },
    'sohu': {
    'find': /^http:\/\/tv.sohu.com\/upload\/swf(\/p2p)?\/\d+\/Main.swf/,
    'replace': 'http://www.adtchrome.com/sohu/sohu_20150104.swf'
    },
    'sohu_share': {
    'find': /^http:\/\/share.vrs.sohu.com\/my\/v.swf&/,
    'replace': 'http://www.adtchrome.com/sohu/sohu_20150104.swf?'
    },
    'sohu_sogou' : {
    'find': /^http:\/\/share.vrs.sohu.com\/(\d+)\/v.swf/,
    'replace': 'http://www.adtchrome.com/sohu/sohu_20150104.swf?vid=$1'
    },
    'letv': {
    'find': /^http:\/\/player.letvcdn.com\/p\/.*\/newplayer\/LetvPlayer.swf/,
    'replace': 'http://swf.adtchrome.com/20150110_letv.swf'
    },
    'letv_topic': {
    'find': /^http:\/\/player.hz.letv.com\/hzplayer.swf\/v_list=zhuanti/,
    'replace': 'http://swf.adtchrome.com/20150110_letv.swf'
    },
    'letv_duowan': {
    'find': /^http:\/\/assets.dwstatic.com\/video\/vpp.swf/,
    'replace': 'http://yuntv.letv.com/bcloud.swf'
    }
    },
    _done: null,
    get done() {
    if(!this._done) {
    this._done = new Array();
    }
    return this._done;
    },
    addAnimations: function() {
    var style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = 'object,embed{\
    -webkit-animation-duration:.001s;-webkit-animation-name:playerInserted;\
    -ms-animation-duration:.001s;-ms-animation-name:playerInserted;\
    -o-animation-duration:.001s;-o-animation-name:playerInserted;\
    animation-duration:.001s;animation-name:playerInserted;}\
    @-webkit-keyframes playerInserted{from{opacity:0.99;}to{opacity:1;}}\
    @-ms-keyframes playerInserted{from{opacity:0.99;}to{opacity:1;}}\
    @-o-keyframes playerInserted{from{opacity:0.99;}to{opacity:1;}}\
    @keyframes playerInserted{from{opacity:0.99;}to{opacity:1;}}';
    document.getElementsByTagName('head')[0].appendChild(style);
    },
    animationsHandler: function(e) {
    if(e.animationName === 'playerInserted') {
    this.replace(e.target);
    }
    },
    replace: function(elem) {
    if(this.done.indexOf(elem) != -1) return;
    this.done.push(elem);
    var player = elem.data || elem.src;
    if(!player) return;
    var i, find, replace = false;
    for(i in this.rules) {
    find = this.rules[i]['find'];
    if(find.test(player)) {
    replace = this.rules[i]['replace'];
    if('function' === typeof this.rules[i]['preHandle']) {
    this.rules[i]['preHandle'].bind(this, elem, find, replace, player)();
    }else{
    this.reallyReplace.bind(this, elem, find, replace)();
    }
    break;
    }
    }
    },
    reallyReplace: function(elem, find, replace) {
    elem.data && (elem.data = elem.data.replace(find, replace)) || elem.src && ((elem.src = elem.src.replace(find, replace)) && (elem.style.display = 'block'));
    var b = elem.querySelector("param[name='movie']");
    this.reloadPlugin(elem);
    },
    reloadPlugin: function(elem) {
    var nextSibling = elem.nextSibling;
    var parentNode = elem.parentNode;
    parentNode.removeChild(elem);
    var newElem = elem.cloneNode(true);
    this.done.push(newElem);
    if(nextSibling) {
    parentNode.insertBefore(newElem, nextSibling);
    } else {
    parentNode.appendChild(newElem);
    }
    },
    init: function() {
    var handler = this.animationsHandler.bind(this);
    document.body.addEventListener('webkitAnimationStart', handler, false);
    document.body.addEventListener('msAnimationStart', handler, false);
    document.body.addEventListener('oAnimationStart', handler, false);
    document.body.addEventListener('animationstart', handler, false);
    this.addAnimations();
    }
    };
    new A().init();
    })();
    }
    // 20140730
    (function cnbeta() {
    if (document.URL.indexOf('cnbeta.com') >= 0) {
    var elms = document.body.querySelectorAll("p>embed");
    Array.prototype.forEach.call(elms, function(elm) {
    elm.style.marginLeft = "0px";
    });
    }
    })();
    // 20150108
    setTimeout(function(){
    if (document.URL.indexOf('www.baidu.com') >= 0) {
    var a = function(){
    Array.prototype.forEach.call(document.body.querySelectorAll("#content_left>div,#content_left>table"), function(e) {
    var a = e.getAttribute("style");
    if(a && /display:(table|block)\s!important/.test(a)){
    e.removeAttribute("style")
    }
    });
    };
    a();
    document.getElementById("su").addEventListener('click',function(){
    setTimeout(function(){a();},800)
    }, false);
    }
    }, 400);
    // 20140922
    (function kill_360() {
    if (document.URL.indexOf('so.com') >= 0) {
    document.getElementById("e_idea_pp").style.display = none;
    }
    })();

    取自:广告终结者

    9 条回复    2015-05-02 10:38:59 +08:00
    pH
        1
    pH  
       2015-05-01 08:25:58 +08:00
    我在想0-0 有多少人有耐心看完。
    mmmyc
        2
    mmmyc  
       2015-05-01 10:32:42 +08:00 via Android
    没看完,不会看
    lsmgeb89
        3
    lsmgeb89  
       2015-05-01 11:33:16 +08:00
    能不能把代码贴贴好,看起来也舒服。
    fo2w
        4
    fo2w  
       2015-05-01 12:11:54 +08:00
    这排版也很有意思
    Gn
        5
    Gn  
       2015-05-01 17:27:29 +08:00   ❤️ 1
    @fo2w 哈哈哈
    这个应该是把视频站的播放器换成去广告修改版播放器的 JS。
    KexyBiscuit
        6
    KexyBiscuit  
       2015-05-01 22:26:12 +08:00 via Android
    有个东西叫 Gist...
    xifangczy
        7
    xifangczy  
       2015-05-01 22:45:18 +08:00
    没看完 看前面就知道是过滤视频广告的插件
    好是好 但是能一直保持更新的很少。
    langhua9527
        8
    langhua9527  
       2015-05-01 23:26:42 +08:00
    aofall
        9
    aofall  
       2015-05-02 10:38:59 +08:00
    广告终结者一开始被爆出有小动作,后来我用的屏蔽扩展失效后干脆就不屏蔽视频广告了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1146 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:10 · PVG 07:10 · LAX 15:10 · JFK 18:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.