-
Notifications
You must be signed in to change notification settings - Fork 166
/
Video_wipe_ADs.user.js
226 lines (184 loc) · 5.68 KB
/
Video_wipe_ADs.user.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
// ==UserScript==
// @name Video wipe ADs
// @version 20140412
// @namespace Shuangya
// @author Shuangya
// @modified ywzhaiqi
// @description 去除国内视频网站的广告
// @include http://v.youku.com/v_show/id*
// @include http://www.letv.com/ptv/vplay*
// @include http://www.iqiyi.com/v_*
// @include http://v.ku6.com/show/*
// @include http://v.qq.com/cover/*
// @include http://tv.sohu.com/20*
// @grant GM_xmlhttpRequest
// @icon http://tb.himg.baidu.com/sys/portrait/item/0b43e3f1d1c4501a
// updateURL http://firefox.sylingd.com/script/source/8.meta.js
// downloadURL http://firefox.sylingd.com/script/source/8.user.js
// ==/UserScript==
(function(){
console.log('Video wipe ADs started!');
var sites = [
// [名称,地址,选择方式,选择]
['youku', 'http://v.youku.com/v_show', 'id', 'player'],
['letv', 'http://www.letv.com/ptv/vplay', 'id', 'fla_box'],
['iqiyi', 'http://www.iqiyi.com/v', 'id', 'flashbox'],
['ku6', 'http://v.ku6.com/show/', 'id', 'kplayer'],
['qq', 'http://v.qq.com/cover/', 'id', 'mod_player'],
['sohu', 'http://tv.sohu.com/20', 'id', 'sohuplayer']
]
var locationHref = window.location.href;
var playerElem,
playerID,
oPlayerHTML; // 原始播放器的 innerHTML
for (var i = 0, len = sites.length, site; i < len; i++) {
site = sites[i];
if (locationHref.indexOf(site[1]) >= 0) {
if (site[2] == 'id') {
playerElem = document.getElementById(site[3]);
playerID = site[3];
break;
}
//if (site[2]=='class') playerElem=document.getElementById(site[3]);
}
}
if (!playerElem) {
return;
}
var VIDEO_FORMAT = {
normal: '标清',
high: '高清',
super: '超清',
// super2: '原画'
};
var CSS = function() {/*
.gm-video-selected {
color: red;
}
#gm-video-format-container {
position: fixed;
zIndex: 6000;
top: 40%;
right: 0;
backgroundColor: white;
border: 1px solid rgb(221,221,221);
padding: 2px;
borderRadius: 5px;
}
*/}.toString().match(/\/\*([\s\S]+)\*\//)[1];
var parseHTML = function(html) {
var doc;
try {
// firefox and chrome 30+,Opera 12 会报错
doc = new DOMParser().parseFromString(html, 'text/html');
} catch (ex) {}
if (!doc) {
doc = document.implementation.createHTMLDocument("");
doc.querySelector('html').innerHTML = html;
}
return doc;
};
var addScript = function(src, text) {
var script = document.createElement('script');
script.type = 'text/javascript';
if (src) {
script.src = src;
} else if (text) {
script.textContent = text;
}
document.body.appendChild(script);
};
var addStyle = function(text) {
var style = document.createElement('style');
style.textContent = text;
document.head.appendChild(style);
};
var addPlayer = function (urls) {
GM_xmlhttpRequest({
method:"GET",
url:'http://git.oschina.net/sy/shuangya/raw/master/userjs/wipeads/ckplayer.js',
onload:function(jdata){
addScript(null, jdata.responseText);
var scriptText = "var flashvars={f:'" + urls.replace(/\|$/gi, '') + "',c:0,v:100};" +
"var params={bgcolor:'#FFF',allowFullScreen:true,allowScriptAccess:'always'};" +
"CKobject.embedSWF('http://www.ckplayer.com/ckplayer6.3/ckplayer.swf','" +
playerID + "','syplayer','100%','100%',flashvars,params);";
addScript(null, scriptText);
}
});
};
var clean = function() {
playerElem.style.background = 'url(https://code.csdn.net/u014469252/shuangya/blob/master/userjs/wipeads/loading.png) no-repeat center center rgb(0,0,0)';
oPlayerHTML = playerElem.innerHTML;
playerElem.innerHTML = '';
};
var createFormatButton = function(urls, format, isSelected) {
var button = document.createElement('a');
button.setAttribute('style', 'display:block;border:none;background:none;');
button.innerHTML = VIDEO_FORMAT[format];
if (isSelected) {
button.classList.add('gm-video-selected');
}
var address = '{f->' + urls.replace(/\|$/gi, '') + '}';
button.setAttribute('onclick',
'CKobject.getObjectById("syplayer").ckplayer_newaddress("' + address + '");' +
'jQuery(".gm-video-selected").removeClass("gm-video-selected");' +
'jQuery(this).addClass("gm-video-selected");'
);
return button;
};
var addFormatContainer = function () {
var qxdiv = document.createElement('div');
qxdiv.id = 'gm-video-format-container';
if (location.host.match(/youku/)) {
qxdiv.style.right = '50px';
}
document.body.appendChild(qxdiv);
return qxdiv;
};
var getFlvcd = function(format, callback) {
GM_xmlhttpRequest({
method:"GET",
overrideMimeType: 'text/html; charset=gb2312',
url:'http://www.flvcd.com/parse.php?format=' + format + '&kw=' + encodeURIComponent(locationHref),
onload: function (res) {
var doc = parseHTML(res.responseText);
var input = doc.querySelector('input[name="inf"]');
if (!input) {
console.error('Flvcd 解析错误');
return;
}
var urls = input.getAttribute('value');
var newFormat = 'normal';
var name = doc.querySelector('input[name="name"]').getAttribute('value');
for (var f in VIDEO_FORMAT) {
if (name.indexOf(VIDEO_FORMAT[f]) > 0) {
newFormat = f;
break;
}
}
callback(urls, newFormat);
}
});
};
var init = function() {
addStyle(CSS);
getFlvcd('super', function(urls, format) {
var container = addFormatContainer();
container.appendChild(createFormatButton(urls, format, true));
clean();
addPlayer(urls);
addScript('http://www.ckplayer.com/js6.2/offlights.js');
// 添加其他清晰度
var formats = Object.keys(VIDEO_FORMAT);
formats.reverse();
var others = formats.slice(formats.indexOf(format) + 1, formats.length);
others.forEach(function(fom){
getFlvcd(fom, function(u, f){
container.appendChild(createFormatButton(u, f));
});
});
});
}
init();
})();