This repository was archived by the owner on Jun 17, 2022. It is now read-only.
forked from Kaijun/Video-Clean-Player-Offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
279 lines (272 loc) · 14.1 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
(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 YoukuAntiAds() {}
YoukuAntiAds.prototype = {
iURL: chrome.extension.getURL('swf/'), //本地地址,默认!
// iURL: 'http://noads.mujj.us/swf/', //在线地址
iURL_on: 'http://noads.mujj.us/swf/', //必须在线的地址
_players: null,
_rules: null,
_done: null,
get players() {
if(!this._players) {
this._players = {
//=====================在线版or本地版(由iURL决定)地址开始=================================================
//双虚线之前为在线地址,请自行需该服务器地址!如使用本地版请注释掉双虚线以上地址
'youku_loader': this.iURL + 'loader.swf',
'youku_player': this.iURL + 'player.swf',
'ku6': this.iURL + 'ku6.swf',
'ku6_out': this.iURL + 'ku6_out.swf',
'iqiyi': this.iURL + 'iqiyi.swf',
'iqiyi5': this.iURL + 'iqiyi5.swf',
'iqiyi_out': this.iURL + 'iqiyi_out.swf',
'pps': this.iURL + 'pps.swf',
'pplive': this.iURL + 'pplive.swf',
'pplive_live': this.iURL + 'pplive_live.swf',
'tudou': this.iURL + 'tudou.swf',
//'letv': this.iURL + 'letv.swf',
'sohu':this.iURL + 'sohu.swf',
'sohu_live': this.iURL + 'sohu_live.swf',
//======================必须在线版地址开始======================================================================================
//双虚线之间的地址不能换为本地地址,否则外联出错,请尽量更改为自己的服务器地址!
'letv': this.iURL_on + 'letv.swf',
'letv_c': this.iURL_on + 'letv0225.swf',
'tudou_olc': this.iURL_on + 'olc_8.swf',
'tudou_sp': this.iURL_on + 'sp.swf',
//'sohu': this.iURL_on + 'sohu.swf',
//'sohu_live': this.iURL_on + 'sohu_live.swf',
'17173_in_Vod': this.iURL_on + '17173.in.vod.swf',
'17173_out_Vod': this.iURL_on + '17173.out.vod.swf',
'17173_in_Live': this.iURL_on + '17173.in.live.swf',
'17173_out_Live': this.iURL_on + '17173.out.live.swf',
//========================必须在线版地址结束========================================================
};
}
return this._players;
},
get rules() {
if(!this._rules) {
this._rules = {
'youku_loader': {
'find': /^http:\/\/static\.youku\.com(\/v[\d\.]*)?\/v\/swf\/loaders?[^\.]*\.swf/i,
'replace': this.players['youku_loader']
},
'youku_player': {
'find': /^http:\/\/static\.youku\.com(\/v[\d\.]*)?\/v\/swf\/(q?player[^\.]*|\w{13})\.swf/i,
'replace': this.players['youku_loader']
},
'youku_out': {
'find': /^http:\/\/player\.youku\.com\/player\.php\/.*sid\/([\w=]+).*(\/v)?\.swf.*/i,
'replace': this.players['youku_loader'] + '?showAd=0&VideoIDS=$1'
},
'ku6': {
'find': /^http:\/\/player\.ku6cdn\.com\/default\/.*\/(v|player)[^\.]*\.swf/i,
'replace': this.players['ku6']
},
'ku6_out': {
'find': /^http:\/\/player\.ku6\.com\/(inside|refer)\/([^\/]+)\/v\.swf.*/i,
'replace': this.players['ku6_out'] + '?vid=$2'
},
'iqiyi': {
'find': /^https?:\/\/www\.iqiyi\.com\/(player\/(\d+\/Player|[a-z0-9]*)|common\/flashplayer\/\d+\/((PPS)?Main|Share)?Player.*_(.|ad\d+))\.swf/i,
'replace': this.players['iqiyi']
},
'iqiyi_out': {
'find': /^https?:\/\/player\.video\.i?qiyi\.com\/([^\/]*)\/.*tvId=([^-]*).*/i,
'replace': this.players['iqiyi_out'] + '?vid=$1&tvId=$2'
},
'iqiyi_out_2': {
'find': /^https?:\/\/(player|dispatcher)\.video\.i?qiyi\.com\/(.*\/shareplayer\.swf|qiyi)/i,
'replace': this.players['iqiyi_out']
},
'pps': {
'find': /^https?:\/\/www\.iqiyi\.com\/player\/cupid\/.*\/pps[\w]+.swf/i,
'replace': this.players['pps']
},
'pplive': {
'find': /^http:\/\/player\.pplive\.cn\/ikan\/.*\/player4player2\.swf/i,
'replace': this.players['pplive']
},
'pplive_live': {
'find': /^http:\/\/player\.pplive\.cn\/live\/.*\/player4live2\.swf/i,
'replace': this.players['pplive_live']
},
'tudou': {
'find': /^http:\/\/js\.tudouui\.com\/.*PortalPlayer[^\.]*\.swf/i,
'replace': this.players['tudou']
},
'tudou_out': {
'find': /^http:\/\/www\.tudou\.com\/.*(\/v\.swf)?/i,
'replace': this.players['tudou_olc'] + '?tvcCode=-1&swfPath=' + this.players['tudou_sp']
},
'letv': {
'find': /^http:\/\/.*letv[\w]*\.com\/.*\/((?!(Live|seed|Disk))(S[\w]{2,3})?(?!Live)[\w]{4}|swf|VLetv)Player[^\.]*\.swf/i,
'replace': this.players['letv']
},
'letv_hz': {
'find': /^http:\/\/.*letv[\w]*\.com\/(hz|.*player\/(s)?sdkletv)player\.swf.*/i,
'replace': this.players['letv']
},
'letv_cloud': {
'find': /^http:\/\/.*(letv[\w]*|dwstatic)\.com\/.*(cloud|vpp)\.swf/i,
'replace': this.players['letv_c']
},
'letv_out': {
'find': /^http:\/\/.*\.letvimg\.com\/.*\/(letvbili|lbplayer|letv-wrapper|acfunletv[^\.]*)\.swf/i,
'replace': this.players['letv']
},
'letv_skin': {
'find': /http:\/\/.*letv[\w]*\.com\/p\/\d+\/\d+\/(?!15)\d*\/newplayer\/\d+\/S?SLetvPlayer\.swf/i,
'replace': 'http://player.letvcdn.com/p/201407/24/15/newplayer/1/SSLetvPlayer.swf'
},
'sohu': {
'find': /^http:\/\/tv\.sohu\.com\/upload\/swf\/(?!(live|\d+)).*\d+\/(Main|PlayerShell)[^\.]*\.swf/i,
'replace': this.players['sohu']
},
'sohu_live': {
'find': /^http:\/\/(tv\.sohu\.com\/upload\/swf\/(live\/|)\d+|(\d+\.){3}\d+(:\d+)?\/.*player)\/(Main|PlayerShell)[^\.]*\.swf/i,
'replace': this.players['sohu_live']
},
'sohu_out_1': {
'find': /^http:\/\/.*\.sohu\.com\/my\/v\.swf(.*)/i,
'replace': this.players['sohu_live'] + '?$1'
},
'sohu_out_2': {
'find': /^http:\/\/.*\.sohu\.com\/(\d+)\/v\.swf/i,
'replace': this.players['sohu_live'] + '?vid=$1'
},
'17173_in_Vod': {
'find': /^http:\/\/f\.v\.17173cdn\.com\/(\d+\/)?flash\/PreloaderFile(Customer)?\.swf/i,
'replace': this.players['17173_in_Vod']
},
'17173_out_Vod_1': {
'find': /^http:\/\/f\.v\.17173cdn\.com\/player_f2\/(\w+)\.swf/i,
'replace': this.players['17173_out_Vod'] + '?cid=$1'
},
'17173_out_Vod_2': {
'find': /^(http:\/\/17173\.tv\.sohu\.com\/player[^\.]*\.swf)/i,
'replace': this.players['17173_out_Vod']
},
'17173_in_Live': {
'find': /^http:\/\/f\.v\.17173cdn\.com\/\d+\/flash\/Player_stream(_firstpage)?\.swf/i,
'replace': this.players['17173_in_Live']
},
'17173_out_Live': {
'find': /^http:\/\/v\.17173\.com\/live\/player\/Player_stream_(custom)?Out\.swf/i,
'replace': this.players['17173_out_Live'] + '?'
}
}
}
return this._rules;
},
get done() {
if(!this._done) {
this._done = new Array();
}
return this._done;
},
initPreHandlers: function() {
this.rules['iqiyi']['preHandle'] = function(elem, find, replace, player) {
if(document.querySelector('span[data-flashplayerparam-flashurl]')) {
replace = this.players['iqiyi5'];
}
this.reallyReplace.bind(this, elem, find, replace)();
}
this.rules['iqiyi_out']['preHandle'] = function(elem, find, replace, player) {
var match = player.match(/(autoplay)=[^&]+/ig);
if(match) {
replace += '&' + match.join('&');
}
this.reallyReplace.bind(this, elem, find, replace)();
}
this.rules['tudou_out']['preHandle'] = function(elem, find, replace, player) {
var fn = this;
var isFx = /firefox/i.test(navigator.userAgent);
GM_xmlhttpRequest({
method: isFx ? 'HEAD' : 'GET',
//url: isFx ? player : 'http://lovejiani.cdn.duapp.com/kafan/tfetcher?turl=' + encodeURIComponent(player + '/v.swf'),
url: isFx ? player : 'https://query.yahooapis.com/v1/public/yql?format=json&q=' + encodeURIComponent('use"https://haoutil.googlecode.com/svn/trunk/firefox/tudou_redirect.yql.xml" as tudou; select * from tudou where url="' + player + '" and referer="' + window.location.href + '"'),
onload: function(response) {
var finalUrl = (isFx ? response.finalUrl : response.responseText);
var match = finalUrl.match(/(iid|youkuid|resourceid|autoplay|snap_pic|code)=[^&]+/ig);
if(match && !/error/i.test(finalUrl)) {
replace += '&' + match.join('&');
fn.reallyReplace.bind(fn, elem, find, replace)();
}
}
});
}
},
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, isReplacing = 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']) {
isReplacing = true;
this.rules[i]['preHandle'].bind(this, elem, find, replace, player)();
}
if(!isReplacing) {
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'));
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() {
this.initPreHandlers();
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 YoukuAntiAds().init();
})();