From b1b600d2136eb86002cd0174babba99fceb0afa9 Mon Sep 17 00:00:00 2001 From: jason lim <50891910+Sxxov@users.noreply.github.com> Date: Sun, 3 Oct 2021 05:44:20 +0800 Subject: [PATCH] Check if `#board` is loaded before syncing class --- js/init.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/js/init.js b/js/init.js index 7fca961..2368075 100644 --- a/js/init.js +++ b/js/init.js @@ -6,9 +6,18 @@ function constructStorageKey() { function syncState() { let storageKey = constructStorageKey(); - chrome.storage.sync.get(storageKey, function(result) { + chrome.storage.sync.get(storageKey, function onChromeStorageSyncResult(result) { let board = document.getElementById('board'); + if (board === null) { + window.addEventListener( + 'domcontentloaded', + onChromeStorageSyncResult.bind(this, result) + ); + + return; + } + if (result[storageKey]) { board.classList.add(result[storageKey]); }