Torrenter

Dodaje linki kierujące do stron z torrentami.

当前为 2014-06-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Torrenter
  3. // @namespace http://www.google.com/search?q=mabakay
  4. // @description Dodaje linki kierujące do stron z torrentami.
  5. // @include http://release24.pl/*
  6. // @include http://www.filmweb.pl/*
  7. // @grant none
  8. // @copyright 2010 - 2014, mabakay
  9. // @date 22 June 2014
  10. // @version 1.42
  11. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  12. // ==/UserScript==
  13.  
  14. var Engines = ["https://thepiratebay.se/search/{0}/0/7/0",
  15. "http://kickass.to/usearch/{0}/?field=seeders&sorder=desc",
  16. "https://www.torrentz.com/search?q={0}",
  17. "http://bitsnoop.com/search/all/{0}/s/a/1/",
  18. "http://www.sumotorrent.sx/en/search/{0}?order=seeders&by=down"];
  19.  
  20. var hostName = window.location.hostname;
  21.  
  22. if (hostName == 'release24.pl') {
  23. var elemList = document.getElementById('mainwindow');
  24. loopCount = elemList.childElementCount > 3 ? elemList.childElementCount - 3 : 2;
  25.  
  26. for (i = 1; i < loopCount; i++) {
  27. var elem = elemList.children[i];
  28.  
  29. if (elem.className == 'wpis') {
  30. var title_regex = /\"(.*)\"/;
  31. regex_result = elem.children[0].children[0].innerHTML.match(title_regex)
  32.  
  33. if (regex_result != null) {
  34. var title = regex_result[1];
  35. var span = createLinkSpan(title, 'margin-left: 50px; font-weight: normal;');
  36.  
  37. elem.children[2].children[0].children[0].children[0].children[0].children[1].children[0].children[0].children[0].appendChild(span);
  38. }
  39. }
  40. }
  41. }
  42. else if (hostName == 'www.filmweb.pl') {
  43. var style = 'margin-left: 50px; font-weight: normal;';
  44. var elemList = getElementByClass('filmTime');
  45.  
  46. if (elemList == null) {
  47. if (getElementByClass('text-large caption') != null) {
  48. style = 'margin-left: 50px; font-weight: normal;';
  49. elemList = getElementByClass('text-large caption');
  50. }
  51. else if (getElementByClass('hdr hdr-super') != null) {
  52. style = 'margin-left: 0px; font-weight: normal;';
  53. elemList = getElementByClass('hdr hdr-super').parentNode;
  54. }
  55. }
  56.  
  57. if (elemList != null) {
  58. var title = getElementByClass('text-large caption');
  59.  
  60. if (title == null)
  61. title = getElementByClass('hdr hdr-super').children[0].children[0];
  62.  
  63. var span = createLinkSpan(title.innerHTML, style);
  64.  
  65. elemList.appendChild(span);
  66. }
  67. }
  68.  
  69. function createLinkSpan(title, style) {
  70. var span = document.createElement('span');
  71. span.setAttribute('id', 'Torrenter');
  72. span.setAttribute('style', style);
  73.  
  74. for (var e in Engines) {
  75. var link = document.createElement('a');
  76. link.setAttribute('href', format(Engines[e], title));
  77. link.setAttribute('style', 'position: relative; top: 5px;');
  78.  
  79. var url_regex = /(https?:\/\/)(.+\....)/;
  80. regex_result = Engines[e].match(url_regex);
  81. link.innerHTML = getFavIconImg(Engines[e].match(url_regex)[2]);
  82.  
  83. if (e > 0) {
  84. var separator = document.createElement('span');
  85. separator.innerHTML = '&nbsp;|&nbsp;';
  86.  
  87. span.appendChild(separator);
  88. }
  89.  
  90. span.appendChild(link);
  91. }
  92.  
  93. return span;
  94. }
  95.  
  96. function getFavIconImg(url) {
  97. imgurl = '<img src="http://www.google.com/s2/favicons?domain=' + url + '" width="16px" height="16px">';
  98.  
  99. return imgurl;
  100. }
  101.  
  102. function format(str) {
  103. for (a = 1; a < arguments.length; a++) {
  104. argNum = "{" + (a - 1) + "}";
  105.  
  106. str = str.replace(argNum, arguments[a]);
  107. }
  108.  
  109. return str;
  110. }
  111.  
  112. function getElementByClass(matchClass) {
  113. var elems = document.getElementsByClassName(matchClass);
  114.  
  115. if (elems.length > 0) {
  116. return elems[0];
  117. }
  118.  
  119. return null;
  120. }