-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwhereToWatch.js
353 lines (320 loc) · 10.4 KB
/
whereToWatch.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// ==UserScript==
// @name 哪里看
// @namespace http://tampermonkey.net/
// @version 0.1.3
// @description 在豆瓣网页检索哪里可以看对应电影,电视剧
// @author no name
// @match https://movie.douban.com/subject/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=douban.com
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @connect yysub.net
// @connect 88hd.com
// @connect so.iqiyi.com
// @connect v.qq.com
// @connect so.youku.com
// @license MIT
// ==/UserScript==
// 获取对应网站信息
function getMovieFromWebSite() {
// 获取豆瓣页面电影名字
let movieName = getMovieNameFromDouBan()
//获取 YYeTs
const YYeTs = new Promise(function (resolve, reject) {
let getMovieIdUrl = `https://www.yysub.net/search/index?keyword=${movieName}&search_type=`
getMovieId(getMovieIdUrl, resolve, reject)
}).then(function (val) {
createLi(val[1], "人人字幕组", val[0])
createCss()
})
//获取 88 影视
// const _88hub = new Promise(function (resolve, reject) {
// let getMovieIdUrl = `https://www.88hd.com/search/`
// getMovieIdFrom88hub(getMovieIdUrl, resolve, reject)
// }).then(function (val) {
// createLi(val[1], "人人字幕组", val[0])
// createCss()
// })
// 获取爱奇艺影视
const aiqiyi = new Promise(function (resolve, reject) {
let getMovieIdUrl = `https://so.iqiyi.com/so/q_${movieName}`
getMovieIdFromAiQiYi(getMovieIdUrl, resolve, reject)
}).then(function (val) {
createLi(val[1], "爱奇艺", val[0])
createCss()
})
// 获取腾讯视频
const tengxun = new Promise(function (resolve, reject) {
let getMovieIdUrl = `https://v.qq.com/x/search/?q=${movieName}`
getMovieIdFromTengXun(getMovieIdUrl, resolve, reject)
}).then(function (val) {
createLi(val[1], "腾讯视频", val[0])
createCss()
})
// 获取优酷视频
const youku = new Promise(function (resolve, reject) {
let getMovieIdUrl = `https://so.youku.com/search_video/q_${movieName}`
getMovieIdFromYouKu(getMovieIdUrl, resolve, reject)
}).then(function (val) {
createLi(val[1], "优酷视频", val[0])
createCss()
})
}
// 获取人人影视电影的 Id, 通过是否有 Id 来判断是否有资源
function getMovieId(getMovieIdUrl, resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
url: getMovieIdUrl,
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
data: "",
onload: function (response) {
const regexpResourceId = /\/resource\/[0-9]+/
let resourceMovieId = response.responseText.match(regexpResourceId)
let info = new Array();
if (resourceMovieId === null) {
info = [0, ""]
} else {
console.log("resourceMovieId", resourceMovieId[0])
// 提取电影 id
const regexpMovieId = /[0-9]{5,5}/
// 将数组元素 resourceMovieId 转换成字符串
movieId = resourceMovieId.toString().match(regexpMovieId)
console.log("movieId", movieId[0].toString())
// 传递的数组
info = [1, "https://www.yysub.net/resource/list/" + movieId]
}
resolve(info)
},
onerror: function (response) {
let info = [-1, ""]
reject(info)
}
});
}
// 获取 88 影视的 Id, 通过是否有 Id 来判断是否有资源
// function getMovieIdFrom88hub(getMovieIdUrl, resolve, reject) {
// GM_xmlhttpRequest({
// method: "POST",
// url: getMovieIdUrl,
// headers: {
// "Content-Type": "application/x-www-form-urlencoded"
// },
// data: "wd=%E6%A2%A6%E5%8D%8E%E5%BD%95&submit=",
// onload: function (response) {
// console.log("请求成功")
// console.log(response.responseText)
// resolve(1)
// },
// onerror: function (response) {
// console.log("请求失败", response);
// reject(0)
// }
// });
// }
// 获取爱奇艺影视的资源
function getMovieIdFromAiQiYi(getMovieIdUrl, resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
url: getMovieIdUrl,
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
data: "",
onload: function (response) {
let info = new Array();
const resourceScore = `title-score`
let isMatch = response.responseText.match(resourceScore)
if (isMatch != null) {
info[0] = 1
info[1] = getMovieIdUrl
} else {
info[0] = 0
info[1] = ""
}
resolve(info)
},
onerror: function (response) {
let info = [-1, ""]
reject(info)
}
});
}
// 获取腾讯视频的资源
function getMovieIdFromTengXun(getMovieIdUrl, resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
url: getMovieIdUrl,
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
data: "",
onload: function (response) {
let info = new Array();
const resourceScore = `result_score`
let isMatch = response.responseText.match(resourceScore)
if (isMatch != null) {
info[0] = 1
info[1] = getMovieIdUrl
} else {
info[0] = 0
info[1] = ""
}
resolve(info)
},
onerror: function (response) {
let info = [-1, ""]
reject(info)
}
});
}
// 获取优酷资源
function getMovieIdFromYouKu(getMovieIdUrl, resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
url: getMovieIdUrl,
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
data: "",
onload: function (response) {
let info = new Array();
console.log(response.responseText)
const resourceScore = `data-spm="PhoneSokuProgram_1"`
let isMatch = response.responseText.match(resourceScore)
const playSource = `播放源`
let isExitPlaySource = response.responseText.match(playSource)
if (isMatch != null && isExitPlaySource == null) {
info[0] = 1
info[1] = getMovieIdUrl
} else {
info[0] = 0
info[1] = ""
}
resolve(info)
},
onerror: function (response) {
let info = [-1, ""]
reject(info)
}
});
}
/*
以下是工具方法
*/
// 公共 HTML
function createHTML() {
// 获取豆瓣右侧栏节点
let aside = document.querySelector(".aside")
// 获取豆瓣片单推荐
let subject_doulist = document.querySelector("#subject-doulist")
// 创建自己的插件展示根节点
let wrap = document.createElement("div")
// 为该根节点添加类名
wrap.classList.add("subject-wheretowatch")
wrap.innerHTML = `<h2>
<i>哪里看</i>
· · · · · ·
<span class="p1">
(
<a href="https://github.com/Eternaldeath/whereToWatch/issues">纠错与建议</a>
)
</span>
</h2>
<ul class="ulInfo"></ul>
<p class="note">全网搜索,仅显示最终播放源</P>
`
aside.insertBefore(wrap, subject_doulist)
}
// 生成 li
function createLi(url, siteName, res) {
let ulInfo = document.querySelector(".subject-wheretowatch .ulInfo")
let li = document.createElement("li")
if (res === 1) {
li.innerHTML = `
<span>${siteName}</span>
<span>
<a href=${url}>资源链接</a>
</span>
`
} else if (res === 0) {
li.innerHTML = `
<span>${siteName}</span>
<span style="color: red">暂无资源</span>
`
} else if (res === -1) {
li.innerHTML = `
<span>${siteName}</span>
<span style="color: red">请求失败</span>
`
}
ulInfo.appendChild(li)
}
// 生成基本 css 样式
function createCss() {
const css = `.subject-wheretowatch{
margin-bottom: 40px;
word-wrap: break-word;
}
.subject-wheretowatch ul{
border-top: 1px dashed #DDD;
list-style: none;
}
.subject-wheretowatch li{
padding: 4.5px 0;
border-bottom: 1px dashed #DDD;
}
.subject-wheretowatch .p1{
font: 13px Arial, Helvetica, sans-serif;
line-height: 150%;
color: #666666;
}
.subject-wheretowatch a:link{
color: #37a;
text-decoration: none;
}
.subject-wheretowatch a{
cursor: pointer;
}
.subject-wheretowatch .none{
display: none;
}
.subject-wheretowatch .note{
color: #999AAA;
font-size: 6px;
font-weight: bold;
}
`
GM_addStyle(css)
}
/*
根据返回值隐藏模块
*/
// function displayNoneByRes(res) {
// let span = document.querySelectorAll(".subject-wheretowatch ul span")
// if (res === 1) {
// // 隐藏“暂无资源”
// span[2].style.cssText = 'display: none'
// // 隐藏请求失败模块
// ulError.style.cssText = 'display: none'
// } else if (res === 0) {
// // 隐藏“资源链接”
// span[1].style.cssText = 'display: none'
// span[2].style.cssText = 'color: #FF0000; font-weight: bold'
// // 隐藏请求失败模块
// ulError.style.cssText = 'display: none'
// } else if (res === -1) {
// ulInfo.style.cssText = 'display: none'
// }
// }
// 获取豆瓣页面电影资源标题
function getMovieNameFromDouBan() {
let movieFullName = document.querySelector("#content > h1 > span").innerHTML
let movieName = movieFullName.split(' ')[0]
return movieName
}
(function () {
getMovieFromWebSite()
createHTML()
})();