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