-
Notifications
You must be signed in to change notification settings - Fork 1
/
counter.tvmaze.user.js
40 lines (34 loc) · 1.82 KB
/
counter.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
// ==UserScript==
// @name TVMaze Counter
// @namespace tvmaze
// @description Display how many episodes are left to watch
// @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==
const totalEpisodes = Array.from(document.querySelectorAll('.watched-eps')).map(element => {
return element.textContent.trim().split('/').map(element => +element).reverse().reduce((a, b) => a - b);
});
const totalEpisodesSum = totalEpisodes.reduce((a, b) => a + b, 0);
localStorage.setItem('totalEps', totalEpisodesSum);
const filterElement = document.getElementById('filter');
const remainingSpan = document.createElement('span');
remainingSpan.classList.add('grid-x', 'grid-margin-x', 'align-center');
remainingSpan.id = 'remaining';
remainingSpan.textContent = `Remaining episodes to watch: ${localStorage.totalEps} from ${document.querySelectorAll('.watched-eps').length} shows`;
filterElement.appendChild(document.createElement('div').appendChild(remainingSpan));
document.querySelector('.watch-dropdown').addEventListener('change', (event) => {
if (event.target.value === '0') {
localStorage.setItem('totalEps', localStorage.totalEps - 1);
remainingSpan.textContent = `Remaining episodes to watch: ${localStorage.totalEps} from ${document.querySelectorAll('.watched-eps').length} shows`;
}
});