Fix location detection for Chrome + error handling

pull/367/head
Kevin Payravi 2023-11-18 02:39:04 -05:00
parent b8fb3a1d03
commit d439a6f3f2
1 changed files with 6 additions and 3 deletions

View File

@ -184,7 +184,7 @@ function displayRedirectBanner(origin, newUrl, id, destinationName, destinationL
var bannerText = document.createElement('span');
bannerText.classList.add('indie-wiki-banner-big-text');
banner.appendChild(bannerText);
if (destinationLanguage === 'EN' && origin.href.match(/fandom\.com\/[a-z]{2}\/wiki\//)) {
if (destinationLanguage === 'EN' && location.href.match(/fandom\.com\/[a-z]{2}\/wiki\//)) {
bannerText.textContent = 'There is an independent wiki covering this topic in English!';
} else {
bannerText.textContent = 'There is an independent wiki covering this topic!';
@ -295,8 +295,11 @@ function main() {
const docObserver = new MutationObserver(function (mutations, mutationInstance) {
const headElement = document.querySelector('head');
if (headElement) {
displayRedirectBanner(origin, newURL, site['id'], site['destination'], site['lang'], storage);
mutationInstance.disconnect();
try {
displayRedirectBanner(origin, newURL, site['id'], site['destination'], site['lang'], storage);
} finally {
mutationInstance.disconnect();
}
}
});
docObserver.observe(document, {