-
Notifications
You must be signed in to change notification settings - Fork 3
/
disable-youtube-av1-vp9.js
197 lines (147 loc) · 6.01 KB
/
disable-youtube-av1-vp9.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
// ==UserScript==
// @name Disable YouTube AV1 and VP9
// @description Disable AV1 and VP9 for video playback on YouTube
// @name:zh-TW 停用 YouTube AV1 和 VP9
// @description:zh-TW 停用 YouTube 的 AV1 和 VP9 影片播放
// @name:zh-HK 停用 YouTube AV1 和 VP9
// @description:zh-HK 停用 YouTube 的 AV1 和 VP9 影片播放
// @name:zh-CN 停用 YouTube AV1 和 VP9
// @description:zh-CN 停用 YouTube 的 AV1 和 VP9 视频播放
// @name:ja YouTube AV1 と VP9 の停用
// @description:ja YouTube の動画再生に AV1 と VP9 を停用する
// @name:ko YouTube AV1과 VP9 비활성화
// @description:ko YouTube의 동영상 재생에 AV1과 VP9를 비활성화하기
// @name:vi Vô hiệu hóa YouTube AV1 và VP9
// @description:vi Vô hiệu hóa AV1 và VP9 để phát video trên YouTube
// @name:de YouTube AV1 und VP9 deaktivieren
// @description:de Deaktiviert AV1 und VP9 für die Videowiedergabe auf YouTube
// @name:fr Désactiver YouTube AV1 et VP9
// @description:fr Désactivez AV1 et VP9 pour la lecture des vidéos sur YouTube
// @name:it Disabilita YouTube AV1 e VP9
// @description:it Disabilita AV1 e VP9 per la riproduzione dei video su YouTube
// @name:es Desactivar AV1 y VP9 en YouTube
// @description:es Desactivar AV1 y VP9 para la reproducción de videos en YouTube
// @namespace http://tampermonkey.net/
// @version 2.4.3
// @author CY Fung
// @match https://www.youtube.com/*
// @match https://www.youtube.com/embed/*
// @match https://www.youtube-nocookie.com/embed/*
// @exclude https://www.youtube.com/live_chat*
// @exclude https://www.youtube.com/live_chat_replay*
// @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// @run-at document-start
// @license MIT
// @compatible chrome
// @compatible firefox
// @compatible opera
// @compatible edge
// @compatible safari
// @unwrap
// @allFrames true
// @inject-into page
// ==/UserScript==
(function () {
'use strict';
console.debug("disable-youtube-av1-and-vp9", "injected");
const flagConfig = () => {
let firstDa = true;
let cid = 0;
const { setInterval, clearInterval, setTimeout } = window;
const tn = () => {
const da = (window.ytcfg && window.ytcfg.data_) ? window.ytcfg.data_ : null;
if (!da) return;
const isFirstDa = firstDa;
firstDa = false;
for (const EXPERIMENT_FLAGS of [da.EXPERIMENT_FLAGS, da.EXPERIMENTS_FORCED_FLAGS]) {
if (EXPERIMENT_FLAGS) {
// EXPERIMENT_FLAGS.html5_disable_av1_hdr = true;
// EXPERIMENT_FLAGS.html5_prefer_hbr_vp9_over_av1 = true;
}
}
if (isFirstDa) {
let mo = new MutationObserver(() => {
mo.disconnect();
mo.takeRecords();
mo = null;
setTimeout(() => {
cid && clearInterval.call(window, cid);
cid = 0;
tn();
})
});
mo.observe(document, { subtree: true, childList: true });
}
};
cid = setInterval.call(window, tn);
};
const supportedFormatsConfig = () => {
function typeTest(type) {
if (typeof type === 'string' && type.startsWith('video/')) {
if (type.includes('vp9')) {
if (/codecs[\x20-\x7F]+\bvp9\b/.test(type)) return false;
} else if (type.includes('vp09')) {
if (/codecs[\x20-\x7F]+\bvp09\b/.test(type)) return false;
} else if (type.includes('av01')) {
if (/codecs[\x20-\x7F]+\bav01\b/.test(type)) return false;
} else if (type.includes('av1')) {
if (/codecs[\x20-\x7F]+\bav1\b/.test(type)) return false;
}
}
}
// return a custom MIME type checker that can defer to the original function
function makeModifiedTypeChecker(origChecker, dx) {
// Check if a video type is allowed
return function (type) {
let res = undefined;
if (type === undefined) res = false;
else res = typeTest(type);
if (res === undefined) res = origChecker.apply(this, arguments);
else res = !dx ? res : (res ? "probably" : "");
// console.debug(20, type, res)
return res;
};
}
// Override video element canPlayType() function
const proto = (HTMLVideoElement || 0).prototype;
if (proto && typeof proto.canPlayType == 'function') {
proto.canPlayType = makeModifiedTypeChecker(proto.canPlayType, true);
}
// Override media source extension isTypeSupported() function
const mse = window.MediaSource;
// Check for MSE support before use
if (mse && typeof mse.isTypeSupported == 'function') {
mse.isTypeSupported = makeModifiedTypeChecker(mse.isTypeSupported);
}
};
function disableAV1() {
// This is the setting to disable AV1
// localStorage['yt-player-av1-pref'] = '-1';
try {
Object.defineProperty(localStorage.constructor.prototype, 'yt-player-av1-pref', {
get() {
if (this === localStorage) return '-1';
return this.getItem('yt-player-av1-pref');
},
set(nv) {
this.setItem('yt-player-av1-pref', nv);
return true;
},
enumerable: true,
configurable: true
});
} catch (e) {
// localStorage['yt-player-av1-pref'] = '-1';
}
if (localStorage['yt-player-av1-pref'] !== '-1') {
console.warn('Disable YouTube AV1 and VP9', '"yt-player-av1-pref = -1" is not supported in your browser.');
return;
}
console.debug("disable-youtube-av1-and-vp9", "AV1 disabled by yt-player-av1-pref = -1");
}
disableAV1();
// flagConfig();
supportedFormatsConfig();
})();