Torrenter

Adds links pointing to torrent sites.

当前为 2014-12-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Torrenter
  3. // @namespace http://www.google.com/search?q=mabakay
  4. // @description Adds links pointing to torrent sites.
  5. // @include http://release24.pl/*
  6. // @include http://www.filmweb.pl/*
  7. // @grant none
  8. // @copyright 2010 - 2014, mabakay
  9. // @date 17 December 2014
  10. // @version 1.47
  11. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  12. // ==/UserScript==
  13.  
  14. var Engines = ["https://oldpiratebay.org/search.php?q={0}&Torrent_sort=seeders.desc",
  15. "https://kickass.to/usearch/{0}/?field=seeders&sorder=desc",
  16. "https://www.torrentz.com/search?q={0}",
  17. "http://extratorrent.cc/search/?search={0}",
  18. "https://yts.re/browse-movie/{0}/All/All/0/seeds",
  19. "http://bitsnoop.com/search/all/{0}/s/a/1/",
  20. "http://isohunt.to/torrents/?ihq={0}&Torrent_sort=seeders.desc"];
  21.  
  22. var hostName = window.location.hostname;
  23.  
  24. if (hostName == 'release24.pl') {
  25. var titleElement = document.getElementById('mainwindow');
  26. loopCount = titleElement.childElementCount > 3 ? titleElement.childElementCount - 3 : 2;
  27.  
  28. for (i = 1; i < loopCount; i++) {
  29. var elem = titleElement.children[i];
  30.  
  31. if (elem.className == 'wpis') {
  32. var title_regex = /\"(.*)\"/;
  33. regex_result = elem.children[0].children[0].innerHTML.match(title_regex)
  34.  
  35. if (regex_result != null) {
  36. var title = regex_result[1];
  37. var span = createLinkSpan(title, 'margin-left: 3em; font-weight: normal;');
  38.  
  39. elem.children[2].children[0].children[0].children[0].children[0].children[1].children[0].children[0].children[0].appendChild(span);
  40. }
  41. }
  42. }
  43. }
  44. else if (hostName == 'www.filmweb.pl') {
  45. var style = 'margin-top: 0.5em; font-size: 0.7em;';
  46. var titleElement = $('.filmMainHeader .hdr:first');
  47. var title, hasSmallTitle = false;
  48.  
  49. if (titleElement.length == 1) {
  50. var smallTitleElement = titleElement.siblings('.cap:first');
  51.  
  52. if (smallTitleElement.length == 1) {
  53. style = 'margin-left: 1.5em; font-size: 0.7em;';
  54. titleElement = smallTitleElement;
  55. hasSmallTitle = true;
  56. title = smallTitleElement.text();
  57. } else {
  58. title = titleElement.find('a').text();
  59. }
  60. }
  61.  
  62. if (titleElement.length && title) {
  63. if (hasSmallTitle){
  64. titleElement.append(createLinkSpan('span', title, style));
  65. } else {
  66. titleElement.parent().append(createLinkSpan('div', title, style));
  67. }
  68. }
  69. }
  70.  
  71. function createLinkSpan(tag, title, style) {
  72. var span = document.createElement(tag);
  73. span.setAttribute('id', 'Torrenter');
  74. span.setAttribute('style', style);
  75.  
  76. for (var i = 0; i < Engines.length; i++) {
  77. var link = document.createElement('a');
  78. link.setAttribute('href', format(Engines[i], encodeURIComponent(title)));
  79. link.setAttribute('style', 'position: relative; top: 5px;');
  80.  
  81. var urlRegex = /(https?:\/\/)(.+\....)/;
  82. var regexResult = Engines[i].match(urlRegex);
  83. link.innerHTML = getFavIconImg(regexResult[2]);
  84.  
  85. if (i > 0) {
  86. var separator = document.createElement('span');
  87. separator.innerHTML = '&nbsp;|&nbsp;';
  88.  
  89. span.appendChild(separator);
  90. }
  91.  
  92. span.appendChild(link);
  93. }
  94.  
  95. return span;
  96. }
  97.  
  98. function getFavIconImg(url) {
  99. var imgurl = '<img src="http://www.google.com/s2/favicons?domain=' + url + '" width="16px" height="16px">';
  100.  
  101. return imgurl;
  102. }
  103.  
  104. function format(str) {
  105. for (var i = 1; i < arguments.length; i++) {
  106. var argNum = "{" + (i - 1) + "}";
  107.  
  108. str = str.replace(argNum, arguments[i]);
  109. }
  110.  
  111. return str;
  112. }