display ed2k links on verycd

display ed2k links on verycd.com

当前为 2014-09-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name display ed2k links on verycd
  3. // @description display ed2k links on verycd.com
  4. // @namespace JaHIY
  5. // @author JaHIY
  6. // @version 0.2.2
  7. // @grant GM_xmlhttpRequest
  8. // @match http://www.verycd.com/topics/*
  9. // @homepageURL https://greasyfork.org/scripts/5032
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. (function(){
  14.  
  15. 'use strict';
  16.  
  17. /*
  18. * DOMParser HTML extension
  19. * 2012-09-04
  20. *
  21. * By Eli Grey, http://eligrey.com
  22. * Public domain.
  23. * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
  24. */
  25. /*! @source https://gist.github.com/1129031 */
  26. /*global document, DOMParser*/
  27. (function(DOMParser) {
  28. "use strict";
  29.  
  30. var DOMParser_proto = DOMParser.prototype,
  31. real_parseFromString = DOMParser_proto.parseFromString;
  32.  
  33. // Firefox/Opera/IE throw errors on unsupported types
  34. try {
  35. // WebKit returns null on unsupported types
  36. if ((new DOMParser).parseFromString("", "text/html")) {
  37. // text/html parsing is natively supported
  38. return;
  39. }
  40. } catch (ex) {}
  41.  
  42. DOMParser_proto.parseFromString = function(markup, type) {
  43. if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
  44. var doc = document.implementation.createHTMLDocument("");
  45. if (markup.toLowerCase().indexOf('<!doctype') > -1) {
  46. doc.documentElement.innerHTML = markup;
  47. }
  48. else {
  49. doc.body.innerHTML = markup;
  50. }
  51. return doc;
  52. } else {
  53. return real_parseFromString.apply(this, arguments);
  54. }
  55. };
  56. }(DOMParser));
  57.  
  58. document.getElementById('iptcomED2K').children.length === 1 &&
  59. GM_xmlhttpRequest({
  60. method: 'GET',
  61. url: 'http://www.icili.com/emule/download/' + window.location.pathname.match(/^\/topics\/(\d+)\/?$/)[1],
  62. headers: {
  63. 'User-Agent': 'Mozilla/5.0',
  64. 'Cache-Control': 'no-cache',
  65. 'Origin': 'http://www.icili.com',
  66. 'Referer': 'http://www.icili.com'
  67. },
  68. onload: function (res) {
  69. var parser = new DOMParser(),
  70. children = parser.parseFromString(res.responseText, 'text/html').getElementById('emuleFile').firstElementChild.children,
  71. files = [],
  72. wrapper = document.getElementById('iptcomED2K'),
  73. docfrag = document.createDocumentFragment();
  74. for (let i=1, l=children.length-1, child; i<l; i++) {
  75. child = children[i].children[1].firstElementChild;
  76. files.push({
  77. 'title': child.title.trim(),
  78. 'href': child.href,
  79. 'size': children[i].children[2].textContent.trim()
  80. });
  81. }
  82. {
  83. let emuletop = document.createElement('div'),
  84. emulemain = emuletop.cloneNode(false),
  85. tbl = document.createElement('table'),
  86. random_code = 'EM51da5b7de03b7';
  87.  
  88. emuletop.className = 'emuletop';
  89. emuletop.textContent = '电驴资源';
  90. docfrag.appendChild(emuletop);
  91.  
  92. emulemain.className = 'emulemain';
  93. docfrag.appendChild(emulemain);
  94.  
  95. tbl.cellPadding = '2';
  96. tbl.cellSpacing = '1';
  97. tbl.width = '100%';
  98. emulemain.appendChild(tbl);
  99. {
  100. let row = tbl.insertRow(-1),
  101. cell = row.insertCell(-1),
  102. archor = document.createElement('a');
  103. cell.className = 'needemule';
  104. cell.colSpan = '2';
  105. archor.href = 'http://www.easymule.com/';
  106. archor.textContent = '下面是用户共享的文件列表,安装电驴后,您可以点击这些文件名进行下载';
  107. cell.appendChild(archor);
  108. }
  109. for (let i=0, l=files.length, row, cell_filename, cell_size, input, archor; i<l; i++) {
  110. row = tbl.insertRow(-1);
  111. cell_filename = row.insertCell(-1);
  112. cell_size = row.insertCell(-1);
  113. input = document.createElement('input');
  114. archor = document.createElement('a');
  115. cell_filename.className = cell_size.className = (i%2 === 0) ? 'post2' : 'post';
  116. input.className = 'forminput';
  117. input.type = 'checkbox';
  118. input.name = random_code;
  119. input.value = files[i]['href'];
  120. input.defaultChecked = true;
  121. input.setAttribute('onclick', 'em_size("' + random_code + '");');
  122. archor.href = archor.ed2k = files[i]['href'];
  123. archor.textContent = files[i]['title'];
  124. cell_filename.appendChild(input);
  125. cell_filename.appendChild(archor);
  126. cell_size.align = 'center';
  127. cell_size.textContent = files[i]['size'];
  128. }
  129. {
  130. let row = tbl.insertRow(-1),
  131. cell = row.insertCell(-1),
  132. input_checkbox = document.createElement('input'),
  133. input_button = input_checkbox.cloneNode(false),
  134. label = document.createElement('label'),
  135. span = document.createElement('span'),
  136. script = document.createElement('script');
  137. cell.align = 'left';
  138. cell.className = (files.length%2 === 0) ? 'post2' : 'post';
  139. input_checkbox.className = 'forminput';
  140. input_checkbox.type = 'checkbox';
  141. input_checkbox.id = 'checkall_' + random_code;
  142. input_checkbox.defaultChecked = true;
  143. input_checkbox.setAttribute('onclick', 'checkAll("' + random_code + '",this.checked)');
  144. label.htmlFor = 'checkall_' + random_code;
  145. input_button.type = 'button';
  146. input_button.className = 'button downall';
  147. input_button.value = '下载选中的文件';
  148. input_button.setAttribute('onclick', 'download("' + random_code + '",0,1)');
  149. span.id = 'updateflash' + random_code;
  150. script.type = 'text/javascript';
  151. script.textContent = 'changeUpdateFlash("' + random_code + '");new MultiCheckBox("' + random_code + '");';
  152. cell.appendChild(input_checkbox);
  153. cell.appendChild(label);
  154. cell.appendChild(input_button);
  155. cell.appendChild(span);
  156. cell.appendChild(script);
  157. }
  158. }
  159. wrapper.replaceChild(docfrag, wrapper.firstElementChild);
  160. }
  161. });
  162. })();