Waiting for head to load before inserting banner

pull/227/head
Kevin Payravi 2023-07-17 00:17:50 -05:00
parent aaefcbd468
commit 221b18621c
1 changed files with 17 additions and 7 deletions

View File

@ -331,7 +331,7 @@ function main(mutations = null, observer = null) {
} }
chrome.storage.local.get(function (localStorage) { chrome.storage.local.get(function (localStorage) {
chrome.storage.sync.get(function (syncStorage) { chrome.storage.sync.get(function (syncStorage) {
const storage = {...syncStorage, ...localStorage}; const storage = { ...syncStorage, ...localStorage };
// Check if extension is on: // Check if extension is on:
if ((storage.power ?? 'on') === 'on') { if ((storage.power ?? 'on') === 'on') {
// Check if on Fandom, Fextralife, or BreezeWiki // Check if on Fandom, Fextralife, or BreezeWiki
@ -394,8 +394,18 @@ function main(mutations = null, observer = null) {
} else { } else {
newURL = 'https://' + site["destination_base_url"]; newURL = 'https://' + site["destination_base_url"];
} }
// Notify that another wiki is available // When head elem is loaded, notify that another wiki is available
const docObserver = new MutationObserver(function (mutations, mutationInstance) {
const headElement = document.querySelector('head');
if (headElement) {
displayRedirectBanner(newURL, site['id'], site['destination'], storage); displayRedirectBanner(newURL, site['id'], site['destination'], storage);
mutationInstance.disconnect();
}
});
docObserver.observe(document, {
childList: true,
subtree: true
});
} }
} }
} }