-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyoutube_network_error_hook.user.js
50 lines (42 loc) · 1.5 KB
/
youtube_network_error_hook.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
// ==UserScript==
// @name Youtube network error hook
// @namespace https://github.com/stu43005
// @version 0.3
// @description
// @author stu43005
// @match https://www.youtube.com/watch*
// @match https://www.youtube.com/embed*
// @exclude https://www.youtube.com/live_chat*
// @run-at document-end
// @grant none
// @require https://unpkg.com/[email protected]/umd/bundle.js
// ==/UserScript==
let retry = 0;
function main() {
'use strict';
if (!window._yt_player) {
if (retry > 10) return;
setTimeout(main, 1000);
retry++;
return;
}
const firstKey = Object.keys(window._yt_player).find(key => {
return window._yt_player[key]?.toString().includes(".videoData.isValid()");
});
if (!firstKey) return;
const temp1 = new window._yt_player[firstKey]({ videoData: { isValid() { return false } } });
const secondKey = Object.keys(temp1).find(key => {
return temp1[key]?.__proto__?.onError;
});
if (!secondKey) return;
const old_onError = temp1[secondKey].__proto__.onError;
temp1[secondKey].__proto__.onError = function (a) {
old_onError.call(this, a);
const videoId = window.ytcfg.get("VIDEO_ID");
console.log(`[errorHook][${videoId}] yt player error:`, a);
window.miniToast.init(a, {}).show();
};
console.log(`[errorHook] setup page: ${location.href}`);
// window.miniToast.init(`[errorHook] setup page`, {}).show();
}
main();