-
Notifications
You must be signed in to change notification settings - Fork 1
/
torrents.tvmaze.user.js
88 lines (71 loc) · 3.15 KB
/
torrents.tvmaze.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
// ==UserScript==
// @name TVMaze Torrent
// @namespace tvmaze
// @description Add Torrent links to TVMaze show page
// @icon https://tvmazecdn.com/images/favico/favicon.ico
// @author vBm <[email protected]>
// @oujs:author vBm
// @license MIT
// @contributionURL https://www.paypal.me/thevbm/3
// @contributionAmount €3.00
// @supportURL https://github.com/vBm/snippets/issues
// @match http://www.tvmaze.com/shows/*
// @match https://www.tvmaze.com/shows/*
// @version 1.1.0
// @date 01/01/2024
// @grant none
// ==/UserScript==
(async () => {
const processActiveListItem = async () => {
const activeListItem = document.querySelector('li.active');
if (!activeListItem) {
console.error('No list item with the "active" class found');
return null;
}
const href = activeListItem.querySelector('a').getAttribute('href');
const match = href.match(/\/shows\/(\d+)\/.*/);
if (match) {
return match[1];
} else {
console.error('Unable to extract show ID');
return null;
}
};
const fetchShowData = async () => {
const showId = await processActiveListItem();
if (showId === null) {
console.error('Unable to fetch show data');
return null;
}
const response = await fetch(`//api.tvmaze.com/shows/${showId}`);
const { externals } = await response.json();
return externals;
};
const { imdb } = await fetchShowData();
const mainImg = document.getElementById('main-img');
const followingDiv = document.createElement('div');
followingDiv.id = 'following';
followingDiv.className = 'radius small button secondary js-needlogin';
const openTorrentLink = (url) => window.open(url);
const createTorrentLink = (spanText, siteUrl) => {
const torrentSpan = document.createElement('span');
torrentSpan.className = 'torrent';
torrentSpan.textContent = spanText;
torrentSpan.target = '_blank';
torrentSpan.addEventListener('click', () => openTorrentLink(siteUrl));
const arrowIcon = document.createElement('i');
arrowIcon.className = 'fa fa-arrow-circle-down';
torrentSpan.prepend(arrowIcon);
return torrentSpan;
};
followingDiv.appendChild(createTorrentLink(' TL ', `https://www.torrentleech.org/torrents/browse/index/imdbID/${imdb}/`));
followingDiv.appendChild(createTorrentLink(' BTN ', `https://broadcasthe.net/torrents.php?action=advanced&imdb=${imdb}/`));
mainImg.appendChild(followingDiv);
const torrentLinks = document.querySelectorAll('.torrent');
torrentLinks.forEach((link) => {
link.style.display = 'inline-block';
link.style.width = '50%';
link.addEventListener('mouseover', () => link.classList.add('hovered'));
link.addEventListener('mouseout', () => link.classList.remove('hovered'));
});
})();