Light Modus hinzugefügt

This commit is contained in:
clerie 2018-06-29 12:16:09 +02:00
parent d0a14f0ee5
commit ac139f6bca
4 changed files with 82 additions and 16 deletions

View File

@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Witzig! - Nicht Witzig!",
"version": "1.1",
"version": "1.2",
"description": "Replaces the thumb up and down in YouTube with a Witzig! and a Nicht Witzig! stamp.",
"homepage_url": "https://github.com/clerie/witzig-nicht-witzig/",
@ -24,6 +24,12 @@
"web_accessible_resources": [
"media/*"
]
],
"options_ui": {
"page": "settings/index.html"
},
"permissions": ["storage"]
}

23
settings/index.html Normal file
View File

@ -0,0 +1,23 @@
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form>
<h2>Ressourcen</h2>
<label>
<input type="checkbox" id="light">
<b>Light Modus</b><br>
Verringert die Prozessorlast durch abschalten der interaktiven Elemente
</label>
<br>
<br>
<button type="submit">Speichen</button>
</form>
<script src="settings.js"></script>
</body>
</html>

23
settings/settings.js Normal file
View File

@ -0,0 +1,23 @@
function saveOptions(e) {
e.preventDefault();
browser.storage.local.set({
light: document.querySelector("#light").checked
});
}
function restoreOptions() {
function setCurrentChoice(result) {
document.querySelector("#light").checked = result.light || false;
}
function onError(error) {
console.log(`Error: ${error}`);
}
var getting = browser.storage.local.get("light");
getting.then(setCurrentChoice, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);

View File

@ -27,6 +27,10 @@ function getURL(path) {
return chrome.runtime.getURL(path) || browser.runtime.getURL(path);
}
function onError(error) {
log(`Error: ${error}`);
}
/*
Grafikfunktionen
*/
@ -50,7 +54,7 @@ Hauptfunktion
*/
// Ersetzt die Daumen durch Stempel
function inject() {
function inject(settings) {
var container_object = document.querySelectorAll(container_path);
resize_container(container_object[0], "100px");
resize_container(container_object[1], "100px");
@ -59,7 +63,7 @@ function inject() {
log("Packe Stempel aus...");
// wenn Like aktiv, zeige aktive Grafik an
if(container_object[0].classList.contains('style-default-active')) {
if(container_object[0].classList.contains('style-default-active') || settings.light) {
inject_image(image_container_object[0], getURL("media/stempel-witzig.png"));
}
else {
@ -68,7 +72,7 @@ function inject() {
log("Witzig!");
// wenn Dislike aktiv, zeige aktive Grafik an
if(container_object[1].classList.contains('style-default-active')) {
if(container_object[1].classList.contains('style-default-active') || settings.light) {
inject_image(image_container_object[1], getURL("media/stempel-nicht-witzig.png"));
}
else {
@ -79,7 +83,7 @@ function inject() {
// Warte noch kurz vor dem einfügen
function inject_with_timeout() {
setTimeout(inject, 10);
setTimeout(function () {inject({light: false})}, 10);
}
/*
@ -96,7 +100,7 @@ function inject_loop () {
current_url = window.location.href;
if(current_url != last_loaded_url) {
log("Neues");
setTimeout(inject, 500);
setTimeout(function () {inject({light: false})}, 500);
last_loaded_url = current_url;
}
@ -106,10 +110,12 @@ function inject_loop () {
// Die YouTube Website läd die Inhalte durch ein externes JavaScript, wenn wir von vornherein unsere eigenen Inhalte einsetzen, werden diese später von YouTube wieder überschrieben. Wir schauen also, ob ein bestimmtes Objekt, dass durch JavaScript eingefügt wird, exstiert, dann erst bringen wir unsere eigenen Inhalte ein.
var loaded = false;
function loading() {
function loading(settings) {
loaded = document.querySelector(load_end_check_path);
if (loaded) {
log("Stempelfläche gefunden.");
if(!settings.light) {
// initialisiere onclick events
link_object = document.querySelectorAll(link_path);
link_object[0].onclick = inject_with_timeout;
@ -119,10 +125,18 @@ function loading() {
inject_loop();
}
else {
setTimeout(loading, 500);
inject(settings);
}
}
else {
setTimeout(function () {loading(settings)}, 500);
}
}
// Starte das Add-on
log("Suche Stempelfläche...");
loading();
// lade Einstellungen
var getting = browser.storage.local.get("light");
getting.then(loading, onError);