// ==UserScript==
// @name vipVideos_skipAd
// @namespace vipVideos_skipAd
// @author xinggsf~gmail。com
// @description 去视频广告,优酷、土豆VIP免费看
// @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/*
// @version 1.2
// @encoding utf-8
// @modified 03/15/2015
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
Overload = function (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();
console.log('handler proc():', o);
o.proc();
}, 159);
}
},
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=[];
}
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 > 1;
if (ret) this.params.push(s[1]);
return ret;
},
isProc : function() {
return true;
},
rebuildSwf : function() {
this.player.outerHTML = this.data.swfMark.format(this.params);
/*
var p, s = this.data.swfMark.format(this.params);
p = this.player.parentNode;
if (p.childNodes.length===1) {
p.innerHTML = s;
}
else {
p.innerHTML = p.innerHTML.replace(/<object [\s\S]+?<\/object>/,s);
} */
},
proc : function() {
this.player = document.getElementById(this.data.id);
console.log('get player: ', this.player);
if (!this.player) return;
// var s = this.player.innerHTML;
// s = s.match(/name="flashvars"\s+value="([^"]+)"/i);
// if (!s && s.length < 2) return;
// this.flashvars = unescape(s[1]).replace(/&/g,'&');
this.flashvars = this.player.children['flashvars'].value;
console.log('flashvars: ', this.flashvars);
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.data = {
id: 'movie_player',
swfMark: '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.buguanji.com/Public/Home/player/20141007/player.swf" width="100%" height="100%" id="movie_player" name="movie_player" bgcolor="#000000" isfullscreen="true" allowfullscreen="true" allowscriptaccess="always" wmode="transparent" flashvars="isShowRelatedVideo=false&showAd=0&show_ce=0&showsearch=0&VideoIDS={0}&isAutoPlay=true&winType=BDskin&Type=PlayList">'
};
}
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.data = {
id: 'tudouHomePlayer',
swfMark: '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.buguanji.com/Public/Home/player/20141007/player.swf" width="100%" height="100%" id="tudouHomePlayer" name="tudouHomePlayer" bgcolor="#000000" isfullscreen="true" allowfullscreen="true" allowscriptaccess="always" wmode="transparent" flashvars="isShowRelatedVideo=false&showAd=0&show_ce=0&showsearch=0&VideoIDS={0}&isAutoPlay=true&winType=BDskin&Type=PlayList">'
};
}
repeater=new Base();
repeater.extend({
isProc:function(){
return this.flashvars.indexOf('paidTime=600&') > 0;
},
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.data = {
id: 'flash',
swfMark: '<embed data-widget-player="flash" pluginspage="http://www.macromedia.com/go/getflashplayer" loop="true" play="true" quality="hight" devicefont="false" allowfullscreen="true" menu="true" type="application/x-shockwave-flash" width="100%" height="100%" src="{0}" id="flash" bgcolor="#000000" wmode="transparent" flashvars="components=feffbfe6e0&tvId={1}&autoplay=true&flashP2PCoreUrl={2}&cid=qc_100001_100141&origin=true&outsite=false&definitionID={3}" align="middle" hint="true" allowscriptaccess="always" Scale="NoScale">'
};
}
repeater=new Base();
repeater.extend({
isProc:function(){
//console.info(a.link_pay);
//return document.querySelector("style#797082642689");
return !document.querySelector("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.data = {
id: 'myDynamicContent',
swfMark: '<embed data-widget-player="flash" pluginspage="http://www.macromedia.com/go/getflashplayer" loop="true" play="true" quality="hight" devicefont="false" allowfullscreen="true" menu="true" type="application/x-shockwave-flash" width="100%" height="100%" src="http://www.iqiyi.com/common/flashplayer/20150311/MainPlayer_5_2_19_3_c3_2_4.swf" id="flash" bgcolor="#000000" wmode="transparent" flashvars="components=feffbfe6e0&tvId={0}&autoplay=true&flashP2PCoreUrl=http://www.iqiyi.com/common/flashplayer/20150216/30032.swf&cid=qc_100001_100141&origin=true&outsite=false&definitionID={1}" align="middle" hint="true" allowscriptaccess="always" Scale="NoScale">'
};
}
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() {
var me = this;
setTimeout(function(){
//Base.prototype.proc.apply(this, arguments);
Base.prototype.proc.call(me);
}, 399);
}
});
PpsTV.prototype=repeater;
router.register('pps.tv', PpsTV);
router.run();
})();