-
Notifications
You must be signed in to change notification settings - Fork 1
/
ended.tvmaze.user.js
57 lines (49 loc) · 2.17 KB
/
ended.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
// ==UserScript==
// @name TVMaze Ended Shows
// @namespace tvmaze
// @description Distinguish ended shows on TVMaze with *
// @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/watchlist*
// @match https://www.tvmaze.com/watchlist*
// @version 0.6
// @date 01/01/2024
// @grant none
// ==/UserScript==
(async () => {
try {
const response = await fetch('/showstatus', { cache: 'no-store' });
const data = await response.text();
const parser = new DOMParser();
const html = parser.parseFromString(data, 'text/html');
const ended = [];
const tbd = [];
const statusElements = Array.from(html.querySelectorAll('[data-title^=Status]'));
if (statusElements.length !== 0) {
statusElements.forEach(statusElement => {
const showTitleElement = statusElement.parentElement.querySelector('[data-title^=Show]');
const showTitle = showTitleElement.textContent;
if (statusElement.textContent === 'Ended') {
ended.push(showTitle);
} else if (statusElement.textContent === 'To Be Determined') {
tbd.push(showTitle);
}
});
Array.from(document.querySelectorAll('H2')).forEach(titleElement => {
const titleText = titleElement.textContent;
if (ended.includes(titleText)) {
titleElement.innerHTML = `* ${titleElement.innerHTML}`;
} else if (tbd.includes(titleText)) {
titleElement.innerHTML = `?!? ${titleElement.innerHTML}`;
}
});
}
} catch (error) {
console.error('Error fetching show status:', error);
}
})();