-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsm.autofill.user.js
388 lines (330 loc) · 11 KB
/
fsm.autofill.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
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
// ==UserScript==
// @name 一键转种至 fsm
// @namespace https://github.com/tomyangsh/userscrips
// @match https://www.happyfappy.org/torrents.php?id=*
// @match https://our.kelu.one/details.php?id=*
// @match https://www.nicept.net/details.php?id=*
// @match https://rousi.zip/details.php?id=*
// @match https://share.ilolicon.com/details.php?id=*
// @match https://bitporn.eu/details.php?id=*
// @match https://kufirc.com/torrents.php?id=*
// @match https://kamept.com/details.php?id=*
// @match https://exoticaz.to/torrent/*
// @match https://www.pttime.org/details.php?id=*
// @match https://pornbay.org/torrents.php?id=*
// @match https://www.empornium.is/torrents.php?id=*
// @match https://www.empornium.sx/torrents.php?id=*
// @match https://kp.m-team.cc/detail/*
// @match https://zp.m-team.io/detail/*
// @match https://xp.m-team.cc/detail/*
// @match https://fsm.name/Torrents/new?autofill
// @grant GM_getValue
// @grant GM_setValue
// @grant GM.xmlHttpRequest
// @version 2.11.8
// @author 大統領
// @description 目前支持:馒头/emp/pb/ptt/exo/kamept/kufirc/bitporn/ilolicon/rousi/nicept/kelu/happyfappy
// @icon https://img.fsm.name/21/69/2169f715a4805d2643db30a4b8fd95d0.jpg
// ==/UserScript==
const HOST = document.location.host.match(/([^.]+)\.\w+$/)[1];
function process_luminance() {
const link_box = document.querySelector('div.linkbox');
const fsm_link = create_link(function () {
let title = document.querySelector('h2').innerText;
let info_node = document.querySelector('#descbox');
let img_list = []
image_cover = document.querySelector('#coverimage img').src.replace('resize/250/', '');
img_list.push(image_cover);
info_node.querySelectorAll('img').forEach(node => {
image = node.src.replace(/\.(th|md)(\.\w+)$/, '$2');
img_list.push(image);
});
const tag = document.querySelector('td.cats_col div').title;
const torrent_url = document.querySelector('a.blueButton').href;
const upload_info = {
"title": title,
"img_list": img_list,
"tag": tag,
"torrent_url": torrent_url
}
GM_setValue("upload_info", upload_info);
})
link_box.append(fsm_link);
}
function process_nexus() {
let subtitle;
let action_bar;
let tags = [];
document.querySelectorAll('td.rowhead').forEach(td => {
switch (td.innerText) {
case '资源标签':
case '標簽':
case '标签': {
td.nextElementSibling.querySelectorAll('span').forEach(span => {
tags.push(span.innerText);
})
break;
}
case '副標題':
case '副标题': {
subtitle = td.nextElementSibling.innerText;
break;
}
case '基本資訊':
case '基本信息': {
const attribute = td.nextElementSibling.innerText;
if (attribute.match('无码')) {
tags.push('无码');
} else if (attribute.match('有码')) {
tags.push('有码');
}
break;
}
case 'Basic Info': {
const type = td.nextElementSibling.innerText.match(/Type:\s(\w+)/)[1];
tags.push(type);
break;
}
case 'Action':
case '行為':
case '行为': {
action_bar = td.nextElementSibling;
break;
}
}
})
const fsm_link = create_link(function () {
const title = document.querySelector('h1').firstChild.textContent;
const info_node = document.querySelector('#kdescr');
const img_list = [];
info_node.querySelectorAll('img').forEach(img => {
image = img.src.replace('.thumb.jpg', '');
img_list.push(image);
})
const tag = tags.join();
const torrent_url = document.querySelector('a.index').href;
const upload_info = {
"title": title,
"subtitle": subtitle,
"img_list": img_list,
"tag": tag,
"torrent_url": torrent_url
}
GM_setValue("upload_info", upload_info);
})
action_bar.append(' | ');
action_bar.append(fsm_link);
}
function load_torrent(url) {
GM.xmlHttpRequest({
url: url,
method: "GET",
responseType: 'blob',
onload: res => {
const torrent_file = new window.File([res.response], 'file.torrent', { type: "application/x-bittorrent" });
const container = new DataTransfer();
container.items.add(torrent_file);
input_file = document.querySelector('input.el-upload__input');
input_file.files = container.files;
input_file.dispatchEvent(new Event('change'));
},
onerror: res => {
console.log(res);
alert("加载种子失败,可能是你点得太快了!");
}
})
}
function upload_img(source_url) {
referer = source_url.match(/https?:\/\/.+?\//)[0];
GM.xmlHttpRequest({
url: source_url,
method: "GET",
responseType: 'blob',
headers: {
'Referer': referer
},
onload: res => {
const image_file = new window.File([res.response], 'file.jpg');
const container = new DataTransfer();
container.items.add(image_file);
input_file = document.querySelectorAll('input.el-upload__input')[1];
input_file.files = container.files;
input_file.dispatchEvent(new Event('change'));
}
})
}
function add_observer(action) {
const observer = new MutationObserver(action);
const target = document.querySelector('title');
const config = { childList: true };
observer.observe(target, config);
}
function create_link(collect_data) {
const fsm_link = document.createElement('a');
fsm_link.innerText = '[转至 FSM]';
fsm_link.style = "cursor: pointer;";
fsm_link.onclick = function() {
collect_data();
const url_autofill = 'https://fsm.name/Torrents/new?autofill';
window.open(url_autofill, '_blank').focus();
}
GM_setValue("source_url", document.location.href);
return fsm_link;
}
switch (HOST) {
case 'happyfappy':
case 'kufirc':
case 'pornbay':
case 'empornium':
process_luminance();
break;
case 'kelu':
case 'nicept':
case 'rousi':
case 'ilolicon':
case 'bitporn':
case 'kamept':
case 'pttime':
process_nexus();
break;
case 'exoticaz': {
const action_bar = document.querySelector('div.p-2 div.float-right');
function collect_data () {
const title = document.querySelector('h1').innerText;
const img_list = [];
const tags = [];
document.querySelectorAll('#TorrentDescription img').forEach(img => {
img_list.push(img.src);
})
document.querySelectorAll('#screenshots img').forEach(img => {
img_list.push(img.src);
})
document.querySelectorAll('div.tags a').forEach(a => {
tags.push(a.innerText);
})
const tag = tags.join();
const torrent_url = document.querySelector('a.btn-xs').href;
const upload_info = {
"title": title,
"img_list": img_list,
"tag": tag,
"torrent_url": torrent_url
}
GM_setValue("upload_info", upload_info);
}
const fsm_link = create_link(collect_data);
action_bar.prepend(fsm_link);
break;
}
case 'm-team': {
function append_link() {
const fsm_link = create_link(function () {
const title = document.querySelector('h2 span').innerText;
let subtitle = '';
let img_list = [];
let tags = [];
document.querySelectorAll('th.ant-descriptions-item-label').forEach(th => {
switch (th.innerText) {
case '副標題': {
subtitle = th.nextSibling.innerText;
break;
}
case 'Tag': {
th.nextSibling.querySelectorAll('span div div').forEach(tag_node => {
tags.push(tag_node.innerText);
})
break;
}
case '基本資訊': {
const attribute = th.nextSibling.innerText;
if (attribute.match('無碼')) {
tags.push('无码');
} else if (attribute.match('有碼')) {
tags.push('有码');
} else if (attribute.match('寫真')) {
tags.push('写真');
} else if (attribute.match('遊戲')) {
tags.push('黄油');
} else if (attribute.match('漫畫')) {
tags.push('漫画');
} else if (attribute.match('動畫')) {
tags.push('动画');
}
break;
}
}
});
tag = tags.join();
document.querySelectorAll('.braft-output-content img').forEach(img => {
img_list.push(img.src);
});
torrent_id = document.location.href.match(/\d+/)[0];
const form_data = new FormData();
form_data.append("id", torrent_id)
GM.xmlHttpRequest({
url: 'https://api.m-team.cc/api/torrent/genDlToken',
method: 'POST',
responseType: 'json',
data: form_data,
headers: {
"authorization": localStorage.getItem('auth')
},
synchronous: false,
onload: res => {
console.log(res);
const torrent_url = res.response.data;
const upload_info = {
"title": title,
"subtitle": subtitle,
"img_list": img_list,
"tag": tag,
"torrent_url": torrent_url
}
GM_setValue("upload_info", upload_info);
}
})
})
let action_bar;
document.querySelectorAll('span').forEach(node => {
if (node.innerText == '行為') {
action_bar = node.parentNode.nextSibling.childNodes[0].childNodes[0];
}
})
action_bar.append(fsm_link);
}
add_observer(append_link);
break;
}
case 'fsm': {
function fill_info(mutations) {
if (!document.querySelector('title').innerText.match('FSM')) {return;}
const editor = document.querySelector('div.ql-editor');
const upload_info = GM_getValue("upload_info");
const note_node = document.createElement('div');
note_node.innerText = "请等待下方图片全部上传完成后再点击发布!记得删去不必要的图片,及拖动改变顺序,第一张图片会用作封面";
editor.parentNode.parentNode.parentNode.prepend(note_node);
input_title = document.querySelectorAll('label')[1].control;
input_title.value = upload_info.title;
input_title.dispatchEvent(new Event('input'));
input_tag = document.querySelectorAll('label')[2].control;
input_tag.value = upload_info.tag;
input_tag.dispatchEvent(new Event('input'));
input_source = document.querySelectorAll('label')[3].control;
input_source.value = GM_getValue("source_url");
input_source.dispatchEvent(new Event('input'));
if (upload_info.subtitle) {
subtitle_node = document.createElement('p');
subtitle_node.innerText = upload_info.subtitle;
editor.append(subtitle_node);
}
for (img_url of upload_info.img_list) {
upload_img(img_url);
}
if (upload_info.torrent_url) {
load_torrent(upload_info.torrent_url);
}
}
add_observer(fill_info);
break;
}
}