Skip to content

Commit 5a7050a

Browse files
committed
Initial commit
0 parents  commit 5a7050a

File tree

6 files changed

+231
-0
lines changed

6 files changed

+231
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Dark Mode Toggle
2+
3+
A simple Firefox extension that creates a toolbar button to toggle dark mode on and off.
4+
5+
Icons modified from originals by ionicons (ionic.io/ionicons).

background.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let isDark;
2+
3+
function updateState() {
4+
isDark = browser.browserSettings.overrideContentColorScheme
5+
.get({})
6+
.then((res) => {
7+
isDark = res.value == 'dark';
8+
browser.browserAction.setIcon({
9+
path: isDark ? "icons/moon.svg" : "icons/sun.svg"
10+
});
11+
});
12+
}
13+
14+
function toggleDarkMode() {
15+
browser.browserSettings.overrideContentColorScheme
16+
.set({ value: isDark ? 'light' : 'dark' })
17+
.then(() => { updateState(); });
18+
}
19+
20+
browser.browserAction.onClicked.addListener(toggleDarkMode);
21+
22+
// update when the extension loads initially
23+
updateState();

icons/moon.svg

+42
Loading

icons/sun.svg

+53
Loading

icons/toggle.svg

+86
Loading

manifest.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Dark Mode Toggle",
4+
"version": "1.0",
5+
"description": "Toolbar button to toggle dark mode",
6+
"icons": {
7+
"48": "icons/toggle.svg",
8+
"96": "icons/toggle.svg"
9+
},
10+
"browser_action": {
11+
"default_icon": "icons/toggle.svg",
12+
"default_title": "Toggle dark mode"
13+
},
14+
"background": {
15+
"scripts": [
16+
"background.js"
17+
]
18+
},
19+
"permissions": [
20+
"browserSettings"
21+
]
22+
}

0 commit comments

Comments
 (0)