From 1ecaebc51ad82ae7f147aa3599dd2453db69fd6b Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 22 Aug 2017 13:28:16 +0300 Subject: [PATCH] manage: use actual prefs while loading page --- manage/manage.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/manage/manage.js b/manage/manage.js index cd7bffca..573ac3e4 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -19,6 +19,7 @@ const newUI = { }, }; newUI.renderClass(); +usePrefsDuringPageLoad(); const TARGET_TYPES = ['domains', 'urls', 'urlPrefixes', 'regexps']; const GET_FAVICON_URL = 'https://www.google.com/s2/favicons?domain='; @@ -502,3 +503,24 @@ function switchUI({styleOnly} = {}) { function rememberScrollPosition() { history.replaceState({scrollY: window.scrollY}, document.title); } + + +function usePrefsDuringPageLoad() { + const observer = new MutationObserver(mutations => { + for (const mutation of mutations) { + for (const node of mutation.addedNodes) { + // [naively] assuming each element of addedNodes is a childless element + const prefValue = node.id ? prefs.readOnlyValues[node.id] : undefined; + if (prefValue !== undefined) { + if (node.type === 'checkbox') { + node.checked = prefValue; + } else { + node.value = prefValue; + } + } + } + } + }); + observer.observe(document, {subtree: true, childList: true}); + onDOMready().then(() => observer.disconnect()); +}