-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyoutube_livechat_remove_ticker.user.js
More file actions
59 lines (55 loc) · 2.53 KB
/
youtube_livechat_remove_ticker.user.js
File metadata and controls
59 lines (55 loc) · 2.53 KB
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
// ==UserScript==
// @name Youtube Livechat remove ticker
// @namespace https://github.com/stu43005
// @version 20250126
// @description
// @author stu43005
// @match https://www.youtube.com/live_chat*
// @match https://www.youtube.com/live_chat_replay*
// @run-at document-start
// @grant none
// @allFrames true
// ==/UserScript==
const getLiveChat = "/youtubei/v1/live_chat/get_live_chat";
window.fetch = new Proxy(fetch, {
apply: function (target, thisArg, args) {
const arg0 = args[0];
const url = arg0 && arg0 instanceof Request ? arg0.url : arg0?.toString();
if (url.includes(getLiveChat)) {
return target.apply(thisArg, args).then((response) => {
const contentType = response.headers.get("Content-Type");
if (contentType && contentType.includes("application/json")) {
return response
.clone()
.json()
.then((data) => {
const liveChatContinuation =
data.continuationContents?.liveChatContinuation;
if (liveChatContinuation?.actions) {
const originCount = liveChatContinuation.actions.length;
liveChatContinuation.actions = liveChatContinuation.actions.filter(
(action) => !("addLiveChatTickerItemAction" in action)
);
const newCount = liveChatContinuation.actions.length;
if (originCount !== newCount) {
console.log(
`actions ${originCount} -> ${newCount} (remove ${
originCount - newCount
})`
);
}
}
return new Response(JSON.stringify(data), {
status: response.status,
statusText: response.statusText,
headers: response.headers,
});
});
}
return response;
});
}
return target.apply(thisArg, args);
},
});
document.querySelectorAll("#ticker-items > *").forEach((el) => el.remove());