Skip to content

Commit 9302ed4

Browse files
Firefox: Mixed Mode Themed Favicon Issue (#72)
* initial commit * This is the base functionality of Doki Theme. * Search functionality is now operable in new custom tab page; Removes settings and logo icons from new custom tab page; Decreases the size of doki logo in popup; Updates Dark Ishtar theme; Updates manifest; Live updating when selecting a new waifu; Adds documentation; Removes debugs; * New custom tab pages are now called 'Waifu Tab'; Waifus are now loaded to a Waifu Tab using JS instead of CSS. This is more convenient than making a CSS for each waifu; Adds a new background script, resources.js. This script points to theme resources & provides utility functions for the other background script. It also provides an easier way to activate a theme without using a switch statement; All of Firefox's New Tabs are replaced with a Waifu Tab. Refactors code for more readability; Adds more documentation comments for new classes & functions; * Completes Aqua & Ishtar themes * Adds more waifu themes to complete; 10 waifus can now be set as background * Adds 5 more Waifu themes * Adds 13 more waifu themes;Adds a permissions file, which explains the purpose of each permission needed to use the extension * Change location of files * Update Readme with Firefox section * relocate files * update readme * New permission needed: Storage; Storage is used to add all waifu choices in the popup menu dynamically with less boilerplate; Refactor code;Update permissions * Merges firefox branch; Updates CHANGELOG * Update manifest * Update manifest * Can now choose a theme at random; Increase tab text brightness for megumin theme; * Refactors code making great use of the local storage api. Instead of making a custom new tab HTML page for each theme, doki theme now reuses one HTML page to load all themes; It is also easier to add more doki themes to the current collection; Permissions file is updated with more clarification on the Storage section; Updates manifest; * Kanna's sidebar now has a theme applied to it * Update permission of firefox branch with master * Update manifest * Removes XML declaration; * Removes merge files outside of firefox folder * The popup menu now remembers the last waifu that was set. * Makes popup menu smaller; Doki Theme now takes advantage of chrome_url_overrides manifest key to land on the custom New Tab. Initially, Doki Theme had its own method for transitioning which involved forcing the browser to show the new custom tab page if any of these tabs are present: about:newtab, about:privatebrowsing, or about:home; Adds chrome_url_overrides & chrome_settings_overrides keys to manifest; Removes unnecessary background script; Adds two more themes for Monika: light/dark Monika joy variant; Update names & file paths for Natsuki & Monika images; Enhance tab_text & tab_background_text colors for some themes; Remembers the last waifu theme chosen; Updates PERMISSIONS.md file; * Removes extra themes;Removes image key from all theme json * Makes branch on par with master * Adds other Monika & Natsuki images; New feature 'mixed' loads a new theme per new tab created; Adds some Documentation; Updates DokiThemeDefinitions for Firefox; * merge with doki-theme-chrome repo * Adds asynchronous programming to reduce load times; * Adds high res icons * Update manifest to proper version formatting * merge from master * Removes unneeded async keywords * update firefox build template by removing unnecessary theme_frame key * Removes theme_frame key from new themes; * When mix mode is activated all new tabs except the last are closed before initialization;Adds comments * Removes empty spaces from themes; In mix mode, tab theme info is now storage in local storage instead of temp variable; Fix Popup menu not changing colors with the theme; * Actually fix popup menu changing to the correct background color * Fixes the popup menu only changing colors on New Tab pages * Fixes popup menu color change for non-new tab pages * Update versioning; Update Changelog * Adds bounce animation to doki icon * update Changelogs;Adds back .editorconfig file * actually adds .editorconfig file * Adds hover animation to popup menu;Fixes popup menu color change when chosen a theme normally without any modes; * Cleans up mix mode * Styling popup header font color. * - Removes extra *Rias* folder. - Changes order of switches - Reduces size of switches - Adds border-radius to dropdown menu - Changes animation from bouncing to heartbeat * yarn.lock * Brighten switch titles * Update Changelog * Update manifest version to 9.0.1 * Themed switch labels * Update Changelog * Add option to activate/disable scrollbar & text selection themes; Update package.json version for firefox; Removes deprecated colors.toolbar_field_separator theme key; Fix 'Random' mode; Add shortcut to options page; Add filters: hue rotation & drop shadow to doki image in popup menu; Refactor some code; * Make doki theme's scrollbar & text selection styles have high priority; Simplify option labels; * Change drop shadow of doki heartbeat to light gray; Fix switches properly disabling for both secondary and dark (functionality); Blurs disabled switches (appearance); Improve performance when switching between theme variants; Adds glow effect to unchecked enabled switches; Code refactoring; * Clean up CONTRIBUTING file * Fixes URL match pattern * Corrects issue number in CHANGELOG; * Fixes Popup menu not changing to appropriate theme color when selected; Reset selection when choosing Random mode; * Update CHANGELOG * Fixes text selection and scrollbar not changing themes when selecting a new theme while on a webpage; * Fixes Random mode not enabling switches properly * Instead of dynamically adding style tag to the <head>, this uses CSS variables to manipulate the styles * Removes toolbar_field_separator from firefox build template; Adds custom checkbox for options page; Tightens search for chosen theme by theme name && group when initializing random mode; Use accentColor instead of caretRow attribute for the caret color; * Update CHANGELOG; Options page now matches the current doki theme; Change checkmark to a heart; Refresh pages based on current activity; * Possible solution to checkmark being out-of-bounds; Remove colons from label representing each checkbox * Appropriate theme(favicon,json,action button,options page & image) for each tab loads correctly when opening tabs really quickly in mixed mode; Fix Tabs not being randomized when opening tabs really quickly in mixed mode; Fix text selection & scrollbar not loading appropriately with their individual tab in mixed mode; Scripts loading the page theme is now more modular; Fix initialization browser if the last option chosen was mix mode; * Update Changlog and versionings * Update changelog * Adds missing `loadTheme` import; Update CHANGELOG.md; * Fix initialization, when user reopens browser; * Error handling for undefined list during mix mode; Removes tab creation listener for mix mode; clean up local mix list when disabled; rename `mixList to `mixedList`; Replace glitchy tab algorithm to utilize the message system approach; `getCurrentTheme` method is now synchronous; * Rename `mixList` to `mixedList`; clean up local mix list; * Fixes search bar widget toggling in *Mixed Mode* reverting all tabs back to using a single theme. Co-authored-by: Alex Simons <alexsimons9999@gmail.com>
1 parent c5dec57 commit 9302ed4

13 files changed

Lines changed: 185 additions & 145 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ Changelog
22
---
33

44
# Unreleased
5+
# 15.0.1 [Firefox: Theming Bug Fixes]
6+
- Fix tabs not being randomized when creating tabs rapidly in mixed mode.
7+
- Fixes text selection & scrollbar not loading appropriately with their individual tab in mixed mode.
8+
- Fixes text selection & scrollbar not loading appropriately with their individual tab in mixed mode.
9+
- Appropriate theme for *options page* for each tab loads correctly in mixed mode.
10+
- Fixes initialization of a theme, when closing and reopening a browser.
11+
- Mitigates favicon & other theming components to stay themed in mixed mode.
12+
- Fixes search bar widget toggling in *Mixed Mode* reverting all tabs back to using a single theme.
513

614
# 15.0.0 [Only for Onii-chan]
715

firefoxThemes/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Doki Theme for Firefox",
33
"short_name": "Doki Theme",
4-
"version": "15.0.0",
4+
"version": "15.0.1",
55
"description": "A theme collection of girls from various anime, manga, and visual novels series.",
66
"manifest_version": 2,
77
"icons": {

firefoxThemes/modules/modes/mix.js

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {getRandomThemeId} from "../utils/random.js";
22
import {loadTheme} from "../utils/themes/browser.js";
3-
3+
/*Global Variables*/
4+
let mixedList = undefined;//Maintain a local list of all mixed tabs
45
/*Separate the New Tab pages from the other types of pages*/
56
function separateTabs(tabs) {
67
let newTabs = [];
@@ -15,7 +16,7 @@ function separateTabs(tabs) {
1516
return [newTabs, otherTabs];
1617
}
1718

18-
/*Add all tabs that are not a new tab into the mix collection*/
19+
/*Add all tabs that are not a new tab into the mix mixedQueue*/
1920
function addOtherTabsToMix(tabs, mixList, themes) {
2021
if (tabs.length > 0) {
2122
for (const tab of tabs) {
@@ -37,65 +38,48 @@ function keepLastTab(tabs) {
3738
return lastTabs;
3839
}
3940

40-
/*EVENT: When a new tab is created add a random theme to it*/
41-
function MixTabCreated(tab) {
42-
if (tab.title === "New Tab") {
43-
browser.storage.local.get("waifuThemes")
44-
.then((storage) => {
45-
const chosenThemeId = getRandomThemeId(storage.waifuThemes.themes);
46-
MixedUpdate(tab, chosenThemeId, storage.waifuThemes.themes);
47-
});
48-
}
49-
}
50-
5141
/*EVENT: Set the theme for the current active tab*/
5242
function MixTabActivated(activeInfo) {
53-
browser.storage.local.get(["waifuThemes", "mixedTabs"])
43+
browser.storage.local.get(["waifuThemes"])
5444
.then((storage) => {
55-
const currentThemeId = storage.mixedTabs.get(activeInfo.tabId);
45+
//Check if mixed mode is still active.
46+
//This check is when searchbar is toggled during mix mode which disables it
47+
if (!mixedList) {
48+
mixTabCleanup();
49+
return;
50+
}
51+
const currentThemeId = mixedList.get(activeInfo.tabId);
5652
if (currentThemeId) {
5753
loadTheme(storage.waifuThemes.themes, currentThemeId);
54+
browser.storage.local.set({currentThemeId});
5855
}
5956
});
6057
}
6158

6259
/*EVENT: When a tab is closed delete the saved data for it*/
6360
function MixTabClosed(tabId) {
64-
browser.storage.local.get()
65-
.then((storage) => {
66-
storage.mixedTabs.delete(tabId);
67-
browser.storage.local.set({mixedTabs: storage.mixedTabs});
68-
});
69-
}
70-
71-
/*Updates the new tab with a new waifu theme*/
72-
function MixedUpdate(tab, themeId, themes) {
73-
browser.storage.local.get(["mixedTabs"])
74-
.then((storage) => {
75-
storage.mixedTabs.set(tab.id, themeId);//Adds the created tab to the list of mixed tabs
76-
browser.storage.local.set({currentThemeId: themeId, mixedTabs: storage.mixedTabs});
77-
//Update the tab with theme
78-
browser.tabs.update(tab.id, {
79-
loadReplace: true,
80-
url: themes[themeId].page
81-
});
82-
//Load browser theme
83-
loadTheme(themes, themeId);
84-
});
61+
//Check if mixed mode is still active.
62+
//This check is when searchbar is toggled during mix mode which disables it
63+
if (!mixedList) {
64+
mixTabCleanup();
65+
return;
66+
}
67+
mixedList.delete(tabId);
68+
browser.storage.local.set({mixedTabs: mixedList});
8569
}
8670

8771
/*Cleans up all things relating to the Mixed tab option*/
8872
function mixTabCleanup() {
8973
browser.storage.local.get("mixedTabs")
9074
.then((storage) => {
9175
//Removes all listeners
92-
if (browser.tabs.onCreated.hasListener(MixTabCreated)) {
93-
browser.tabs.onCreated.removeListener(MixTabCreated);
76+
if (browser.tabs.onCreated.hasListener(MixTabActivated)) {
9477
browser.tabs.onActivated.removeListener(MixTabActivated);
9578
browser.tabs.onRemoved.removeListener(MixTabClosed);
9679
}
9780
if (storage.mixedTabs) {
9881
browser.storage.local.set({mixedTabs: undefined});
82+
mixedList = undefined;
9983
}
10084
});
10185
}
@@ -108,9 +92,9 @@ function setupMixedUpdate(msg) {
10892
.then((storage) => {
10993
if (!storage.mixedTabs) {
11094
storage.mixedTabs = new Map();//Create a new mixed tab list
95+
mixedList = new Map();
11196
}
11297
//Activate event listeners
113-
browser.tabs.onCreated.addListener(MixTabCreated);//When a tab is created
11498
browser.tabs.onActivated.addListener(MixTabActivated);//When the active tab has been switched
11599
browser.tabs.onRemoved.addListener(MixTabClosed);//When a tab has been closed
116100
if (tabs.length > 0) {
@@ -130,11 +114,44 @@ function setupMixedUpdate(msg) {
130114
} else {
131115
browser.storage.local.set({currentThemeId, mixedTabs: storage.mixedTabs});
132116
}
117+
mixedList = storage.mixedTabs;
133118
//Initialize first (and only) new tab with the default theme
134119
loadTheme(themes, currentThemeId);
135120
}
136121
});
137122
});
138123
}
139124

140-
export {setupMixedUpdate, mixTabCleanup};
125+
/*MESSAGE: Send a message to the page to apply theme*/
126+
function pageResponse(msg) {
127+
if (!msg.mixMSG) return;
128+
browser.storage.local.get(["currentThemeId", "waifuThemes", "backgroundType", "showWidget"]).then(storage => {
129+
if (!mixedList) {
130+
browser.tabs.sendMessage(msg.pageTab.id, {
131+
pageMSG: true,
132+
waifuThemes: storage.waifuThemes,
133+
currentThemeId: storage.currentThemeId,
134+
backgroundType: storage.backgroundType,
135+
showWidget: storage.showWidget,
136+
});
137+
} else {
138+
if (!mixedList.has(msg.pageTab.id)) {
139+
mixedList.set(msg.pageTab.id, getRandomThemeId(storage.waifuThemes.themes));
140+
browser.storage.local.set({mixedTabs: mixedList});
141+
}
142+
browser.tabs.sendMessage(msg.pageTab.id, {
143+
pageMSG: true,
144+
waifuThemes: storage.waifuThemes,
145+
currentThemeId: storage.currentThemeId,
146+
backgroundType: storage.backgroundType,
147+
showWidget: storage.showWidget,
148+
mixedTabs: mixedList,
149+
pageTab: msg.pageTab
150+
});
151+
loadTheme(storage.waifuThemes.themes, mixedList.get(msg.pageTab.id));
152+
}
153+
});
154+
}
155+
156+
export {setupMixedUpdate, mixTabCleanup};
157+
browser.runtime.onMessage.addListener(pageResponse);

firefoxThemes/modules/utils/themes/browser.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@ async function loadTheme(themes, themeId) {
1010
const themeJSON = await res.json();
1111
browser.theme.update(themeJSON);
1212
}
13+
/*Retrieve the appropriate theme*/
14+
function getCurrentTheme(themes,themeId,mixedTabs,tab){
15+
if(mixedTabs){
16+
themeId = mixedTabs.get(tab.id);
17+
browser.storage.local.set({currentThemeId:themeId});
18+
}
19+
return themes[themeId];
20+
}
1321

14-
export {loadTheme};
22+
export {loadTheme,getCurrentTheme};

firefoxThemes/options/options.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ function setCss(chosenTheme) {
1414
root.style.setProperty('--checkmark-color',colors.classNameColor);
1515
}
1616

17-
function initContent() {
18-
browser.storage.local.get(['loadOnStart', 'textSelection', 'scrollbar', 'waifuThemes', 'currentThemeId'])
19-
.then((storage) => {
20-
initCheckbox(loadOnStartCheckbox,!!storage.loadOnStart);
21-
initCheckbox(textSelectionCheckbox,!!storage.textSelection);
22-
initCheckbox(scrollbarCheckbox,!!storage.scrollbar);
23-
setCss(storage.waifuThemes.themes[storage.currentThemeId])
24-
});
17+
async function initContent() {
18+
const storage = await browser.storage.local.get(['loadOnStart', 'textSelection', 'scrollbar', 'waifuThemes', 'currentThemeId','mixedTabs'])
19+
initCheckbox(loadOnStartCheckbox,!!storage.loadOnStart);
20+
initCheckbox(textSelectionCheckbox,!!storage.textSelection);
21+
initCheckbox(scrollbarCheckbox,!!storage.scrollbar);
22+
let themeId = storage.currentThemeId;
23+
if(storage.mixedTabs){
24+
const tab = await browser.tabs.getCurrent();
25+
themeId = storage.mixedTabs.get(tab.id);
26+
}
27+
setCss(storage.waifuThemes.themes[themeId]);
2528
}
2629

2730
const onChangeCheckEvents = async (e) => {
2831
changeCheckboxState(e);
2932
await browser.runtime.sendMessage({
33+
resourceMSG:true,
3034
optionName: e.target.id,
3135
optionValue: e.target.className
3236
});

firefoxThemes/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "doki-theme-firefox",
3-
"version": "15.0.0",
3+
"version": "15.0.1",
44
"description": "A theme collection of girls from various anime, manga, and visual novels series.",
55
"main": "index.js",
66
"repository": "https://github.com/doki-theme/doki-theme-web",

firefoxThemes/popup/popup.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ const setBackground = async () => {
3636
});
3737

3838
const {currentThemeId} = await browser.storage.local.get(["currentThemeId"])
39-
browser.runtime.sendMessage({currentThemeId});
39+
browser.runtime.sendMessage({resourceMSG:true,currentThemeId});
4040
}
4141

4242
const setHideWidget = async () => {
4343
await browser.storage.local.set({
4444
showWidget: showSearchSwitch.checked
4545
});
4646

47-
const {currentThemeId} = await browser.storage.local.get(["currentThemeId"])
48-
browser.runtime.sendMessage({currentThemeId});
47+
browser.runtime.sendMessage({resourceMSG:true,applyWidget:true});
4948
}
5049

5150
/*Stores info to set dark mode switch accordingly*/
@@ -81,7 +80,7 @@ const setOpposingTheme = async () => {
8180
const newThemeId = newTheme.id;
8281
setCSS(newTheme);
8382
await browser.storage.local.set({currentThemeId: newThemeId});
84-
browser.runtime.sendMessage({currentThemeId: newThemeId});
83+
browser.runtime.sendMessage({resourceMSG:true,currentThemeId: newThemeId});
8584
}
8685
}
8786

@@ -151,7 +150,7 @@ function setTheme(e) {
151150
setCSS(themes[chosenThemeId]);
152151
selectTag.value = 'none';// Reset option back to 'choose a waifu'
153152
}
154-
browser.runtime.sendMessage({currentThemeId: chosenThemeId, mixState: currentMix});
153+
browser.runtime.sendMessage({resourceMSG:true,currentThemeId: chosenThemeId, mixState: currentMix});
155154
});
156155
}
157156

firefoxThemes/resources.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {mixedStates} from "./modules/utils/states.js";
33
import {setupMixedUpdate, mixTabCleanup} from "./modules/modes/mix.js";
44
import {normalUpdate} from "./modules/modes/normal.js";
55
import {updateOptions} from "./modules/contentConfig.js";
6-
6+
import {getRandomThemeId} from "./modules/utils/random.js";
7+
import {reloadTabs} from "./modules/utils/browser.js";
78
/*---CLASSES---*/
89

910
/*Class Goal: Holds theme data about all waifus*/
@@ -40,26 +41,28 @@ class Theme {
4041
}
4142

4243
/*Initialize Local Storage & custom new tab page*/
43-
function startStorage() {
44-
browser.storage.local.get(["currentThemeId", "loadOnStart", "textSelection", "scrollbar"])
45-
.then((storage) => {
46-
const initStorage = {
47-
waifuThemes: new WaifuThemes(),
48-
};
49-
//Retrieve all themes if none exists in local storage
50-
browser.storage.local.set(initStorage);
51-
//Load browser theme
52-
if (storage.currentThemeId) {
53-
loadTheme(initStorage.waifuThemes.themes, storage.currentThemeId);
54-
}
55-
if (storage.loadOnStart) {
56-
//When the browser first opens, redirect to custom new tab page
57-
browser.tabs.update({loadReplace: true, url: "waifus/index.html"});
58-
}
59-
// Register all styles from option page
60-
updateOptions({optionName: "textSelection", optionValue: !!!storage.textSelection});
61-
updateOptions({optionName: "scrollbar", optionValue: !!!storage.scrollbar});
62-
});
44+
async function startStorage() {
45+
const storage = await browser.storage.local.get(["currentThemeId", "loadOnStart", "textSelection", "scrollbar", "mixedTabs"]);
46+
const initStorage = {
47+
waifuThemes: new WaifuThemes(),
48+
};
49+
//Retrieve all themes if none exists in local storage
50+
browser.storage.local.set(initStorage);
51+
//Load browser theme
52+
if (storage.mixedTabs) {
53+
let themeId = storage.currentThemeId || getRandomThemeId(initStorage.waifuThemes.themes);
54+
updateTabs({mixState: mixedStates.RESET, currentThemeId: themeId});
55+
} else if (storage.currentThemeId) {
56+
let themeId = storage.currentThemeId || getRandomThemeId(initStorage.waifuThemes.themes);
57+
updateTabs({currentThemeId: themeId});
58+
}
59+
if (storage.loadOnStart) {
60+
//When the browser first opens, redirect to custom new tab page
61+
browser.tabs.update({loadReplace: true, url: "waifus/index.html"});
62+
}
63+
// Register all styles from option page
64+
updateOptions({optionName: "textSelection", optionValue: !!!storage.textSelection});
65+
updateOptions({optionName: "scrollbar", optionValue: !!!storage.scrollbar});
6366
}
6467

6568
/*Update all new tabs with new waifu theme*/
@@ -79,15 +82,19 @@ function updateTabs(msg) {
7982
}
8083
}
8184

82-
/*Update all theme components*/
85+
/*MESSAGE: Update all theme components*/
8386
function updateTheme(msg) {
84-
if (!msg.optionName) {
87+
if (!msg.resourceMSG) return;
88+
89+
if (msg.applyWidget) {
90+
reloadTabs({title: 'New Tab'});
91+
} else if (msg.optionName && msg.optionValue) {
92+
updateOptions(msg);
93+
} else {
8594
updateTabs(msg);
8695
for (const optionName of ['textSelection', 'scrollbar']) {
8796
updateOptions({optionName});
8897
}
89-
} else {
90-
updateOptions(msg);
9198
}
9299
}
93100

firefoxThemes/waifus/faviconLoader.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)