自动获取磁链接并自动离线下载

As of 03/04/2016. See the latest version.

  1. // ==UserScript==
  2. // @name 挊
  3. // @namespace 撸
  4. // @description 自动获取磁链接并自动离线下载
  5.  
  6. // @include http*://avmo.pw/*
  7. // @include http*://avso.pw/*
  8. // @include http*://avxo.pw/*
  9.  
  10. // @include http*://*5avlib.com/*
  11. // @include http*://*look4lib.com/*
  12. // @include http*://javlib3.com/*
  13. // @include http*://*javlibrary.com/*
  14. // @include http*://*javli6.com/*
  15.  
  16. // @include http*://www.libredmm.com/products/*
  17. // @include http*://www.javbus.com/*
  18. // @include http*://www.javbus.me/*
  19. // @include http*://www.javbus2.com/*
  20. // @include http*://www.javbus3.com/*
  21. // @include http*://www.javbus5.com/*
  22.  
  23. // @include http*://avdb.la/movie/*
  24. // @include http*://www.141jav.com/view/*
  25. // @include http*://www.av4you.net/work/*.htm
  26. // @include http*://www.dmmy18.com/*
  27.  
  28. // @include http*://pan.baidu.com/disk/home*
  29. // @include http*://115.com/?tab=offline&mode=wangpan
  30. // @include http*://cloud.letv.com/webdisk/home/index
  31. // @include http*://disk.yun.uc.cn/
  32. // @include http*://www.furk.net/users/files/add
  33. // @include *.yunpan.360.cn/my/
  34. // @include http://www.dmm.co.jp/digital/videoa/*
  35. // @include http://www.btcherry.org/*
  36. // @include https://btdigg.org/search*
  37.  
  38. // @version 1.34
  39. // @run-at document-end
  40. // @grant GM_xmlhttpRequest
  41. // @grant GM_setClipboard
  42. // @grant GM_setValue
  43. // @grant GM_getValue
  44. // @grant GM_addStyle
  45. // @grant GM_registerMenuCommand
  46. // ==/UserScript==
  47. /*
  48. // @include https://btdigg.org/search*
  49. // @include http://www.cilizhushou.com/search/*
  50. // @include http://www.minnano-av.com/av*
  51. // @include http://www.oisinbosoft.com/dera/*
  52.  
  53. */
  54. var main = {
  55. //av信息查询 类
  56. jav: {
  57. type: 0,
  58. re: /(avmo|avso|avxo).*movie.*/,
  59. vid: function() {
  60. return $('.header')[0].nextElementSibling.innerHTML;
  61. },
  62. proc: function(tab) {
  63. insert_after('#movie-share');
  64. }
  65. },
  66. javlibrary: {
  67. type: 0,
  68. re: /(javlibrary|javlib3|look4lib|5avlib|javli6).*\?v=.*/,
  69. vid: function() {
  70. return $('#video_id')[0].getElementsByClassName('text')[0].innerHTML;
  71. },
  72. proc: function(tab) {
  73. insert_after('#video_favorite_edit');
  74. }
  75. },
  76. libredmm: {
  77. type: 0,
  78. re: /libredmm/,
  79. vid: function() {
  80. return location.href.match(/products\/(.*)/)[1];
  81. },
  82. proc: function(tab) {
  83. insert_after('.container');
  84. }
  85. },
  86. dmm: {
  87. type: 0,
  88. re: /dmm\.co\.jp/,
  89. vid: function() {
  90. var result = location.href.replace(/.*cid=/, '').replace(/\/\??.*/, '').match(/[^h_0-9].*/);
  91. return result[0] ? result[0].replace('00', '') : '';
  92. },
  93. proc: function(tab) {
  94. insert_after('.lh4');
  95. },
  96. },
  97. minnano: {
  98. type: 0,
  99. re: /minnano-av/,
  100. vid: function() {
  101. var elems = $('.t11');
  102. var r = '';
  103. for (var i = 0; i < elems.length; i++) {
  104. if (elems[i].textContent == '品番') {
  105. r = elems[i].nextElementSibling.textContent;
  106. break;
  107. }
  108. }
  109. return r;
  110. },
  111. proc: function(tab) {
  112. var tmp = (function() {
  113. var a = $('table');
  114. for (var i = 0; i < a.length; i++) {
  115. if (a[i].bgColor == '#EEEEEE') {
  116. return a[i];
  117. }
  118. }
  119. })();
  120. insert_after(tmp);
  121. }
  122. },
  123. oisinbosoft: {
  124. type: 0,
  125. re: /oisinbosoft/,
  126. vid: function() {
  127. var r = location.pathname.replace(/.*\/+/, '').replace('.html', '');
  128. return r.indexOf('-') == r.lastIndexOf('-') ? r : r.replace(/\w*-?/, '');
  129. },
  130. proc: function(tab) {
  131. // add_style('#magnet-tab table{clear:both;}');
  132. insert_after('#detail_info');
  133. }
  134. },
  135. javbus: {
  136. type: 0,
  137. re: /javbus/,
  138. vid: function() {
  139. var a = $('.header')[0].nextElementSibling;
  140. return a ? a.textContent : '';
  141. },
  142. proc: function(tab) {
  143. insert_after('#star-div');
  144. }
  145. },
  146. avdb: {
  147. type: 0,
  148. re: /avdb\.la/,
  149. vid: function() {
  150. return $('.info')[0].firstElementChild.innerHTML.replace(/<.*>/, '').trim();
  151. },
  152. proc: function(tab) {
  153. insert_after($('#downs')[0].previousElementSibling);
  154. }
  155. },
  156. jav141: {
  157. type: 0,
  158. re: /141jav/,
  159. vid: function() {
  160. return location.href.match(/view\/(.*)\//)[1];
  161. },
  162. proc: function(tab) {
  163. insert_after($('.dlbtn')[0].previousElementSibling);
  164. },
  165. },
  166. av4you: {
  167. type: 0,
  168. re: /av4you/,
  169. vid: function() {
  170. return $('.star-detail-name')[0].textContent.trim();
  171. },
  172. proc: function(tab) {
  173. insert_after('.star-detail');
  174. }
  175. },
  176. dmmy18_sin: {
  177. type: 0,
  178. re: /dmmy18\.com\/details\.aspx\?id=.*/,
  179. vid: function() {
  180. return $('.info li')[0].textContent.replace('番号:', '');
  181. },
  182. proc: function(tab) {
  183. insert_after('.head_coverbanner');
  184. },
  185. },
  186. //网盘下载 类
  187. //这些 $ 是真正的 jquery
  188. baidu: {
  189. type: 1,
  190. re: /pan\.baidu\.com/,
  191. fill_form: function(magnet) {
  192. document.querySelector('.g-button[data-button-id=b13]').click();
  193. setTimeout(function() {
  194. document.querySelector('#_disk_id_2').click();
  195. setTimeout(function() {
  196. document.querySelector('#share-offline-link').value = magnet;
  197. document.querySelector('.g-button[data-button-id=b63]').click();
  198. }, 500);
  199. }, 1500);
  200. }
  201. },
  202. 115: {
  203. type: 1,
  204. re: /115\.com/,
  205. fill_form: function(link) {
  206. var rsc = setInterval(function() {
  207. if (document.readyState == 'complete') {
  208. clearInterval(rsc);
  209. setTimeout(function() {
  210. Core['OFFL5Plug'].OpenLink();
  211. setTimeout(function() {
  212. $('#js_offline_new_add').val(link);
  213. }, 300);
  214. }, 1000);
  215. }
  216. }, 400);
  217. }
  218. },
  219. letv: {
  220. type: 1,
  221. re: /cloud\.letv\.com/,
  222. fill_form: function(link) {
  223. setTimeout(function() {
  224. $('#offline-btn').click();
  225. setTimeout(function() {
  226. $('#offline_clear_complete').prev().click();
  227. setTimeout(function() {
  228. $('#offline-add-link').val(link);
  229. }, 500);
  230. }, 1000);
  231. }, 2000);
  232. }
  233. },
  234. furk: {
  235. type: 1,
  236. re: /www\.furk\.net/,
  237. fill_form: function(link) {
  238. setTimeout(function() {
  239. $('#url').val(link.replace('magnet:?xt=urn:btih:', ''));
  240. }, 1500);
  241. }
  242. },
  243. 360: {
  244. type: 1,
  245. re: /yunpan\.360\.cn\/my/,
  246. fill_form: function(link) {
  247. yunpan.cmdCenter.showOfflineDia();
  248. setTimeout(function() {
  249. $('.offdl-btn-create').click();
  250. setTimeout(function() {
  251. $('#offdlUrl').val(link);
  252. }, 500);
  253. }, 1000);
  254. }
  255. },
  256. uc: {
  257. type: 1,
  258. re: /disk\.yun\.uc\.cn\//,
  259. fill_form: function(link) {
  260. setTimeout(function() {
  261. $('#newuclxbtn_index').click();
  262. setTimeout(function() {
  263. $('#uclxurl').val(link);
  264. }, 1000);
  265. }, 1200);
  266. }
  267. },
  268. //磁链接搜索 类
  269. btcherry_a: {
  270. type: 2,
  271. re: /btcherry\.org\/search\?keyword=.*/,
  272. func: function(tab) {
  273. var selector = '.r div a';
  274. var a = $(selector);
  275. for (var i = 0; i < a.length; i++) {
  276. var b = tab.cloneNode(true);
  277. b.setAttribute('maglink', a[i].href);
  278. //console.log(a[i].href)
  279. a[i].parentElement.appendChild(b);
  280. }
  281. },
  282. },
  283. btcherry_b: {
  284. type: 2,
  285. re: /btcherry\.org\/hash\/.*/,
  286. func: function(tab) {
  287. var selector = '#content div ul';
  288. var a = $(selector)[0];
  289. tab.setAttribute('maglink', $('li a', a)[0]);
  290. a.parentElement.insertBefore(tab, a);
  291. },
  292. },
  293. btdigg: {
  294. type: 2,
  295. re: /btdigg\.org\/search/,
  296. func: function(tab) {
  297. console.log($('#search_res'));
  298. if ($('#search_res').length != 0) { //搜索页面
  299. var selector = '.snippet';
  300. var a = $(selector);
  301. for (var i = 0; i < a.length; i++) {
  302. var b = tab.cloneNode(true);
  303. //console.log($('.ttth a',a[i].previousElementSibling)[0]))
  304. b.setAttribute('maglink', $('.ttth a', a[i].previousElementSibling)[0].href);
  305. a[i].parentElement.appendChild(b);
  306. };
  307. }
  308. else if ($('.torrent_info_tbl').length != 0) { //详情页面
  309. var selector = '.torrent_info_tbl';
  310. var a = $(selector)[0];
  311. tab.setAttribute('maglink', $('a', a)[1].href);
  312. a.parentElement.insertBefore(tab, a);
  313. }
  314. },
  315. },
  316. // cilizhushou_a: {
  317. // re: /cilizhushou/,
  318. // func: function(div) {
  319. // $xafter('.tail', div, function(elem) {
  320. // return elem.getElementsByTagName('a')[0].href;
  321. // });
  322. // },
  323. // },
  324. // // shousibaocai_single: {
  325. // // re: '',
  326. // // func: '',
  327. // // },
  328. // btava_a: {
  329. // re: /search\//,
  330. // func: function(div) {
  331. // $xafter('.data-list .date', div, function(elem) {
  332. // return 'magnet:?xt=urn:btih:' + elem.parentElement.getElementsByTagName('a')[0].href.match(/hash\/(.*)/)[1];
  333. // });
  334. // },
  335. // },
  336. // btava_single: {
  337. // re: /magnet\/detail\/hash\//,
  338. // func: function(div) {
  339. // div.setAttribute('data', $('#magnetLink')[0].value);
  340. // common.after($('#magnetLink')[0], div);
  341. // },
  342. // },
  343. // // instsee_a:{
  344. // // re: /^http:\/\/www\.instsee.com\/$|instsee\.com\/default.aspx.*/,
  345. // // func: function(div){
  346. // // }
  347. // // },
  348. // demo: {
  349. // re: /.*/,
  350. // vid: function() {
  351. // return 'demo'
  352. // },
  353. // proc: function(table) {
  354. // common.after(document.body, table);
  355. // }
  356. // },
  357. };
  358. main_keys = Object.keys(main) //下面的不要出现
  359. main['cur_tab'] = null;
  360. main['cur_vid'] = '';
  361. var $ = function(selector, context) {
  362. if (context) {
  363. return context.querySelectorAll(selector);
  364. }
  365. return document.querySelectorAll(selector);
  366. };
  367. var insert_after = function(b) {
  368. b = $(b)[0];
  369. if (b) {
  370. b.parentElement.insertBefore(main.cur_tab, b);
  371. }
  372. };
  373. var offline_sites = {
  374. baidu: {
  375. url: 'http://pan.baidu.com/disk/home',
  376. name: '百度云',
  377. enable: true
  378. },
  379. 115: {
  380. name: '115离线',
  381. url: 'http://115.com/?tab=offline&mode=wangpan',
  382. enable: true,
  383. },
  384. letv: {
  385. name: '乐视云',
  386. url: 'http://cloud.letv.com/webdisk/home/index',
  387. enable: false
  388. },
  389. 360: {
  390. name: '360云',
  391. url: 'http://yunpan.360.cn/my/',
  392. enable: false
  393. },
  394. uc: {
  395. name: 'UC离线',
  396. url: 'http://disk.yun.uc.cn/',
  397. enable: false
  398. },
  399. furk: {
  400. name: 'Furk',
  401. url: 'https://www.furk.net/users/files/add',
  402. enable: true
  403. },
  404. };
  405. var common = {
  406. add_style: function(css) {
  407. if (css) {
  408. GM_addStyle(css);
  409. }
  410. else {
  411. GM_addStyle([
  412. '#nong-table{margin:10px auto;color:#666 !important;font-size:13px;text-align:center;background-color: #F2F2F2;}',
  413. '#nong-table th,#nong-table td{text-align: center;height:30px;background-color: #FFF;padding:0 1em 0;border: 1px solid #EFEFEF;}',
  414. '.nong-row{text-align: center;height:30px;background-color: #FFF;padding:0 1em 0;border: 1px solid #EFEFEF;}',
  415. '.nong-copy{color:#08c !important;}',
  416. '.nong-offline{text-align: center;}',
  417. '#nong-head a {margin-right: 5px;}',
  418. '.nong-offline-download{color: rgb(0, 180, 30) !important; margin-right: 4px !important;}',
  419. '.nong-offline-download:hover{color:red !important;}',
  420. ].join(''));
  421. }
  422. },
  423. handle_event: function(event) {
  424. if (event.target.className == 'nong-copy') {
  425. event.target.innerHTML = '成功';
  426. GM_setClipboard(event.target.href);
  427. setTimeout(function() {
  428. event.target.innerHTML = '复制';
  429. }, 1000);
  430. event.preventDefault(); //阻止跳转
  431. }
  432. else if (event.target.className == 'nong-offline-download') {
  433. var maglink = event.target.parentElement.parentElement.getAttribute('maglink') || event.target.parentElement.parentElement.parentElement.getAttribute('maglink')
  434. GM_setValue('magnet', maglink);
  435. }
  436. else if (event.target.id == 'nong-search-select') {
  437. current_search_name = event.target.value;
  438. GM_setValue('search', current_search_name);
  439. search_engines[current_search_name](current_vid, function(src, data) {
  440. magnet_table.updata_table(src, data);
  441. });
  442. }
  443. },
  444. reg_event: function() { //TODO target 处理 更精准
  445. var list = [
  446. '.nong-copy',
  447. '.nong-offline-download'
  448. ];
  449. for (var i = 0; i < list.length; i++) {
  450. var a = document.querySelectorAll(list[i]);
  451. for (var u = 0; u < a.length; u++) {
  452. a[u].addEventListener('click', this.handle_event, false);
  453. }
  454. }
  455. // var b = document.querySelectorAll('#nong-search-select')[0];
  456. // b.addEventListener('change', this.handle_event, false);
  457.  
  458. },
  459. after: function(target, newnode) {
  460. target.parentElement.insertBefore(newnode, target.nextElementSibling);
  461. },
  462. parsetext: function(text) {
  463. var doc = null;
  464. try {
  465. doc = document.implementation.createHTMLDocument('');
  466. doc.documentElement.innerHTML = text;
  467. return doc;
  468. }
  469. catch (e) {
  470. alert('parse error');
  471. }
  472. },
  473. insert_js: function(js, maglink) {
  474. var script = document.createElement('script');
  475. script.setAttribute('type', 'text/javascript');
  476. script.innerHTML = '(' + js.toString() + ')(\'' + maglink + '\')';
  477. document.body.appendChild(script);
  478. },
  479. add_mini_table: function(sel, func) {
  480. var a = $(sel);
  481. for (var i = a.length - 1; i >= 0; i--) {
  482. a[i].parentElement.insertBefore(a[i], magnet_table.mini()); //TODO
  483. func(a[i]);
  484. }
  485. },
  486. };
  487. var magnet_table = {
  488. template: {
  489. create_head: function() {
  490. var a = document.createElement('tr');
  491. a.className = 'nong-row';
  492. a.id = 'nong-head';
  493. var list = [
  494. '标题',
  495. '大小',
  496. '操作',
  497. '离线下载'
  498. ];
  499. for (var i = 0; i < list.length; i++) {
  500. var b = this.head.cloneNode(true);
  501. if (i == 0) {
  502. var select = document.createElement("select");
  503. var ops = ["btio", "btdb"];
  504. var cur_index = GM_getValue("search_index");
  505. for (var j = 0; j < ops.length; j++) {
  506. var op = document.createElement("option");
  507. op.value = j.toString();
  508. op.textContent = ops[j];
  509. if (cur_index == j) {
  510. op.setAttribute("selected", "selected");
  511. }
  512. select.appendChild(op);
  513. }
  514. b.removeChild(b.firstChild);
  515. b.appendChild(select);
  516. a.appendChild(b);
  517. continue;
  518. }
  519. b.firstChild.textContent = list[i];
  520. a.appendChild(b);
  521. }
  522. // var select_box = this.create_select_box();
  523. // a.firstChild.appendChild(select_box);
  524.  
  525. return a;
  526. },
  527. create_row: function(data) {
  528. var a = document.createElement('tr');
  529. a.className = 'nong-row';
  530. a.setAttribute('maglink', data.maglink);
  531. var b = document.createElement('td');
  532. var list = [
  533. this.create_info(data.title, data.maglink),
  534. this.create_size(data.size, data.src),
  535. this.create_operation(data.maglink),
  536. this.create_offline()
  537. ];
  538. for (var i = 0; i < list.length; i++) {
  539. var c = b.cloneNode(true);
  540. c.appendChild(list[i]);
  541. a.appendChild(c);
  542. }
  543. return a;
  544. },
  545. create_loading: function() {
  546. var a = document.createElement('tr');
  547. a.className = 'nong-row';
  548. var p = document.createElement('p');
  549. p.textContent = 'Loading';
  550. p.id = 'notice';
  551. a.appendChild(p);
  552. return a;
  553. },
  554. create_info: function(title, maglink) {
  555. var a = this.info.cloneNode(true);
  556. a.firstChild.textContent = title.length < 20 ? title : title.substr(0, 20) + '...';
  557. a.firstChild.href = maglink;
  558. a.title = title;
  559. return a;
  560. },
  561. create_size: function(size, src) {
  562. var a = this.size.cloneNode(true);
  563. a.textContent = size;
  564. a.href = src;
  565. return a;
  566. },
  567. create_operation: function(maglink) {
  568. var a = this.operation.cloneNode(true);
  569. a.firstChild.href = maglink;
  570. return a;
  571. },
  572. create_offline: function() {
  573. var a = this.offline.cloneNode(true);
  574. a.className = 'nong-offline';
  575. return a;
  576. },
  577. create_select_box: function() {
  578. var select_box = document.createElement('select');
  579. select_box.id = 'nong-search-select';
  580. select_box.setAttribute('title', '切换搜索结果');
  581. var search_name = GM_getValue('search', default_search_name);
  582. for (var k in search_engines) {
  583. var o = document.createElement('option');
  584. if (k == search_name) {
  585. o.setAttribute('selected', 'selected');
  586. }
  587. o.setAttribute('value', k);
  588. o.textContent = k;
  589. select_box.appendChild(o);
  590. }
  591. return select_box;
  592. },
  593. head: (function() {
  594. var a = document.createElement('th');
  595. var b = document.createElement('a');
  596. a.appendChild(b);
  597. return a;
  598. })(),
  599. info: (function() {
  600. var a = document.createElement('div');
  601. var b = document.createElement('a');
  602. b.textContent = 'name';
  603. b.href = 'src';
  604. a.appendChild(b);
  605. return a;
  606. })(),
  607. size: function() {
  608. var a = document.createElement('a');
  609. a.textContent = 'size';
  610. return a;
  611. }(),
  612. operation: (function() {
  613. var a = document.createElement('div');
  614. var copy = document.createElement('a');
  615. copy.className = 'nong-copy';
  616. copy.textContent = '复制';
  617. a.appendChild(copy);
  618. return a;
  619. })(),
  620. offline: (function() {
  621. var a = document.createElement('div');
  622. var b = document.createElement('a');
  623. b.className = 'nong-offline-download';
  624. b.target = '_blank';
  625. for (var k in offline_sites) {
  626. if (offline_sites[k].enable) {
  627. var c = b.cloneNode(true);
  628. c.href = offline_sites[k].url;
  629. c.textContent = offline_sites[k].name;
  630. a.appendChild(c);
  631. }
  632. }
  633. return a;
  634. })(),
  635. },
  636. create_empty_table: function() {
  637. var a = document.createElement('table');
  638. a.id = 'nong-table';
  639. return a;
  640. },
  641. updata_table: function(src, data, type) {
  642. // console.log(data);
  643. if (type == 'full') {
  644. var tab = $('#nong-table')[0];
  645. var a = tab.querySelectorAll('.nong-row');
  646. for (var i = 0; i < a.length; i++) {
  647. if (a[i].id == 'nong-head') {
  648. continue;
  649. }
  650. tab.removeChild(a[i]);
  651. }
  652. for (var i = 0; i < data.length; i++) {
  653. tab.appendChild(this.template.create_row(data[i]));
  654. }
  655. }
  656. // else if(type =='mini'){
  657. // }
  658.  
  659. common.reg_event();
  660. },
  661. full: function(src, data) {
  662. var tab = this.create_empty_table();
  663. tab.appendChild(this.template.create_head());
  664. // for (var i = 0; i < data.length; i++) {
  665. // tab.appendChild(this.template.create_row(data[i]))
  666. // }
  667. var loading = this.template.create_loading();
  668. tab.appendChild(loading);
  669. return tab;
  670. },
  671. mini: function(data) {
  672. var tab = this.create_empty_table();
  673. tab.appendChild(this.template.create_offline());
  674. return tab;
  675. }
  676. };
  677. var search_engines = {
  678. switch_engine: function(i) {
  679. // var index = GM_getValue("search_index",0);
  680. GM_setValue('search_index', i)
  681. return i
  682. },
  683. cur_engine: function(kw, cb) {
  684. var z = this[GM_getValue('search_index', 0)];
  685. return this[GM_getValue('search_index', 0)](kw, cb)
  686. },
  687. full_url: '',
  688. 0: function(kw, cb) {
  689. GM_xmlhttpRequest({
  690. method: 'GET',
  691. url: 'https://btio.pw/search/' + kw,
  692. onload: function(result) {
  693. search_engines.full_url = result.finalUrl;
  694. var doc = common.parsetext(result.responseText)
  695. if (!doc) {
  696. //TODO
  697. }
  698. var data = [];
  699. var t = doc.getElementsByClassName('data-list')[0];
  700. if (t) {
  701. var a = t.getElementsByTagName('a');
  702. for (var i = 0; i < a.length; i++) {
  703. if (!a[i].className.match('btn')) {
  704. data.push({
  705. 'title': a[i].title,
  706. 'maglink': 'magnet:?xt=urn:btih:' + a[i].outerHTML.replace(/.*hash\//, '').replace(/" .*\n.*\n.*\n.*/, ''),
  707. 'size': a[i].nextElementSibling.textContent,
  708. 'src': a[i].href,
  709. });
  710. }
  711. }
  712. }
  713. cb(result.finalUrl, data);
  714. },
  715. onerror: function(e) {
  716. console.log(e);
  717. }
  718. })
  719. },
  720. 1: function(kw, cb) {
  721. GM_xmlhttpRequest({
  722. method: 'GET',
  723. url: 'https://btdb.in/q/' + kw + '/',
  724. onload: function(result) {
  725. search_engines.full_url = result.finalUrl;
  726. var doc = common.parsetext(result.responseText)
  727. var data = [];
  728. var elems = doc.getElementsByClassName('item-title');
  729. for (var i = 0; i < elems.length; i++) {
  730. data.push({
  731. 'title': elems[i].firstChild.title,
  732. 'magnet': elems[i].nextElementSibling.firstChild.href,
  733. 'size': elems[i].nextElementSibling.children[2].textContent,
  734. 'src': 'https://btdb.in' + elems[i].firstChild.href,
  735. });
  736. }
  737. cb(result.finalUrl, data);
  738. },
  739. onerror: function(e) {
  740. console.log(e);
  741. }
  742. });
  743. },
  744. 2: function(kw, cb) {
  745. GM_xmlhttpRequest({
  746. method: 'POST',
  747. url: this.url,
  748. data: 's=' + kw,
  749. headers: {
  750. 'Content-Type': 'application/x-www-form-urlencoded'
  751. },
  752. onload: function(result) {
  753. var doc = document.implementation.createHTMLDocument('');
  754. doc.documentElement.innerHTML = result.responseText;
  755. var data = [];
  756. var t = doc.getElementsByClassName('list-content')[0];
  757. if (t) {
  758. var elems = t.getElementsByClassName('item-title');
  759. for (var i = 0; i < elems.length; i++) {
  760. data.push({
  761. 'title': elems[i].getElementsByTagName('a')[0].textContent,
  762. 'magnet': elems[i].nextElementSibling.getElementsByTagName('a')[0].href,
  763. 'size': elems[i].nextElementSibling.getElementsByTagName('b')[1].textContent
  764. });
  765. }
  766. cb(result.finalUrl, data);
  767. }
  768. },
  769. onerror: function(e) {
  770. console.log(e);
  771. }
  772. });
  773. },
  774. };
  775. var run = function() {
  776. for (var i = 0; i < main_keys.length; i++) {
  777. var v = main[main_keys[i]];
  778. if (v.re.test(location.href)) {
  779. if (v.type == 0) {
  780. try {
  781. main.cur_vid = v.vid();
  782. }
  783. catch (e) {
  784. main.cur_vid = '';
  785. }
  786. if (main.cur_vid) {
  787. common.add_style();
  788. main.cur_tab = magnet_table.full();
  789. console.log('番号:', main.cur_vid)
  790. v.proc()
  791.  
  792. console.log(main.cur_tab)
  793. var t = $('#nong-head')[0].firstChild;
  794. t.firstChild.addEventListener('change', function(e) {
  795. console.log(e.target.value);
  796. GM_setValue('search_index', e.target.value);
  797. var s = $('#nong-table')[0];
  798. s.parentElement.removeChild(s);
  799. run()
  800. });
  801.  
  802. search_engines.cur_engine(main.cur_vid, function(src, data) {
  803. if (data.length == 0) {
  804. $('#nong-table')[0].querySelectorAll('#notice')[0].textContent = 'No search result';
  805. }
  806. else {
  807. magnet_table.updata_table(src, data, 'full');
  808. /*display search url*/
  809. var y = $('#nong-head th')[1].firstChild;
  810. y.href = search_engines.full_url;
  811. }
  812. });
  813. }
  814. }
  815. else if (v.type == 1) {
  816. var js = v.fill_form;
  817. var maglink = GM_getValue('magnet');
  818. if (maglink) {
  819. common.insert_js(js, maglink);
  820. GM_setValue('magnet', '')
  821. }
  822. }
  823. else if (v.type == 2) {
  824. common.add_style();
  825. v.func(magnet_table.mini());
  826. magnet_table.updata_table('', '', 'mini');
  827. }
  828. break;
  829. }
  830. }
  831. };
  832. // var print_sites = function() {
  833. // }
  834. // GM_registerMenuCommand('Hello, world! (again)', print_sites, 'e', 'shift alt', 'w');
  835. run();