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

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

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