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

Från och med 2021-07-04. Se den senaste versionen.

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