// ==UserScript== // @name vipVideos_skipAd // @namespace vipVideos_skipAd // @author xinggsf~gmail。com // @description 优酷、土豆VIP免费看,去iqiyi.com、pps.tv视频广告 // @homepageURL https://greasyfork.org/scripts/8561 // updateURL https://greasyfork.org/scripts/8561/code/vipVideos_skipAd.user.js // downloadURL https://greasyfork.org/scripts/8561/code/vipVideos_skipAd.user.js // @license GPL version 3 // @include http://www.iqiyi.com/* // @include http://v.pps.tv/play_* // @include http://ipd.pps.tv/play_* // @include http://www.tudou.com/albumplay/* // @include http://www.tudou.com/listplay/* // @include http://www.tudou.com/programs/view/* // @include http://v.youku.com/v_show/id_* // @include http://v.youku.com/v_playlist/* // @include http://tv.sohu.com/* // @version 1.3.4 // @encoding utf-8 // @modified 2015.03.17 // @run-at document-end // @grant none // @downloadURL none // ==/UserScript== (function() { function $(css){ return document.querySelector(css); } function Overload(fn_objs) { var is_match = function (x, y) { if (x == y) return true; if (x.indexOf("*") == -1) return false; var x_arr = x.split(","), y_arr = y.split(","); if (x_arr.length != y_arr.length) return false; while (x_arr.length) { var x_first = x_arr.shift(), y_first = y_arr.shift(); if (x_first != "*" && x_first != y_first) return false; } return true; }; var ret = function () { var args = arguments, args_len = args.length, args_types = [], args_type, fn_objs = args.callee._fn_objs, match_fn = function () {}; for (var i = 0; i < args_len; i++) { var type = typeof args[i]; type == "object" && (args[i].length > -1) && (type = "array"); args_types.push(type); } args_type = args_types.join(","); for (var k in fn_objs) { if (is_match(k, args_type)) { match_fn = fn_objs[k]; break; } } return match_fn.apply(this, args); }; ret._fn_objs = fn_objs; return ret; } String.prototype.format = Overload({ "array" : function (params) { var reg = /{(\d+)}/gm; return this.replace(reg, function (match, key) { return params[~~key]; }); }, "object" : function (param) { var reg = /{([^{}]+)}/gm; return this.replace(reg, function (match, key) { return param[key]; }); } }); if (typeof String.prototype.startsWith !== 'function') { String.prototype.startsWith = function (str){ return this.slice(0, str.length) === str; }; String.prototype.endsWith = function (str){ return this.slice(-str.length) === str; }; } var router = { handlers: {}, run: function() { var o, handler = this.matchHandler(); console.log('handler:', handler); if (handler) { setTimeout(function(){ //Object.create(handler).proc(); o = new handler();//new Function(handler) console.log('handler proc():', o); o.proc(); }, 99); } }, register: function(domain, handler) { this.handlers[domain] = handler; }, matchHandler: function() { console.log('matchHandler() --'); var host = location.host.match(/\w+\.\w+$/)[0]; return (host in this.handlers) ? this.handlers[host] : null; } }; /*定义基类Base*/ function Base() { //这里放置final、静态方法,不在原型链上 this.clearSelectTags = function(css){ var c = document.querySelectorAll(css); if (!c) return; Array.prototype.forEach.call(c, function(t){ t.parentNode.removeChild(t); }); }; this.params=[]; this.argName = 'flashvars'; } Base.prototype={ extend: function(obj){ for(var i in obj){ this[i]=obj[i]; } }, getFlashvar : function(vName) { var ret, s = new RegExp(vName +'=([^&]+)');//,'i' s = this.flashvars.match(s); ret = s && s.length === 2; if (ret) { this.params.push(s[1]); return this;//方便用链式语法 } return false; }, isProc : function() { return true; }, getFlashvars : function() { // var r, s = this.player.innerHTML; // r = s.match(/name="flashvars"\s+value="([^"]+)"/i); // if (!r) r = s.match(/value="([^"]+)"\s+name="flashvars"/i); // if (r && r.length === 3) // this.flashvars = unescape(r[1]).replace(/&/g,'&'); this.flashvars = this.player.children[this.argName].value; console.log(this.argName, this.flashvars); }, rebuildSwf : function() { this.player.outerHTML = this.swfMark.format(this.params); }, proc : function() { this.player = $(this.swfCSS); console.log('get player: ', this.player); if (!this.player) return; this.getFlashvars(); if (!this.flashvars || !this.isProc()) return; this.getParams(); console.log('getParams(): ', this.params); this.rebuildSwf(); this.clearSelectTags('script'); } }; /*定义子类Youku*/ function Youku() { Base.call(this); this.swfCSS = '#movie_player'; this.swfMark = ''; } var repeater=new Base(); repeater.extend({ getParams:function(){ this.getFlashvar('VideoIDS'); if (!this.params.length) throw new Error('param error!'); } }); Youku.prototype=repeater; router.register('youku.com', Youku); function Tudou() { Base.call(this); this.swfCSS = '#tudouHomePlayer'; //http://100.100.100.100/buguanji.swf this.swfMark = ''; } repeater=new Base(); repeater.extend({ isProc:function(){ //有播放时间限制即进行处理 return /paidTime=\d{2,}&/.test(this.flashvars); }, getParams:function(){ if (!this.getFlashvar('vcode')) throw new Error('param error!'); } }); Tudou.prototype=repeater; router.register('tudou.com', Tudou); function Iqiyi() { Base.call(this); this.swfCSS = '#flash'; this.swfMark = ''; this.argName = 'flashVars'; } repeater=new Base(); repeater.extend({ /* isProc:function(){ console.info($("a.link_pay")); //return $("style#797082642689"); return !$("div.vdoRel"); }, */ getParams:function(){ this.params.push(this.player.getAttribute('data')); /* var s = this.flashvars.replace(/&\w+?loader=[^&]+/g,'') .replace(/&tipdataurl=[^&]+/i,'') .replace(/&adurl=[^&]+/i,'') .replace(/components=\w+/i,'components=feffbfe6e0') .replace(/&cid=qc_[^&]+/,'&cid=qc_100001_100141'); this.params.push(s); */ if (!this.getFlashvar('tvId')) this.params.push(''); this.getFlashvar('flashP2PCoreUrl'); if (!this.getFlashvar('definitionID')) this.getFlashvar('vid'); if (this.params.length < 4) throw new Error('param little!'); } }); Iqiyi.prototype=repeater; router.register('iqiyi.com', Iqiyi); function PpsTV() { Base.call(this); this.swfCSS = 'div.flash-player > object'; this.swfMark = ''; } repeater=new Base(); repeater.extend({ getParams:function(){ if (!this.getFlashvar('tvId')) this.params.push(''); if (!this.getFlashvar('definitionID')) { if (!this.getFlashvar('vid')) throw new Error("Don't do anything!"); } }, proc : function() { //Base.prototype.proc.apply(this, arguments); //等待播放器DOM构造完成后,即调用父类方法 var me = this, timer = setInterval(function(){ if ($(me.swfCSS)) { clearInterval(timer); Base.prototype.proc.call(me); } }, 100); } }); PpsTV.prototype=repeater; router.register('pps.tv', PpsTV); function Sohu() {} repeater=new Base(); repeater.extend({ proc : function() { this.player = $('embed#player'); if (!this.player) return; console.log('get player: ', this.player); this.flashvars = this.player.getAttribute('flashvars'); if (this.getFlashvar('vid')) { //var s, d = new Date(); //d = d.toISOString().slice(0, 9).replace(/-/g, '');yyyyMMdd日期格式 //s = 'http://tv.sohu.com/upload/swf/{0}/Main.swf'; //s = s.format([d]); //this.params.push(s); this.params.push(this.player.src); console.log('getParams: ', this.params); var s = ''; this.clearSelectTags('script'); this.player.outerHTML = s.format(this.params); console.log("finish! Now flash player is modified!", this); } } }); Sohu.prototype=repeater; router.register('sohu.com', Sohu); router.run(); })();