Skip to content

Commit

Permalink
Firefox Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Saphareas committed Jan 17, 2018
1 parent 9dff1cf commit f32c387
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 4 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
icons/action.xcf
TODO.txt

*.crx

*.pem
.releases
chrome/icons/icon-128\.png
61 changes: 61 additions & 0 deletions firefox/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 17):
* <saphareas@gmail.com> 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
36 changes: 36 additions & 0 deletions firefox/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 17):
* <saphareas@gmail.com> 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");
}
67 changes: 67 additions & 0 deletions firefox/darken_ps.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 17):
* <saphareas@gmail.com> 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;
}
Binary file added firefox/icons/action-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/action-38.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/action-off-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/action-off-38.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/icon-96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
]

}

0 comments on commit f32c387

Please sign in to comment.