Torrenter

Adds links to torrent sites on popular movie websites.

当前为 2018-03-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Torrenter
  3. // @namespace http://www.google.com/search?q=mabakay
  4. // @version 1.50
  5. // @description Adds links to torrent sites on popular movie websites.
  6. // @author mabakay
  7. // @copyright 2010 - 2018, mabakay
  8. // @date 25 march 2018
  9. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  10. // @run-at document-end
  11. // @icon64URL https://raw.githubusercontent.com/mabakay/torrenter/master/torrenter_64.png
  12. // @supportURL https://github.com/mabakay/torrenter
  13. // @match http://www.filmweb.pl/*
  14. // @match https://www.filmweb.pl/*
  15. // @match http://release24.pl/*
  16. // @match https://release24.pl/*
  17. // @match http://www.imdb.com/*
  18. // @match https://www.imdb.com/*
  19. // @grant none
  20. // ==/UserScript==
  21.  
  22. (function() {
  23. 'use strict';
  24.  
  25. var engines = [
  26. "https://thepiratebay.org/search/{0}/0/7/0",
  27. "https://rarbgmirror.org/torrents.php?search={0}&order=seeders&by=DESC",
  28. "http://1337x.to/search/{0}/1/",
  29. "https://torrentz2.eu/search?f={0}",
  30. "https://yts.am/browse-movies/{0}/all/all/0/seeds",
  31. "https://eztv.ag/search/{0}",
  32. "https://www.limetorrents.cc/search/all/{0}/seeds/1/"
  33. ];
  34.  
  35. var hostName = window.location.hostname;
  36.  
  37. switch (hostName) {
  38. case "release24.pl":
  39. processRelease24();
  40. break;
  41.  
  42. case "www.filmweb.pl":
  43. processFilmweb();
  44. break;
  45.  
  46. case "www.imdb.com":
  47. processImdb();
  48. break;
  49. }
  50.  
  51. function createLinkSpan(tag, title, style) {
  52. var span = document.createElement(tag);
  53. span.setAttribute("id", "Torrenter");
  54. span.setAttribute("style", style);
  55.  
  56. for (var i = 0; i < engines.length; i++) {
  57. var link = document.createElement("a");
  58. link.setAttribute("href", format(engines[i], encodeURIComponent(title)));
  59. link.setAttribute("style", "position: relative; top: 5px;");
  60.  
  61. var urlRegex = /(https?:\/\/)(.+?)\//;
  62. var regexResult = engines[i].match(urlRegex);
  63. link.innerHTML = getFavIconImg(regexResult[2]);
  64.  
  65. link.setAttribute("title", regexResult[2]);
  66.  
  67. if (i > 0) {
  68. var separator = document.createElement("span");
  69. separator.innerHTML = "&nbsp;|&nbsp;";
  70.  
  71. span.appendChild(separator);
  72. }
  73.  
  74. span.appendChild(link);
  75. }
  76.  
  77. return span;
  78. }
  79.  
  80. function getFavIconImg(url) {
  81. return '<img src="http://www.google.com/s2/favicons?domain=' + url + '" width="16px" height="16px">';
  82. }
  83.  
  84. function format(str) {
  85. for (var i = 1; i < arguments.length; i++) {
  86. var argNum = "{" + (i - 1) + "}";
  87.  
  88. str = str.replace(argNum, arguments[i]);
  89. }
  90.  
  91. return str;
  92. }
  93.  
  94. function processRelease24() {
  95. var titleElement = document.getElementById("mainwindow");
  96. var loopCount = titleElement.childElementCount > 3 ? titleElement.childElementCount - 3 : 2;
  97.  
  98. for (var i = 1; i < loopCount; i++) {
  99. var elem = titleElement.children[i];
  100.  
  101. if (elem.className === "wpis") {
  102. var title_regex = /\"(.*)\"\s*(\(([0-9]{4})\))?/;
  103. var match = elem.children[0].children[0].innerHTML.match(title_regex);
  104.  
  105. if (match != null) {
  106. var title = match[1];
  107.  
  108. if (match.length === 4 && match[3]) {
  109. title += " " + match[3];
  110. }
  111.  
  112. var span = createLinkSpan("span", title, "margin-left: 3em; font-weight: normal;");
  113.  
  114. elem.children[2].children[0].children[0].children[0].children[0].children[1].children[0].children[0].children[0].appendChild(
  115. span
  116. );
  117. }
  118. }
  119. }
  120. }
  121.  
  122. function processFilmweb() {
  123. var style = "margin-top: 0.5em; font-size: 0.7em;";
  124. var titleElement = document.querySelector(".filmMainHeader .hdr");
  125. var title,
  126. hasSmallTitle = false;
  127.  
  128. if (titleElement) {
  129. var smallTitleElement = document.querySelector(".filmMainHeader .cap.s-16");
  130.  
  131. if (smallTitleElement) {
  132. style = "margin-left: 1.5em; font-size: 0.7em;";
  133. titleElement = smallTitleElement;
  134. hasSmallTitle = true;
  135.  
  136. title = smallTitleElement.innerText;
  137. } else {
  138. title = document.querySelector(".filmMainHeader .hdr a").innerText;
  139. }
  140.  
  141. var year = document.querySelector(".filmMainHeader .hdr .filmTitle").childNodes[2].innerText;
  142. var yearRegexp = /\(([0-9]{4})\)/;
  143. var match = year.match(yearRegexp);
  144.  
  145. if (match != null) {
  146. title += " " + match[1];
  147. }
  148. }
  149.  
  150. if (titleElement && title) {
  151. if (hasSmallTitle) {
  152. titleElement.appendChild(createLinkSpan("span", title, style));
  153. } else {
  154. titleElement.parentElement.appendChild(createLinkSpan("div", title, style));
  155. }
  156. }
  157. }
  158.  
  159. function processImdb() {
  160. var style = "margin-top: 0.5em; font-size: 0.7em;";
  161. var titleElement = document.querySelector("div.title_block h1[itemprop=name]");
  162. var title,
  163. hasSmallTitle = false;
  164.  
  165. if (titleElement) {
  166. var smallTitleElement = document.querySelector("div.title_block div.originalTitle");
  167.  
  168. if (smallTitleElement) {
  169. style = "margin-left: 1.5em; font-size: 0.7em; margin-bottom: 0.5em; display: inline-block;";
  170. titleElement = smallTitleElement;
  171. hasSmallTitle = true;
  172.  
  173. title = smallTitleElement.childNodes[0].nodeValue;
  174. } else {
  175. title = titleElement.childNodes[0].nodeValue;
  176. }
  177.  
  178. var yearElement = document.querySelector("#titleYear");
  179. if (yearElement) {
  180. var year = yearElement.textContent;
  181. var yearRegexp = /\(([0-9]{4})\)/;
  182. var match = year.match(yearRegexp);
  183.  
  184. if (match != null) {
  185. title += " " + match[1];
  186. }
  187. }
  188. }
  189.  
  190. if (titleElement && title) {
  191. if (hasSmallTitle) {
  192. titleElement.appendChild(createLinkSpan("span", title, style));
  193. } else {
  194. titleElement.parentElement.appendChild(createLinkSpan("div", title, style));
  195. }
  196. }
  197. }
  198. })();