Fix bug in header settings

This commit is contained in:
Lawrence Hook
2022-08-24 17:11:50 -04:00
parent e81bf72867
commit 31fc4ac0c6
3 changed files with 13 additions and 9 deletions
+7 -3
View File
@@ -207,7 +207,7 @@ const FIELDSETS = [
}
];
const HEADER_SETTINGS = {
const DEFAULT_HEADER_SETTINGS = {
global_enable: true,
dark_mode: false
};
@@ -215,7 +215,7 @@ const HEADER_SETTINGS = {
const DEFAULT_SETTINGS = FIELDSETS.reduce((acc, fieldset) => {
fieldset.options.forEach(option => acc[option.id] = option.defaultValue);
return acc;
}, { ...HEADER_SETTINGS });
}, { ...DEFAULT_HEADER_SETTINGS });
// Respond to requests
browser.runtime.onMessage.addListener((data, sender) => {
@@ -237,8 +237,12 @@ browser.runtime.onMessage.addListener((data, sender) => {
const { frameId, tab } = sender;
browser.storage.local.get(localSettings => {
const settings = { ...DEFAULT_SETTINGS, ...localSettings };
const headerSettings = Object.entries(DEFAULT_HEADER_SETTINGS).reduce((acc, [id, value]) => {
acc[id] = id in localSettings ? localSettings[id] : value;
return acc;
}, {});
if (tab) browser.tabs.sendMessage(tab.id, { FIELDSETS, settings }, { frameId });
if (!tab) browser.runtime.sendMessage({ FIELDSETS, HEADER_SETTINGS, settings });
if (!tab) browser.runtime.sendMessage({ FIELDSETS, headerSettings, settings });
});
}
+5 -5
View File
@@ -18,11 +18,11 @@ document.addEventListener("DOMContentLoaded", () => {
// Receive messages
browser.runtime.onMessage.addListener((data, sender) => {
try {
const { FIELDSETS, HEADER_SETTINGS, settings } = data;
const { FIELDSETS, headerSettings, settings } = data;
// Initial page load.
if (FIELDSETS) {
populateOptions(FIELDSETS, HEADER_SETTINGS, settings);
populateOptions(FIELDSETS, headerSettings, settings);
HTML.setAttribute('loaded', true);
}
@@ -34,7 +34,7 @@ browser.runtime.onMessage.addListener((data, sender) => {
});
function populateOptions(FIELDSETS, HEADER_SETTINGS, SETTING_VALUES) {
function populateOptions(FIELDSETS, headerSettings, SETTING_VALUES) {
// Clear the options list
OPTIONS_LIST.innerHTML = '';
@@ -83,8 +83,8 @@ function populateOptions(FIELDSETS, HEADER_SETTINGS, SETTING_VALUES) {
OPTIONS_LIST.append(fieldset);
});
if (HEADER_SETTINGS) {
Object.entries(HEADER_SETTINGS).forEach(([ id, value ]) => {
if (headerSettings) {
Object.entries(headerSettings).forEach(([ id, value ]) => {
updateSetting(id, value);
const svg = document.querySelector(`div#${id} svg`);
+1 -1
View File
@@ -3,7 +3,7 @@
"description": "Spend less time on YouTube. Customize YouTube's user interface to be less engaging.",
"homepage_url": "https://github.com/lawrencehook/remove-youtube-suggestions",
"manifest_version": 2,
"version": "4.3.1",
"version": "4.3.2",
"icons": {
"16": "images/16.png",