mirror of
https://github.com/lawrencehook/remove-youtube-suggestions.git
synced 2026-07-25 06:54:31 +00:00
Fix bug in header settings
This commit is contained in:
@@ -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
@@ -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
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user