-
Notifications
You must be signed in to change notification settings - Fork 1
/
audycja_zawiera_lokowanie_produktu.user.js
139 lines (126 loc) · 4.79 KB
/
audycja_zawiera_lokowanie_produktu.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// ==UserScript==
// @name Audycja zawiera(ła) lokowanie produktu
// @namespace uscripts.minibomba.pro
// @match https://www.youtube.com/*
// @match https://uscripts.minibomba.pro/audycja_zawiera_lokowanie_produktu
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @grant GM_openInTab
// @version 1.0.1
// @homepageURL https://github.com/mini-bomba/uscripts
// @updateURL https://raw.githubusercontent.com/mini-bomba/uscripts/master/audycja_zawiera_lokowanie_produktu.user.js
// @downloadURL https://raw.githubusercontent.com/mini-bomba/uscripts/master/audycja_zawiera_lokowanie_produktu.user.js
// @author mini_bomba
// ==/UserScript==
(async function (){
// Configs
const DEFAULT_SETTINGS = {
"trigger-sponsor": true,
"trigger-exclusive-access": true,
"trigger-selfpromo": false,
"start-image-url": "https://uscripts.minibomba.pro/sponsor_begin.png",
"end-image-url": "https://uscripts.minibomba.pro/sponsor_end.png",
}
function getSetting(key) {
return GM_getValue(key, DEFAULT_SETTINGS[key]);
}
function handleSettingChange(event) {
if (event.target.nodeName === "INPUT" && event.target.checkValidity()) switch (event.target.type) {
case "checkbox":
GM_setValue(event.target.id, event.target.checked);
break;
case "number":
let val = Number(event.target.value)
if (!isNaN(val)) GM_setValue(event.target.id, val);
break;
default:
GM_setValue(event.target.id, event.target.value);
}
}
function handleSettingsPage() {
const settings = document.getElementById("settings");
for (const setting of settings.querySelectorAll("input")) {
if (setting.type === "checkbox") {
setting.checked = getSetting(setting.id);
} else {
setting.value = getSetting(setting.id);
}
}
settings.addEventListener("change", handleSettingChange);
document.getElementById("not-installed").classList.add("hidden");
settings.classList.remove("hidden");
}
function sleep(ms) {
return new Promise((res, _) => setTimeout(res, ms));
}
GM_registerMenuCommand("Open settings", () => GM_openInTab("https://uscripts.minibomba.pro/audycja_zawiera_lokowanie_produktu"));
if (window.location == "https://uscripts.minibomba.pro/audycja_zawiera_lokowanie_produktu") {
window.addEventListener("mbusc-azlp", e => e.preventDefault()); // Config page uses this to verify the script is installed
return handleSettingsPage();
}
const style = document.createElement("style");
style.innerHTML = `
.mbusc-azlp-img {
opacity: 0;
max-width: 80%;
max-height: 100%;
flex-grow: 1;
}
.mbusc-azlp-container {
height: 10%;
width: 100%;
position: absolute;
z-index: 50;
bottom: 1%;
display: flex;
flex-direction: column-reverse;
align-items: center;
}
}
`;
document.head.appendChild(style);
const animation_frames = {
opacity: [0, 1, 1, 0],
offset: [0, 0.1, 0.9, 1],
easing: ["ease-in", "linear", "ease-out"],
}
let player_div = null;
for (i=0;i<20;i++) {
player_div = document.getElementById("movie_player");
if (player_div != null) break;
await sleep(250);
}
const player = player_div.querySelector("video");
const image_div = document.createElement("div");
image_div.classList.add("mbusc-azlp-container");
const image = document.createElement("img");
image.classList.add("mbusc-azlp-img");
image_div.appendChild(image);
player_div.appendChild(image_div);
const animation = image.animate(animation_frames, 10000);
player.addEventListener("play", () => {
const category_pill = document.querySelector(".sponsorBlockCategoryPill");
if (!category_pill) return;
if (!(
(category_pill.style.backgroundColor.includes("sponsor") && getSetting("trigger-sponsor"))
|| (category_pill.style.backgroundColor.includes("exclusive_access") && getSetting("trigger-exclusive-access"))
|| (category_pill.style.backgroundColor.includes("selfpromo") && getSetting("trigger-selfpromo"))
)) return;
animation.finish();
image.src = getSetting("start-image-url");
animation.play();
});
player.addEventListener("pause", () => {
const category_pill = document.querySelector(".sponsorBlockCategoryPill");
if (!category_pill) return;
if (!(
(category_pill.style.backgroundColor.includes("sponsor") && getSetting("trigger-sponsor"))
|| (category_pill.style.backgroundColor.includes("exclusive_access") && getSetting("trigger-exclusive-access"))
|| (category_pill.style.backgroundColor.includes("selfpromo") && getSetting("trigger-selfpromo"))
)) return;
animation.finish();
image.src = getSetting("end-image-url");
animation.play();
});
})();