2019-06-29 19:47:18 +00:00
|
|
|
// inject CSS
|
|
|
|
|
|
|
|
const STYLE_CLASS = "youtube-ac-styling";
|
|
|
|
|
|
|
|
Array.from(document.getElementsByClassName(STYLE_CLASS)).forEach((e) => {
|
|
|
|
e.remove();
|
|
|
|
});
|
|
|
|
|
2019-07-11 19:19:07 +00:00
|
|
|
window.ytacCSS = {
|
2019-06-29 19:47:18 +00:00
|
|
|
"sidebar": "#related",
|
|
|
|
"comments": "#comments",
|
|
|
|
"endscreen": ".videowall-endscreen",
|
|
|
|
"invideo": ".ytp-ce-video",
|
|
|
|
"notification": "ytd-notification-topbar-button-renderer",
|
2019-07-10 09:59:04 +00:00
|
|
|
"other": "#newness-dot, .ytp-spinner"
|
2019-06-29 19:47:18 +00:00
|
|
|
};
|
|
|
|
|
2019-07-11 19:19:07 +00:00
|
|
|
const INVISIBLE = " { display: none !important; }";
|
2019-06-29 19:47:18 +00:00
|
|
|
|
2019-07-11 19:19:07 +00:00
|
|
|
function addCSS(key) {
|
|
|
|
if (document.getElementById("ytac" + key) !== null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let head = document.getElementsByTagName('head')[0];
|
2019-06-29 19:47:18 +00:00
|
|
|
let e = document.createElement('style');
|
|
|
|
e.setAttribute('type', 'text/css');
|
|
|
|
e.setAttribute("class", STYLE_CLASS);
|
|
|
|
e.setAttribute("id", "ytac" + key);
|
|
|
|
|
|
|
|
if ('textContent' in e) {
|
2019-07-11 19:19:07 +00:00
|
|
|
e.textContent = window.ytacCSS[key] + INVISIBLE;
|
2019-06-29 19:47:18 +00:00
|
|
|
} else {
|
2019-07-11 19:19:07 +00:00
|
|
|
e.styleSheet.cssText = window.ytacCSS[key] + INVISIBLE;
|
2019-06-29 19:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
head.appendChild(e);
|
|
|
|
}
|
|
|
|
|
2019-07-11 19:19:07 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:47:18 +00:00
|
|
|
// browser action listener
|
|
|
|
|
|
|
|
// Listen for messages from the background script.
|
|
|
|
if (window.ytacListener != null) {
|
|
|
|
browser.runtime.onMessage.removeListener(window.ytacListener);
|
|
|
|
}
|
|
|
|
window.ytacListener = (message) => {
|
|
|
|
console.log("[YTAC] received browser action " + message.command);
|
|
|
|
if (message.command == "comments") {
|
|
|
|
console.log("[YTAC] showing comments");
|
|
|
|
document.getElementById("ytaccomments").remove();
|
|
|
|
} else if (message.command == "sidebar") {
|
|
|
|
console.log("[YTAC] showing video sidebar");
|
|
|
|
document.getElementById("ytacsidebar").remove();
|
2019-07-11 19:19:07 +00:00
|
|
|
addClickListeners("sidebar");
|
2019-06-29 19:47:18 +00:00
|
|
|
} else if (message.command == "invideo") {
|
|
|
|
console.log("[YTAC] showing in-video suggestions");
|
|
|
|
document.getElementById("ytacinvideo").remove();
|
|
|
|
} else if (message.command == "endscreen") {
|
|
|
|
console.log("[YTAC] showing endscreen");
|
|
|
|
document.getElementById("ytacendscreen").remove();
|
|
|
|
} else if (message.command == "notification") {
|
|
|
|
console.log("[YTAC] showing notification bell");
|
|
|
|
document.getElementById("ytacnotification").remove();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
browser.runtime.onMessage.addListener(window.ytacListener);
|
|
|
|
console.log("[YTAC] added action listener");
|
|
|
|
|
|
|
|
function modifyThings() {
|
|
|
|
let repeating = false;
|
|
|
|
// autoplay disabler
|
|
|
|
let autoplayButton = document.getElementById("toggle");
|
|
|
|
if (autoplayButton == null) {
|
2019-07-10 09:59:04 +00:00
|
|
|
console.warn("[YTAC] could not locate autoplay button");
|
2019-06-29 19:47:18 +00:00
|
|
|
} else if (autoplayButton.getAttribute("aria-pressed") === "true") {
|
|
|
|
autoplayButton.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
// description expander
|
2019-07-10 09:59:04 +00:00
|
|
|
let showMoreButton = document.getElementsByClassName("more-button");
|
|
|
|
if (showMoreButton.length == 0) {
|
2019-06-29 19:47:18 +00:00
|
|
|
console.warn("[YTAC] could not locate description expander, trying again in 5s");
|
2019-07-10 09:59:04 +00:00
|
|
|
setTimeout(modifyThings, 5000);
|
2019-06-29 19:47:18 +00:00
|
|
|
} else {
|
2019-07-10 09:59:04 +00:00
|
|
|
showMoreButton[0].click();
|
2019-06-29 19:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
modifyThings();
|