commit 56b2910980a9ad4d913a72cccd8a261f18ce4898 Author: Arne Keller Date: Sat Jun 29 21:47:18 2019 +0200 Initial commit diff --git a/icons/ytac.svg b/icons/ytac.svg new file mode 100644 index 0000000..ad6c27a --- /dev/null +++ b/icons/ytac.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..5f390d6 --- /dev/null +++ b/manifest.json @@ -0,0 +1,20 @@ +{ + "description": "Enables you to fight your youtube addiction by disabling video suggestions and related 'features' of YouTube's website.", + "manifest_version": 2, + "name": "yt-addiction-control", + "version": "0.1", + "homepage_url": "https://github.repository.todo/", + + "content_scripts": [ + { + "matches": ["*://*.youtube.com/*"], + "js": ["youtube-addiction-control-extension-firefox.js"] + } + ], + + "browser_action": { + "default_icon": "icons/ytac.svg", + "default_title": "YT Addiction Control", + "default_popup": "popup/control.html" + } +} diff --git a/popup/control.css b/popup/control.css new file mode 100644 index 0000000..6922323 --- /dev/null +++ b/popup/control.css @@ -0,0 +1,23 @@ +html, body { + width: 15em; +} + +.hidden { + display: none; +} + +.button { + margin: 3% auto; + padding: 4px; + text-align: center; + font-size: 1.5em; + cursor: pointer; +} + +.button:hover { + background-color: #CFF2F2; +} + +.button { + background-color: #E5F2F2; +} \ No newline at end of file diff --git a/popup/control.html b/popup/control.html new file mode 100644 index 0000000..f7d14c3 --- /dev/null +++ b/popup/control.html @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/popup/control.js b/popup/control.js new file mode 100644 index 0000000..578658e --- /dev/null +++ b/popup/control.js @@ -0,0 +1,13 @@ +/** +* Listen for clicks on the buttons, and send the appropriate message to +* the content script in the page. +*/ +document.addEventListener("click", (e) => { + function applyChange(tabs) { + browser.tabs.sendMessage(tabs[0].id, { + command: e.target.id + }); + } + browser.tabs.query({active: true, currentWindow: true}) + .then(applyChange); +}); diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..debd803 --- /dev/null +++ b/todo.txt @@ -0,0 +1,7 @@ +"theme_icons": [{ + "light": "icons/beasts-32-light.png", + "dark": "icons/beasts-32.png", + "size": 32 + }], + +(4) tab title notification count \ No newline at end of file diff --git a/youtube-addiction-control-extension-firefox.js b/youtube-addiction-control-extension-firefox.js new file mode 100644 index 0000000..63b19b0 --- /dev/null +++ b/youtube-addiction-control-extension-firefox.js @@ -0,0 +1,87 @@ +// inject CSS + +const STYLE_CLASS = "youtube-ac-styling"; + +Array.from(document.getElementsByClassName(STYLE_CLASS)).forEach((e) => { + e.remove(); +}); + +let ytacCSS = { + "sidebar": "#related", + "comments": "#comments", + "endscreen": ".videowall-endscreen", + "invideo": ".ytp-ce-video", + "notification": "ytd-notification-topbar-button-renderer", + "other": "newness-dot, .ytp-spinner" +}; + +const INVISIBLE = " { display: none !important; }" + +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; + } else { + e.styleSheet.cssText = ytacCSS[key] + INVISIBLE; + } + + head.appendChild(e); +} + +// 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(); + } 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) { + console.warn("[YTAC] could not locate autoplay button, trying again in 5s"); + setTimeout(modifyThings, 5000); + repeating = true; + } else if (autoplayButton.getAttribute("aria-pressed") === "true") { + autoplayButton.click(); + } + + // description expander + let showMoreButton = document.getElementById("more"); + if (showMoreButton == null) { + console.warn("[YTAC] could not locate description expander, trying again in 5s"); + if (!repeating) { + setTimeout(modifyThings, 5000); + } + } else { + showMoreButton.click(); + } +} +modifyThings(); \ No newline at end of file