-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
199 lines (180 loc) · 6.91 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
fetch("https://raw.githubusercontent.com/pelcatala/titolscat/main/titolsext.json")
.then((response) => response.json())
.then((data) => {
// Variable global codis
var codis = data;
// Variable global d'audio
var audio;
function injecta() {
// Buscar si està disponible
var identificador = location.href.match(/^\d+|\d+\b|\d+(?=\w)/g)[0];
let disponible = codis.find(el => el.codi === identificador.toString());
if (disponible == null) {
console.log("contingut no disponible")
} else {
// Sol·licitud servidor
let req = new XMLHttpRequest();
var basedades;
req.onreadystatechange = () => {
if (req.readyState == 4) {
// Interpretar resposta
basedades = req.responseText;
basedades = JSON.parse(basedades);
var trobat = 1;
try {
const adreca = basedades[0].audio;
}
catch (error) {
trobat = 0;
console.log("contingut no trobat a la base de dades");
}
finally {
if (trobat == 1) {
console.log("contingut sí trobat a la base de dades");
// Carregar dades
let primer = 1;
const adreca = basedades[0].audio;
const desf = parseFloat(basedades[0].desf);
const videoPlayer = netflix.appContext.state.playerApp.getAPI().videoPlayer;
const player = videoPlayer.getVideoPlayerBySessionId(videoPlayer.getAllPlayerSessionIds()[0]);
player.pause();
audio = new Audio(adreca);
audio.preload="none";
// Reproducció i pausa segures
var promesa;
function repro() {
if (primer != 1) {
promesa = audio.play();
};
};
function pausase() {
if (promesa !== undefined) {
promesa.then(_ => {
audio.pause();
})
}
}
// Events
player.addEventListener("currenttimechanged", () => { if (Math.abs(audio.currentTime - (player.getCurrentTime() / 1000 + desf)) > 0.2) audio.currentTime = player.getCurrentTime() / 1000 + desf });
player.addEventListener("playingchanged", () => { if (player.isPaused()) pausase(); else if (player.isMuted()) { primer = 0; repro() } });
player.addEventListener("mutedchanged", () => { if (player.isMuted()) { audio = new Audio(adreca); if (!player.isPaused()) { repro() } } else pausase() });
// Mutejar a l'iniciar
if (player.isMuted()) {
//promesa = audio.play();
} else {
player.setMuted(1);
}
// Posar V.O.
setTimeout(function () {
const trackList = player.getAudioTrackList();
var idioma = 0;
function posarvo() {
if (trackList[idioma].isNative) {
player.setAudioTrack(trackList[idioma]);
}
else if (idioma < trackList.length - 1) {
idioma = idioma + 1;
posarvo();
}
}
posarvo();
}, ((Math.random() * 10) + 5) * 100);
}
}
}
}
// Consultar base de dades
req.open("GET", "https://www.hybrid-ware.com/netflix", true);
req.setRequestHeader("X-Access-Key", "$2b$10$V5KbCVo8rGFLobLQauuOQuqxzKW9vFzYW4fWNyjMQ0Drna3.udebW");
req.setRequestHeader("X-JSON-Path", identificador);
req.setRequestHeader("X-Bin-Meta", "false");
req.send();
}
}
// Ordre de buscar doblatge en català
function intenta() {
setTimeout(function () {
var acert = 0;
try {
const videoPlayer = netflix.appContext.state.playerApp.getAPI().videoPlayer;
const player = videoPlayer.getVideoPlayerBySessionId(videoPlayer.getAllPlayerSessionIds()[0]);
if (typeof player === "undefined") {
acert = 0;
} else {
acert = 1;
}
player.play();
} catch (error) {
acert = 0;
} finally {
if (acert == 0) {
intenta();
} else {
injecta();
}
}
}, 100);
}
// Si s'obre una pàgina d'inici es busca doblatge immediatament
var expressio = /\bnetflix.com\/watch\/\b/g
if (window.location.href.match(expressio) == "netflix.com/watch/") {
intenta();
} else {
titolscat();
};
// Cada segon consulta si s'ha canviat de pàgina
var anterior = window.location.href;
setInterval(function () {
if (anterior != window.location.href) {
anterior = window.location.href;
if (window.location.href.match(expressio) == "netflix.com/watch/") {
try {
audio.pause();
} catch (error) { } finally {
intenta();
}
} else {
try {
audio.pause();
} catch (error) { } finally {
titolscat();
}
}
}
}, 1000);
// Funció que afegeix al catàleg l'indicador de contingut en català
function titolscat() {
let url = 'https://raw.githubusercontent.com/pelcatala/titolscat/main/titolscat.json';
var tagradaria = document.createElement("img")
tagradaria.src = "https://raw.githubusercontent.com/pelcatala/titolscat/main/indicador.png";
tagradaria.setAttribute("height", "48px")
tagradaria.setAttribute("class", "imgdisp")
tagradaria.style.position = "absolute";
tagradaria.style.top = "0px";
tagradaria.style.right = "0px";
fetch(url)
.then(res => res.json())
.then(out => {
var codis = out;
function runFunction() {
var encatala = document.getElementsByClassName("slider-refocus")
for (let disp in encatala) {
if (encatala[disp].childNodes?.length) {
for (var i = 0; i < encatala[disp].childNodes.length; i++) {
if (encatala[disp].childNodes[i].className == "imgdisp") {
break;
} else if (i == encatala[disp].childNodes.length - 1) {
var codi = encatala[disp].pathname.match(/^[^\d]*(\d+)/)[1]
let disponible = codis.find(el => el.codi === codi.toString());
if (disponible != null) {
encatala[disp].appendChild(tagradaria.cloneNode(true));
}
}
}
}
}
}
var t = setInterval(runFunction, 1000);
});
};
});