DEPRECATED: TRAKT.TV: YouTube trailer search and RARBG/Torrentleech link

adds a RARBG and a Torrentleech link to the link sidebar and a youtube trailer search behind the trailer button

  1. // ==UserScript==
  2. // @name DEPRECATED: TRAKT.TV: YouTube trailer search and RARBG/Torrentleech link
  3. // @namespace https://github.com/Alistair1231/my-userscripts/
  4. // @version 0.8.4
  5. // @description adds a RARBG and a Torrentleech link to the link sidebar and a youtube trailer search behind the trailer button
  6. // @author Alistair1231
  7. // @match https://trakt.tv/*
  8. // @icon https://www.google.com/s2/favicons?domain=trakt.tv
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. function waitForSiteToLoad() {
  13. let value = document.querySelectorAll(".sidebar.affixable .external a");
  14. if (value == null) {
  15. setTimeout(waitForSiteToLoad, 300);
  16. return;
  17. }
  18. return value;
  19. }
  20.  
  21. function injectRarbgButton(path, imdbButton) {
  22. console.log("injecting rarbg button");
  23. let imdbId = imdbButton.href.match(/tt\d+/)[0];
  24.  
  25. let rarbgButton = document.createElement("a");
  26. rarbgButton.target = "_blank";
  27. // rarbgButton.innerHTML = "RARBG";
  28. rarbgButton.innerHTML = "<img width=16 height=16 alt=\"RARBG\" src=\"https://icons.duckduckgo.com/ip2/rarbg.to.ico\">";
  29. rarbgButton.id = "rarbgButton";
  30.  
  31. if (path == "shows")
  32. rarbgButton.href = `https://rarbgproxy.org/tv/${imdbId}/`;
  33. else if (path == "movies")
  34. rarbgButton.href = `https://rarbgproxy.org/torrents.php?imdb=${imdbId}`;
  35.  
  36. imdbButton.after(rarbgButton);
  37. }
  38. function injectTorrentleechButton(title, rarbgButton,path) {
  39. let torrentleechButton = document.createElement("a");
  40. torrentleechButton.target = "_blank";
  41. torrentleechButton.innerHTML = "<img width=16 height=16 alt=\"TL\" src=\"https://icons.duckduckgo.com/ip2/torrentleech.org.ico\">";
  42. torrentleechButton.id = "torrentleechButton";
  43. if(path == "shows")
  44. torrentleechButton.href = `https://www.torrentleech.org/torrents/browse/index/categories/27/query/${title}/orderby/seeders/order/desc`;
  45. if(path == "movies")
  46. torrentleechButton.href = `https://www.torrentleech.org/torrents/browse/index/categories/8,37,43,14,12,13,47,27/query/${title}/orderby/seeders/order/desc`;
  47.  
  48. rarbgButton.after(torrentleechButton);
  49. }
  50. function injectYoutubeSearchButton(title) {
  51.  
  52. //create button for youtube search
  53. let newLink = document.createElement("a");
  54. newLink.className = "popup-video one-liner trailer";
  55. newLink.target = "_blank";
  56. newLink.href = `https://www.youtube.com/results?search_query=%22${title}%22+trailer`;
  57. // copied from other button (for text and icon)
  58. newLink.innerHTML += '<div class="icon"><div class="fa fa-youtube-play"></div></div><div class="text"><div class="site">Trailer Search</div></div>';
  59. newLink.id = "youtubeSearchButton";
  60.  
  61.  
  62. //put new button after old, if not already there
  63. let oldTrailer = document.querySelector(".popup-video.one-liner.trailer");
  64. oldTrailer.after(newLink);
  65. }
  66.  
  67. function run() {
  68. let path = window.location.pathname.split('/');
  69. let linkArray = document.querySelectorAll(".sidebar.affixable .external a");
  70.  
  71. linkArray = waitForSiteToLoad();
  72.  
  73. try {
  74. let title;
  75. if(window.location.pathname.split('/')[3]==null) // if on main page of tv-show
  76. title = document.querySelector(".mobile-title h1").firstChild.textContent.replace(/ $/g,""); // gets title and removes space at the end
  77. else // on page like /seasons/1
  78. title = document.querySelector(".mobile-title h2 a").innerHTML.replace(/: $/g,""); // gets title and removes ': ' from the end
  79. let urlTitle=encodeURIComponent(title);
  80. let imdbButton = Array.from(linkArray).filter(x => x.innerHTML == "IMDB")[0];
  81.  
  82. if (document.getElementById("rarbgButton") == null) // if rarbg button doesn't exist
  83. injectRarbgButton(path[1], imdbButton);
  84.  
  85. if ((document.querySelector("a.trailer")!=null) && (document.getElementById("youtubeSearchButton")==null)) // if there is a trailer button but no trailer search was added
  86. injectYoutubeSearchButton(urlTitle);
  87.  
  88. if ((document.getElementById("torrentleechButton") == null) && (document.getElementById("rarbgButton") != null)) // if torrentleech button doesn't and rarbg button does exist
  89. injectTorrentleechButton(urlTitle, rarbgButton,path[1]);
  90.  
  91.  
  92. } catch (err) { }
  93. }
  94. (function () {
  95. 'use strict';
  96. setInterval(run, 700);
  97. })();