1337x - Torrent page improvements

Makes titles longer on the torrent page and optionally enables the detail box when available.

当前为 2019-06-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 1337x - Torrent page improvements
  3. // @namespace NotNeo
  4. // @version 1.5.2
  5. // @description Makes titles longer on the torrent page and optionally enables the detail box when available.
  6. // @author NotNeo
  7. // @include http*://1337x.to/account
  8. // @include http*://1337x.to/torrent/*
  9. // @include http*://1337x.st/account
  10. // @include http*://1337x.st/torrent/*
  11. // @include http*://1337x.ws/account
  12. // @include http*://1337x.ws/torrent/*
  13. // @include http*://1337x.eu/account
  14. // @include http*://1337x.eu/torrent/*
  15. // @include http*://1337x.se/account
  16. // @include http*://1337x.se/torrent/*
  17. // @include http*://1337x.is/account
  18. // @include http*://1337x.is/torrent/*
  19. // @include http*://www.1337x.to/account
  20. // @include http*://www.1337x.to/torrent/*
  21. // @include http*://www.1337x.st/account
  22. // @include http*://www.1337x.st/torrent/*
  23. // @include http*://www.1337x.ws/account
  24. // @include http*://www.1337x.ws/torrent/*
  25. // @include http*://www.1337x.eu/account
  26. // @include http*://www.1337x.eu/torrent/*
  27. // @include http*://www.1337x.se/account
  28. // @include http*://www.1337x.se/torrent/*
  29. // @include http*://www.1337x.is/account
  30. // @include http*://www.1337x.is/torrent/*
  31. // @grant GM_getValue
  32. // @grant GM_setValue
  33. // @grant GM_deleteValue
  34. // ==/UserScript==
  35.  
  36. var imdbThing, foundIMDB, containerFailureCounter = 0;
  37.  
  38. var domainArr = [
  39. "1337x.to/account",
  40. "1337x.st/account",
  41. "1337x.ws/account",
  42. "1337x.eu/account",
  43. "1337x.se/account",
  44. "1337x.is/account"
  45. ]
  46.  
  47. function AreInAccount() {
  48. let istrue = false;
  49. domainArr.forEach(function(cur){
  50. if(window.location.href.indexOf(cur) >= 0) {
  51. istrue = true;
  52. return false; //breaks out of foreach, not outer function
  53. }
  54. });
  55. return istrue;
  56. }
  57.  
  58. var hideStreamButt = false;
  59. var hideAnonButt = false;
  60. var hideDirectButt = false;
  61. var usingDetailBox = true;
  62. var usingIMDBLinker = true;//setting to default
  63.  
  64. if( GM_getValue("usingDetailBox") != null ) {
  65. usingDetailBox = GM_getValue("usingDetailBox"); //overriding with saved settings if there is one
  66. }
  67. if( GM_getValue("hideAnonButt") != null ) {
  68. hideAnonButt = GM_getValue("hideAnonButt"); //overriding with saved settings if there is one
  69. }
  70. if( GM_getValue("hideStreamButt") != null ) {
  71. hideStreamButt = GM_getValue("hideStreamButt"); //overriding with saved settings if there is one
  72. }
  73. if( GM_getValue("hideDirectButt") != null ) {
  74. hideDirectButt = GM_getValue("hideDirectButt"); //overriding with saved settings if there is one
  75. }
  76. if( GM_getValue("usingIMDBLinker") != null ) {
  77. usingIMDBLinker = GM_getValue("usingIMDBLinker"); //overriding with saved settings if there is one
  78. }
  79.  
  80. var imdbInfoText = "If the uploader has an imdb link anywhere in his description, then the button will take you directly to the imdb page for that movie.\\nIf however there is no imdb link in the description, the button will take you to the search results page for the movie name instead.";
  81.  
  82. if(AreInAccount()) { //if on settings page
  83. document.getElementById("settings").innerHTML = '<br><input type="checkbox" value="1" name="useDetail" id="useDetailCheckbox" style="transform: scale(1.5);"> <label for="useDetailCheckbox">Show detail box for torrents, when available.</label><br>' +
  84. '<input type="checkbox" value="1" name="useIMDB" id="usingIMDBLinker" style="transform: scale(1.5);"> <label for="usingIMDBLinker">Show IMDb link button in detail box.</label> <a href="#" onclick="alert(\''+imdbInfoText+'\'); return false;" ><b>?</b></a><br>' +
  85. '<input type="checkbox" value="1" name="hideAnon" id="hideAnonCheckbox" style="transform: scale(1.5);"> <label for="hideAnonCheckbox">Hide the "Anonymous Download" button</label><br>' +
  86. '<input type="checkbox" value="1" name="hideDirect" id="hideDirectCheckbox" style="transform: scale(1.5);"> <label for="hideDirectCheckbox">Hide the "Direct Download" button</label><br>' +
  87. '<input type="checkbox" value="1" name="hideStream" id="hideStreamCheckbox" style="transform: scale(1.5);"> <label for="hideStreamCheckbox">Hide the "Play Now (Stream)" button</label><br>' + document.getElementById("settings").innerHTML;
  88.  
  89. document.getElementById("useDetailCheckbox").checked = usingDetailBox; //settings checkbox checked value to saved value (or default, if none are saved)
  90. document.getElementById("hideAnonCheckbox").checked = hideAnonButt; //settings checkbox checked value to saved value (or default, if none are saved)
  91. document.getElementById("hideDirectCheckbox").checked = hideDirectButt; //settings checkbox checked value to saved value (or default, if none are saved)
  92. document.getElementById("hideStreamCheckbox").checked = hideStreamButt; //settings checkbox checked value to saved value (or default, if none are saved)
  93. document.getElementById("usingIMDBLinker").checked = usingIMDBLinker; //settings checkbox checked value to saved value (or default, if none are saved)
  94.  
  95. document.getElementById("useDetailCheckbox").onchange = function() { //on value change
  96. usingDetailBox = document.getElementById("useDetailCheckbox").checked; //settings current value to the the new
  97. GM_setValue("usingDetailBox", usingDetailBox); //saving current value
  98. };
  99. document.getElementById("hideAnonCheckbox").onchange = function() { //on value change
  100. hideAnonButt = document.getElementById("hideAnonCheckbox").checked; //settings current value to the the new
  101. GM_setValue("hideAnonButt", hideAnonButt); //saving current value
  102. };
  103. document.getElementById("hideDirectCheckbox").onchange = function() { //on value change
  104. hideDirectButt = document.getElementById("hideDirectCheckbox").checked; //settings current value to the the new
  105. GM_setValue("hideDirectButt", hideDirectButt); //saving current value
  106. };
  107. document.getElementById("hideStreamCheckbox").onchange = function() { //on value change
  108. hideStreamButt = document.getElementById("hideStreamCheckbox").checked; //settings current value to the the new
  109. GM_setValue("hideStreamButt", hideStreamButt); //saving current value
  110. };
  111. document.getElementById("usingIMDBLinker").onchange = function() { //on value change
  112. usingIMDBLinker = document.getElementById("usingIMDBLinker").checked; //settings current value to the the new
  113. GM_setValue("usingIMDBLinker", usingIMDBLinker); //saving current value
  114. };
  115. }
  116. else {
  117. var title = document.getElementsByTagName("title")[0].textContent;
  118. title = title.substring(9, title.length-16);
  119. var titleArea = document.getElementsByClassName("box-info-heading")[0];
  120. if(titleArea.getElementsByTagName("span").length == 2 && title.length > 100) {
  121. title = title.substring(0, 100) + "...";
  122. } else if(titleArea.getElementsByTagName("span").length >= 3 && title.length > 85) {
  123. title = title.substring(0, 85) + "...";
  124. }
  125. titleArea.getElementsByTagName("h1")[0].textContent = title;
  126.  
  127. if(usingDetailBox) {
  128. var realDetailBox = document.getElementsByClassName("torrent-detail")[0];
  129. if(realDetailBox !== undefined) {
  130. if(!(realDetailBox.offsetWidth > 0 && realDetailBox.offsetHeight > 0)) { //if realDetailBox is not visible, make own
  131. var datHTML = realDetailBox.innerHTML;
  132. document.getElementsByClassName("torrent-category-detail")[0].innerHTML += '<div class="torrent-detail clearfix" style="display: inline-block; position: relative; margin-top: 10px; width: 100%;">'+datHTML+'</div>';
  133. }
  134. }
  135. }
  136.  
  137. if(usingIMDBLinker) {
  138. foundIMDB = document.getElementById("description").innerHTML.split("imdb.com/title/")[1];
  139. if (foundIMDB != null) { //if code was found...
  140. foundIMDB = foundIMDB.substr(0, 9); //...get it.
  141. if (!/^tt[0-9]{7}$/.test(foundIMDB)) { //if code is invalid...
  142. foundIMDB = null; //...make it null
  143. }
  144. }
  145. imdbThing = `<span class="imdbRatingPlugin" data-user="ur000000000" data-title="`+foundIMDB+`" data-style="p2">
  146. <a href="https://www.imdb.com/title/`+foundIMDB+`/?ref_=plg_rt_1"><img src="https://ia.media-imdb.com/images/G/01/imdb/plugins/rating/images/imdb_37x18.png" alt="" /></a>
  147. </span>`;
  148.  
  149. if(document.getElementsByClassName("torrent-detail")[0]) {
  150. addGlobalStyle(`.imdbRatingPlugin .rating { background: none; height: unset; position: unset; max-width: unset; } .imdbRatingPlugin { position: absolute; top: 0; right: 0; z-index: 9999; } .torrent-detail-info h3 { margin-right: 105px; }`);
  151. WaitForContainerThenInsertAndActivate();
  152. }
  153. else if(foundIMDB != null) {
  154. document.querySelectorAll(".torrent-category-detail > .list")[0].innerHTML += imdbThing;
  155. addGlobalStyle(`
  156. .list span.imdbRatingPlugin > .rating .ofTen {padding: 0; line-height: 9px;}
  157. .list span.imdbRatingPlugin > .rating .ofTen::after { content: ""; }
  158. .list span.imdbRatingPlugin > .rating { padding: 0; background: none; height: unset; position: unset; max-width: unset; font-size: 15px; line-height: 15px;}
  159. .list span.imdbRatingPlugin > .rating::after { content: ""; }
  160. .list span.imdbRatingPlugin::after { content: ""; }
  161. .list span.imdbRatingPlugin {color: #000; display: inline-block; font-size: 15px; line-height: unset; padding: 2px; position: unset; background-color: transparent; margin: 3px 0 0 0;}
  162. `);
  163. ActivateIMDBScript();
  164. }
  165. }
  166.  
  167. if(hideStreamButt || hideAnonButt || hideDirectButt) {
  168. try {
  169. document.querySelectorAll("div.torrent-detail-page ul > li > a").forEach(function(el){
  170. //alert(el.textContent);
  171. if((hideStreamButt && el.textContent == "Play No‌w (Str‌eam)") || (hideAnonButt && el.textContent == "An‌on‌ymous Download") || (hideDirectButt && el.textContent == "Dir‌ect Download")) {
  172. el.parentNode.style.display = 'none';
  173. }
  174. });
  175. } catch(err) {
  176. alert("Error getting Stream/Anon button. Please report this via PM to \"NotNeo\"");
  177. }
  178. }
  179. }
  180.  
  181. function WaitForContainerThenInsertAndActivate() {
  182. let targetLocation = document.getElementById("mCSB_1_container");
  183. if(targetLocation === null) {
  184. containerFailureCounter++;
  185. if(containerFailureCounter >= 200) //Give up if after ~20 seconds we still cannot find the container
  186. {
  187. alert("Error getting infobox description container.");
  188. return;
  189. }
  190. setTimeout(WaitForContainerThenInsertAndActivate, 100);
  191. }
  192. else {
  193. targetLocation.innerHTML += imdbThing;
  194. if(foundIMDB != null) {
  195. ActivateIMDBScript();
  196. }
  197. else {
  198. let movieName = document.querySelectorAll(".torrent-detail-info h3 a")[0].textContent;
  199. document.querySelectorAll(".imdbRatingPlugin > a")[0].href = "https://www.imdb.com/find?q="+movieName.trim().replace(/\s/g, "+")+"&s=tt";
  200. }
  201. }
  202. }
  203.  
  204. function ActivateIMDBScript() {
  205. let imdbScript=document.createElement("script");
  206. imdbScript.id="imdb-rating-api";
  207. imdbScript.src="https://ia.media-imdb.com/images/G/01/imdb/plugins/rating/js/rating.js";
  208. let place = document.getElementsByClassName("imdbRatingPlugin")[0];
  209. place.parentNode.insertBefore(imdbScript, place);
  210. }
  211.  
  212. function addGlobalStyle(css) {
  213. var head, style;
  214. head = document.getElementsByTagName('head')[0];
  215. if (!head) { return; }
  216. style = document.createElement('style');
  217. style.type = 'text/css';
  218. style.innerHTML = css;
  219. head.appendChild(style);
  220. }