mirror of
https://gitlab.com/arnekeller/yt-addiction-control.git
synced 2024-11-22 16:34:59 +00:00
Initial commit
This commit is contained in:
commit
56b2910980
6
icons/ytac.svg
Normal file
6
icons/ytac.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500">
|
||||
<rect x="70" y="115" width="360" height="270" fill="#F00"/>
|
||||
<path fill="#fff" stroke-width="1" stroke="#fff" d="M 150 150 l 200 100 l -200 100 l 0 -200"/>
|
||||
<path fill="none" stroke-width="50" stroke="#B00" d="M86,88a230,230 0 1,0 1,-1zL412,412"/>
|
||||
</svg>
|
After Width: | Height: | Size: 357 B |
20
manifest.json
Normal file
20
manifest.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
23
popup/control.css
Normal file
23
popup/control.css
Normal file
@ -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;
|
||||
}
|
20
popup/control.html
Normal file
20
popup/control.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="control.css"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="popup-content">
|
||||
<div class="button" id="comments">Show comments</div>
|
||||
<div class="button" id="sidebar">Show video sidebar</div>
|
||||
<div class="button" id="invideo">Show in-video video suggestions</div>
|
||||
<div class="button" id="endscreen">Show endscreen video suggestions</div>
|
||||
<div class="button" id="notification">Show notification button</div>
|
||||
</div>
|
||||
<script src="control.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
13
popup/control.js
Normal file
13
popup/control.js
Normal file
@ -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);
|
||||
});
|
7
todo.txt
Normal file
7
todo.txt
Normal file
@ -0,0 +1,7 @@
|
||||
"theme_icons": [{
|
||||
"light": "icons/beasts-32-light.png",
|
||||
"dark": "icons/beasts-32.png",
|
||||
"size": 32
|
||||
}],
|
||||
|
||||
(4) tab title notification count
|
87
youtube-addiction-control-extension-firefox.js
Normal file
87
youtube-addiction-control-extension-firefox.js
Normal file
@ -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();
|
Loading…
Reference in New Issue
Block a user