mirror of
https://gitlab.com/arnekeller/yt-addiction-control.git
synced 2024-11-23 00:45:00 +00:00
Rehide video suggestions after clicking on one
This commit is contained in:
parent
468595da75
commit
6b54383dec
@ -6,7 +6,7 @@ Array.from(document.getElementsByClassName(STYLE_CLASS)).forEach((e) => {
|
||||
e.remove();
|
||||
});
|
||||
|
||||
let ytacCSS = {
|
||||
window.ytacCSS = {
|
||||
"sidebar": "#related",
|
||||
"comments": "#comments",
|
||||
"endscreen": ".videowall-endscreen",
|
||||
@ -15,24 +15,37 @@ let ytacCSS = {
|
||||
"other": "#newness-dot, .ytp-spinner"
|
||||
};
|
||||
|
||||
const INVISIBLE = " { display: none !important; }"
|
||||
const INVISIBLE = " { display: none !important; }";
|
||||
|
||||
function addCSS(key) {
|
||||
if (document.getElementById("ytac" + key) !== null) {
|
||||
return;
|
||||
}
|
||||
let head = document.getElementsByTagName('head')[0];
|
||||
for (key of Object.keys(ytacCSS)) {
|
||||
let e = document.createElement('style');
|
||||
e.setAttribute('type', 'text/css');
|
||||
e.setAttribute("class", STYLE_CLASS);
|
||||
e.setAttribute("id", "ytac" + key);
|
||||
|
||||
if ('textContent' in e) {
|
||||
e.textContent = ytacCSS[key] + INVISIBLE;
|
||||
e.textContent = window.ytacCSS[key] + INVISIBLE;
|
||||
} else {
|
||||
e.styleSheet.cssText = ytacCSS[key] + INVISIBLE;
|
||||
e.styleSheet.cssText = window.ytacCSS[key] + INVISIBLE;
|
||||
}
|
||||
|
||||
head.appendChild(e);
|
||||
}
|
||||
|
||||
function addClickListeners(key) {
|
||||
for (el of document.querySelectorAll(window.ytacCSS[key])) {
|
||||
el.addEventListener("click", (e) => addCSS(key));
|
||||
}
|
||||
}
|
||||
|
||||
for (key of Object.keys(window.ytacCSS)) {
|
||||
addCSS(key);
|
||||
}
|
||||
|
||||
// browser action listener
|
||||
|
||||
// Listen for messages from the background script.
|
||||
@ -47,6 +60,7 @@ window.ytacListener = (message) => {
|
||||
} else if (message.command == "sidebar") {
|
||||
console.log("[YTAC] showing video sidebar");
|
||||
document.getElementById("ytacsidebar").remove();
|
||||
addClickListeners("sidebar");
|
||||
} else if (message.command == "invideo") {
|
||||
console.log("[YTAC] showing in-video suggestions");
|
||||
document.getElementById("ytacinvideo").remove();
|
||||
|
Loading…
Reference in New Issue
Block a user