-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
117 lines (97 loc) · 3.55 KB
/
script.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// ==UserScript==
// @name Filmweb - seen movies hider
// @namespace https://github.com/kmanijak/filmweb-seen-movies-hider
// @version 0.4
// @updateURL https://raw.githubusercontent.com/kmanijak/filmweb-seen-movies-hider/master/script.js
// @description Hide movies you've seen on Filmweb rankings
// @author Karol Manijak & Justyna Sroka
// @match https://www.filmweb.pl/ranking/*
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle(
`.hide-button {
margin-top: 14px;
border: 1px solid #eab30b;
padding: 4px 12px;
}`
);
(function() {
'use strict';
let firstUsage = true;
let moviesHidden = false;
let movies = null;
const buttonTextHide = 'Ukryj obejrzane 🙈';
const buttonTextShow = 'Pokaż obejrzane 🐵';
const hideButton = document.createElement('button');
hideButton.className = 'hide-button';
hideButton.innerHTML = buttonTextHide;
hideButton.type = 'button';
const addToDOM = (target, element) => {
target.appendChild(element);
}
const getSeenMovies = () => {
if (!movies) {
movies = document.querySelectorAll('.item.place');
}
return Array.prototype.filter.call(movies, movie => (
window.getComputedStyle(movie.querySelector('.ifw-flag')).color === 'rgb(255, 194, 0)'
))
};
const getNotSeenMovies = () => {
if (!movies) {
movies = document.querySelectorAll('.item.place');
}
return Array.prototype.filter.call(movies, movie => (
window.getComputedStyle(movie.querySelector('.ifw-flag')).color !== 'rgb(255, 194, 0)'
))
};
const changeMoviesDisplay = (display) => {
const seenMovies = getSeenMovies();
Array.prototype.map.call(seenMovies, movie => {
movie.style.display = display;
});
if (firstUsage) {
const notSeenMovies = getNotSeenMovies();
Array.prototype.map.call(notSeenMovies, movie => {
const poster = movie.querySelector('.filmPoster__image');
const src = poster.getAttribute('data-src');
if (src) {
poster.setAttribute('src', src);
}
});
firstUsage = false;
}
}
const changeButtonText = (text) => {
hideButton.innerHTML = text;
}
const toggleMovies = () => {
if (moviesHidden) {
changeMoviesDisplay('flex');
changeButtonText(buttonTextHide);
moviesHidden = false;
} else {
changeMoviesDisplay('none');
changeButtonText(buttonTextShow);
moviesHidden = true;
}
}
const addHideButton = () => {
const nextLine = document.createElement('br');
hideButton.onclick = toggleMovies;
const anchorPlace = document.querySelector('.ranking__user-see-info');
addToDOM(anchorPlace, nextLine);
addToDOM(anchorPlace, hideButton);
}
const addPercentage = () => {
const paragraph = document.createElement('strong');
const anchorPlace = document.querySelector('.amount');
const seenMovies = Number(anchorPlace.innerHTML);
const allMovies = Number(document.querySelector('.ranking__user-see-info').childNodes[3].textContent.split(' ')[2])
const percentage = seenMovies / allMovies * 100;
paragraph.innerHTML = ` (${Math.round(percentage * 10) / 10}%)`;
addToDOM(anchorPlace, paragraph);
}
addPercentage();
addHideButton();
})();