-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube-share.user.js
64 lines (55 loc) · 2.24 KB
/
youtube-share.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
// ==UserScript==
// @name YouTube Share tracking remover
// @namespace Violentmonkey Scripts
// @match https://www.youtube.com/*
// @grant none
// @version 2.3
// @downloadURL https://github.com/0Supa/userscripts/raw/main/youtube-share.user.js
// @author Supa
// @description Removes the tracking parameter(s) YouTube adds when using the Share button, and other annoyances
// ==/UserScript==
const allowedShareParams = ["t"];
const cleanUrl = (el) => {
const url = new URL(el.value);
for (const key of url.searchParams.keys()) {
if (!allowedShareParams.includes(key))
url.searchParams.delete(key);
}
el.value = url.toString();
};
let timeCheckbox = null;
const observer = new MutationObserver(mutations => {
for (const m of mutations) {
const nodes = Array.from(m.addedNodes);
const dialog = nodes.find(el => el.nodeName === "TP-YT-PAPER-DIALOG")
if (dialog) {
const childNodes = Array.from(dialog.childNodes);
const adblockerPopup = childNodes.find(el => el.nodeName === "YTD-ENFORCEMENT-MESSAGE-VIEW-MODEL");
if (adblockerPopup) {
dialog.remove();
document.querySelector("video")?.play();
document.querySelector("tp-yt-iron-overlay-backdrop")?.remove();
}
break;
}
const sharePanel = nodes.find(el => el.classList?.contains("ytd-unified-share-panel-renderer"));
if (sharePanel) {
const shareUrl = document.querySelector("#share-url");
if (shareUrl) {
cleanUrl(shareUrl);
const checkbox = document.querySelector("#start-at-checkbox");
if (checkbox && timeCheckbox !== checkbox) {
timeCheckbox = checkbox;
timeCheckbox.addEventListener("click", () => {
cleanUrl(shareUrl);
});
}
}
break;
}
}
});
const container = document.querySelector("ytd-app");
if (!container) throw "Parent container not found";
observer.observe(container, { childList: true, subtree: true });
window.addEventListener("visibilitychange", e => e.stopImmediatePropagation(), true);