From 3e2d1833d7911cafb608cd68f30f9b221025096a Mon Sep 17 00:00:00 2001 From: Tim Nguyen Date: Tue, 7 Nov 2017 18:56:55 +0000 Subject: [PATCH] Add per-window theme example: private browsing theme (#307) --- private-browsing-theme/README.md | 9 +++++++++ private-browsing-theme/background.js | 25 +++++++++++++++++++++++++ private-browsing-theme/manifest.json | 16 ++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 private-browsing-theme/README.md create mode 100644 private-browsing-theme/background.js create mode 100644 private-browsing-theme/manifest.json diff --git a/private-browsing-theme/README.md b/private-browsing-theme/README.md new file mode 100644 index 0000000..3326d19 --- /dev/null +++ b/private-browsing-theme/README.md @@ -0,0 +1,9 @@ +# Private browsing theme + +## What it does + +An example using the theme API to apply a different theme on private windows. + +## What it shows + +How to use the windowId argument of browser.theme.reset() and browser.theme.update(). diff --git a/private-browsing-theme/background.js b/private-browsing-theme/background.js new file mode 100644 index 0000000..b229b5e --- /dev/null +++ b/private-browsing-theme/background.js @@ -0,0 +1,25 @@ +browser.windows.onCreated.addListener(themeWindow); + +// Theme all currently open windows +browser.windows.getAll().then(wins => wins.forEach(themeWindow)); + +function themeWindow(window) { + // Check if the window is in private browsing + if (window.incognito) { + browser.theme.update(window.id, { + images: { + headerURL: "", + }, + colors: { + accentcolor: "black", + textcolor: "white", + toolbar: "#333", + toolbar_text: "white" + } + }); + } + // Reset to the default theme otherwise + else { + browser.theme.reset(window.id); + } +} diff --git a/private-browsing-theme/manifest.json b/private-browsing-theme/manifest.json new file mode 100644 index 0000000..f83589a --- /dev/null +++ b/private-browsing-theme/manifest.json @@ -0,0 +1,16 @@ +{ + "manifest_version": 2, + "name": "Private browsing theme", + "version": "2.0", + "description": "Extension that sets a dark theme for private windows", + "background": { + "scripts": ["background.js"] + }, + "permissions": ["theme"], + "applications": { + "gecko": { + "id": "private-window-theme@mozilla.org", + "strict_min_version": "57.0b14" + } + } +}