-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
235 lines (206 loc) · 7.93 KB
/
main.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
"use strict";
const rarbgURL = 'https://rarbg.is/download.php?';
const dyttURL = 'http://www.dytt8.net';
const rarbgHosts = [
{host: 'https://rarbgmirror.com', response: 9999},
{host: 'https://rarbg.is', response: 9999},
{host: 'https://rarbg.to', response: 9999},
{host: 'https://rarbgunblock.com', response: 9999},
{host: 'http://rarbgs.com', response: 9999},
{host: 'http://rarbg4-to.unblocked.lol', response: 9999},
{host: 'https://rarbg.unblocked.bet', response: 9999},
{host: 'http://rarbg-to.pbproxy.red', response: 9999},
{host: 'https://rarbg.unblocked.cool', response: 9999},
{host: 'https://rarbg.unblockall.org', response: 9999}
];
var rarbgResponsed = false;
var currentRarbgHost = null;
function getValidRarbgHost(success) {
console.log(rarbgHosts);
for (const item of rarbgHosts) {
//const url = item.host + '/index8.php';
const url = item.host;
const start_time = new Date().getTime();
getAsyncHTML(url,
(data) => {
if (rarbgResponsed) {
return;
}
const request_time = new Date().getTime() - start_time;
item.response = request_time;
// sort with response time, next time with start with lower response
rarbgHosts.sort((a, b) => a.response - b.response);
console.log(item.host, 'responsed', request_time);
rarbgResponsed = true;
currentRarbgHost = item.host;
success();
},
(error) => {
console.log(item.host, error);
})
}
}
function getAsyncHTML(url, resolve, reject) {
$.ajax(url).done(resolve).fail(reject);
}
function getRecommend(success, error) {
const url = currentRarbgHost + "/torrents.php?category=movies";
console.log(url);
getAsyncHTML(url, success, error);
}
function recommendResolve(dataSet) {
if (dataSet.indexOf('Please wait while we try to verify your browser') > 0) {
console.log(currentRarbgHost, 'need verify');
for (let i = 0, len = rarbgHosts.length; i < len; i++) {
if (currentRarbgHost === rarbgHosts[i].host) {
rarbgHosts.splice(i, 1);
currentRarbgHost = null;
rarbgResponsed = false;
break;
}
}
getValidRarbgHost(() => {
// rarbg今日推荐
new Promise((success, error) => getRecommend(
success, error))
.then(recommendResolve)
.catch(reject);
})
return;
}
console.log('recommendResolve', currentRarbgHost);
const newData = dataSet.replace(/<img((?!over_opt).)*(?:>|\/>)/gi,'');
const jqData = $(newData);
const $td = jqData.find('td .lista').has('a[href^="/torrent/"] img');
for (const td of $td) {
const a = $(td).find('a').eq(0);
const img = $(td).find('img').eq(0);
img.attr('src', 'https://' + img.attr('src'));
const id = $(a).attr('href').match(/\/torrent\/(.*)/)[1];
const title = $(a).attr('title');
const downloadURL = rarbgURL + 'id=' + id + '&f=' + title + '-[rarbg.to].torrent';
const itemHTML = `<div class="img" >
<a href="${downloadURL}" alt="${title}" data-balloon="${title}" data-balloon-pos="up">
<img src="${img.attr('src')}" border="0" alt="${title}">
</a>
</div>`;
$('.recommend').append($(itemHTML));
}
}
function getTop100(success, error) {
const url = currentRarbgHost + "/top100.php?category[]=14&category[]=15&category[]=16&category[]=17&category[]=21&category[]=22&category[]=42&category[]=44&category[]=45&category[]=46&category[]=47&category[]=48";
console.log(url);
getAsyncHTML(url, success, error);
}
function top100Resolve(dataSet) {
console.log('top100Resolve');
const newData = dataSet.replace(/<img.*?(?:>|\/>)/gi,'');
const jqData = $(newData);
const trArr = jqData.find('tr.lista2');
for (const tr of trArr) {
const tdArr = $(tr).find('td');
const $a = $(tdArr[1]).find('a').eq(0);
const title = $a.attr('title');
const detail = $(tdArr[1]).find('span').eq(1).text();
const size = $(tdArr[3]).text();
const id = $a.attr('href').match(/\/torrent\/(.*)/)[1];
const downloadURL = rarbgURL + 'id=' + id + '&f=' + title + '-[rarbg.to].torrent';
const itemHTML = `<div class="item">
<div class="title">
<h3>
<a href="${downloadURL}" alt="${title}">
${title}
</a>
</h3>
<span class="size">${size}</span>
</div>
<div class="detail">
${detail}
</div>
</div>`;
$('.top100').append($(itemHTML));
}
}
function getDyttItem(url) {
return new Promise(function(resolve, reject) {
getAsyncHTML(url, resolve, reject);
});
}
function dyttItemResolve(data) {
// Remove all images
const newData = data.replace(/<img.*?(?:>|\/>)/gi,'');
const jqData = $(newData);
const title = jqData.find('.bd3r .co_area2 .title_all').text();
const tempA = jqData.find('a[href^="ftp"]');
// 转换成迅雷url格式
const downloadURL = ThunderEncode(tempA.attr('href'));
const itemHTML = `<div class="item">
<div class="title">
<h3>
<a href="${downloadURL}" alt="${title}">
${title}
</a>
</h3>
<span class="size"></span>
</div>
<div class="detail"></div>
</div>`;
$('.dytt').append($(itemHTML));
}
function dyttResolve(data) {
const newData = data.replace('<img', '<noimg');
const areaArr = $(newData).find('.co_area2');
for (const area of areaArr) {
const title = $(area).find('.title_all').text();
if (title === '最新发布170部影视') {
const aArr = $(area).find('a');
// 第一个元素是‘IMDB评分8分以上影片200部' 去掉
aArr.splice(0, 1);
for (const a of aArr) {
setTimeout(function () {
const url = dyttURL + a.pathname;
getDyttItem(url)
.then(dyttItemResolve)
.catch(reject);
}, 500);
}
}
}
}
function getDytt(success, error) {
const url = "http://www.dytt8.net/index.htm";
getAsyncHTML(url, success, error);
}
function reject(reason) {
console.log(reason);
}
document.addEventListener('DOMContentLoaded', function() {
// tab section related
(function() {
[].slice.call(document.querySelectorAll('.tabs')).forEach(function(el) {
new CBPFWTabs(el);
});
})();
// append img logo div
const imgURL = chrome.extension.getURL("icon.png");
$('.codrops-logo').append(`<img src="${imgURL}"/>`);
// 电影天堂
new Promise((success, error) => getDytt(
success, error))
.then(dyttResolve)
.then(attachRatingEvent4Dytt)
.catch(reject);
getValidRarbgHost(() => {
// rarbg今日推荐
new Promise((success, error) => getRecommend(
success, error))
.then(recommendResolve)
.catch(reject);
// rarbg最受欢迎top100
new Promise((success, error) => getTop100(
success, error))
.then(top100Resolve)
.then(attachRatingEvent)
.catch(reject);
})
});