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

Fra og med 10.02.2016. Se den nyeste version.

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