diff --git a/.gitignore b/.gitignore index 44620bd..1175977 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ icons/action.xcf TODO.txt - -*.crx - -*.pem +.releases +chrome/icons/icon-128\.png diff --git a/firefox/background.js b/firefox/background.js new file mode 100644 index 0000000..2769532 --- /dev/null +++ b/firefox/background.js @@ -0,0 +1,61 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 17): + * wrote this file. As long as you retain this notice you + * can use this stuff for any non-commercial purposes. If we meet some day, + * and you think this stuff is worth it, you can buy me a beer in return. + * Fabian Große + * ---------------------------------------------------------------------------- + */ + +var tabID; //global ist nicht schön + +function init() { + var getStorage = browser.storage.local.get(null, + function getStorageCallback(items){ + if ("isDark" in items) { + if (items["isDark"]) { + _toggleDarkModeHelper(); + } + } + else { + browser.storage.local.set({isDark: false}); + } + } + ) +} + +//Zeige die Page Action für den Tab, aus dem eine Message kam (pietsmiet.de) +function showPageAction(request, sender) { + tabID = sender.tab.id; + browser.pageAction.show(tabID); + init(); +} + +function toggleDarkMode(actionTitle) { + if (actionTitle == "Abdunkeln") { + browser.tabs.sendMessage(tabID, "toDark"); //benachrichtige Content-Script, das Theme zu dunkel zu wechseln + browser.pageAction.setTitle({tabId: tabID, title: "Zurück zu Normal"}); + browser.pageAction.setIcon({tabId: tabID, path: { + 19: "icons/action-19.png", + 38: "icons/action-38.png" + }}); + } + else { + browser.tabs.sendMessage(tabID, "reset"); //benachrichtige Content-Script, das Theme zu normal zu wechseln + browser.pageAction.setTitle({tabId: tabID, title: "Abdunkeln"}); + browser.pageAction.setIcon({tabId: tabID, path: { + 19: "icons/action-off-19.png", + 38: "icons/action-off-38.png" + }}); + } +} + +//Helper-Funktion, weil getTitle unbedingt einen Callback haben muss o.O +function _toggleDarkModeHelper() { + //ruft toggleDarkMode auf und übergibt den aktuellen Action Title + browser.pageAction.getTitle({tabId: tabID}, toggleDarkMode); +} + +browser.runtime.onMessage.addListener(showPageAction); //Sobald das Background-Script eine Message erhält, showPageAction ausführen +browser.pageAction.onClicked.addListener(_toggleDarkModeHelper); //sobald auf die Page Action geklickt wurde, führe _toggleDarkModeHelper aus diff --git a/firefox/content.js b/firefox/content.js new file mode 100644 index 0000000..22ba248 --- /dev/null +++ b/firefox/content.js @@ -0,0 +1,36 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 17): + * wrote this file. As long as you retain this notice you + * can use this stuff for any non-commercial purposes. If we meet some day, + * and you think this stuff is worth it, you can buy me a beer in return. + * Fabian Große + * ---------------------------------------------------------------------------- + */ + +const CSS_FILE = browser.runtime.getURL("darken_ps.css"); //Voll-qualifizierter Pfad zur "dunklen" CSS-Datei + +function onToggleMode(request, sender) { + if (request == "toDark") { //Wenn auf dunkel gewechselt werden soll + var element = document.createElement("link"); + element.setAttribute("id", "darkmode"); //id, um es später wieder zu finden + element.setAttribute("rel", "stylesheet"); + element.setAttribute("type", "text/css"); + element.setAttribute("href", CSS_FILE); + document.getElementsByTagName("head")[0].appendChild(element); //hänge an den Head an + browser.storage.local.set({isDark: true}); + } + else { //also wenn auf normal gewechselt werden soll + document.getElementById("darkmode").remove(); //entferne vorher erstelltes link-Element aus DOM + browser.storage.local.set({isDark: false}); + } +} + +browser.runtime.sendMessage("show the damn icon"); // Sende irgendwas zum Background, um dort die TabID zu haben +browser.runtime.onMessage.addListener(onToggleMode); //Sobald das Content-Script eine Message erhält, onToggleMode ausführen + +// Antworten-Button Fix +var comments = document.getElementsByClassName("comment-body"); +for (i=0; i < comments.length; i++) { + commBodies[i].parentNode.children[2].setAttribute("class","comments-buttons"); +} diff --git a/firefox/darken_ps.css b/firefox/darken_ps.css new file mode 100644 index 0000000..682ec53 --- /dev/null +++ b/firefox/darken_ps.css @@ -0,0 +1,67 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 17): + * wrote this file. As long as you retain this notice you + * can use this stuff for any non-commercial purposes. If we meet some day, + * and you think this stuff is worth it, you can buy me a beer in return. + * Fabian Große + * ---------------------------------------------------------------------------- + */ + +/* Hintergrund und Textfarbe der Hauptseite */ +body { + background-color: #111111; + color: #fff; +} + +/* Hintergrund und Textfarbe des Video-Containers */ +.main .container { + background-color: #242424; + color: #fff; +} + +/* Textfarbe für alle Überschriften */ +h1, +h2, +h3, +h4, +h5 { + color: #fff; +} + +/* Textfarbe für alle Überschriften-Links... */ +h1 a:link, +h2 a:link, +h3 a:link, +h4 a:link, +h5 a:link { + color: #fff; +} + +/* ...auch die bereits besuchten */ +h1 a:visited, +h2 a:visited, +h3 a:visited, +h4 a:visited, +h5 a:visited { + color: #fff; +} + +/* Explizit Textfarbe für... */ +.latestnews-headline, /* Newsüberschriften */ +.ob-rec-text, /* Anzeigenüberschriften */ +.breadcrumb li.active, /* aktives Breadcrumb */ +.comment-body /* Kommentare */ { + color: #fff !important; +} + +/* Breadcrumbs etwas dunkler/grauer */ +.breadcrumb a { + color: #999; +} + +/* Break-Farbe von Beige auf Weiß zu Schwarz auf Grau */ +hr { + border-top: 1px solid #111111; + border-bottom: 1px solid #242424; +} diff --git a/firefox/icons/action-19.png b/firefox/icons/action-19.png new file mode 100644 index 0000000..135075a Binary files /dev/null and b/firefox/icons/action-19.png differ diff --git a/firefox/icons/action-38.png b/firefox/icons/action-38.png new file mode 100644 index 0000000..2140b1f Binary files /dev/null and b/firefox/icons/action-38.png differ diff --git a/firefox/icons/action-off-19.png b/firefox/icons/action-off-19.png new file mode 100644 index 0000000..7cf5bd8 Binary files /dev/null and b/firefox/icons/action-off-19.png differ diff --git a/firefox/icons/action-off-38.png b/firefox/icons/action-off-38.png new file mode 100644 index 0000000..ad1864b Binary files /dev/null and b/firefox/icons/action-off-38.png differ diff --git a/firefox/icons/icon-128.png b/firefox/icons/icon-128.png new file mode 100644 index 0000000..c9f7612 Binary files /dev/null and b/firefox/icons/icon-128.png differ diff --git a/firefox/icons/icon-48.png b/firefox/icons/icon-48.png new file mode 100644 index 0000000..2eaf5e5 Binary files /dev/null and b/firefox/icons/icon-48.png differ diff --git a/firefox/icons/icon-96.png b/firefox/icons/icon-96.png new file mode 100644 index 0000000..bbf39be Binary files /dev/null and b/firefox/icons/icon-96.png differ diff --git a/firefox/manifest.json b/firefox/manifest.json new file mode 100644 index 0000000..d1746fe --- /dev/null +++ b/firefox/manifest.json @@ -0,0 +1,52 @@ +{ + "manifest_version": 2, + "name": "Pietsmiet.de Dark Mode", + "shortname": "Dark Pietsmiet", + "version": "17.1", + "author": "Fabian Große/Saphareas", + "homepage_url": "https://github.com/Saphareas/pietsmiet.de-Dark-Mode", + + "description": "Fügt der Pietsmiet.de-Seite ein dunkles Theme/einen Nachtmodus hinzu.", + + "icons": { + "48": "icons/icon-48.png", + "96": "icons/icon-96.png" + }, + + "applications": { + "gecko": { + "id": "{af4fc8a6-ed40-488f-bd74-417b3906f78f}", + "strict_min_version": "52.0" + } + }, + + "content_scripts": [ + { + "matches": ["*://*.pietsmiet.de/*"], + "js": ["content.js"] + } + ], + + "background": { + "scripts": ["background.js"] + }, + + "page_action": { + "browser_style": true, + "default_icon": { + "19": "icons/action-off-19.png", + "38": "icons/action-off-38.png" + }, + "default_title": "Abdunkeln" + }, + + "permissions": [ + "activeTab", + "storage" + ], + + "web_accessible_resources": [ + "darken_ps.css" + ] + +}