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

ของเมื่อวันที่ 02-04-2016 ดู เวอร์ชันล่าสุด

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