diff --git a/background.js b/background.js index 737c13c..daab31b 100644 --- a/background.js +++ b/background.js @@ -30,7 +30,7 @@ function redirectToBreezeWiki(storage, eventInfo, url) { const subdomain = url.hostname.split(".")[0]; const article = url.href.split('fandom.com/wiki/')[1]; if (article) { - chrome.tabs.update(eventInfo.tabId, { url: host + '/' + subdomain + '/search?q=' + article }); + chrome.tabs.update(eventInfo.tabId, { url: host + '/' + subdomain + '/wiki/' + article }); } else { chrome.tabs.update(eventInfo.tabId, { url: host + '/' + subdomain }); } @@ -51,11 +51,17 @@ function redirectToBreezeWiki(storage, eventInfo, url) { if (url.href.includes('fandom.com/wiki/')) { if (!(storage.breezewikiHost ?? null)) { - fetch('http://bw.getindie.wiki/instances.json') + fetch('https://bw.getindie.wiki/instances.json') .then((response) => response.json()) .then((breezewikiHosts) => { - const host = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance; - chrome.storage.sync.set({ 'breezewikiHost': host }); + // Check if BreezeWiki's main site is available + let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com'); + if (breezewikiMain.length > 0) { + chrome.storage.sync.set({ 'breezewikiHost': breezewikiMain[0].instance }); + } else { + // If BreezeWiki.com is not available, set to a random mirror + chrome.storage.sync.set({ 'breezewikiHost': breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance }); + } chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts }); chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() }); processRedirect(host); diff --git a/manifest2.json b/manifest2.json index d5d034f..1bb9f61 100644 --- a/manifest2.json +++ b/manifest2.json @@ -1,6 +1,6 @@ { "name": "Indie Wiki Buddy", - "version": "1.0.2", + "version": "1.0.3", "description": "Helping you discover quality independent wikis through alerts, redirects, and search filtering", "permissions": [ "storage", diff --git a/manifest3.json b/manifest3.json index afe1340..fa3c484 100644 --- a/manifest3.json +++ b/manifest3.json @@ -1,6 +1,6 @@ { "name": "Indie Wiki Buddy", - "version": "1.0.2", + "version": "1.0.3", "description": "Helping you discover quality independent wikis through alerts, redirects, and search filtering", "permissions": [ "storage", diff --git a/popup.js b/popup.js index bbb27b4..d160f69 100644 --- a/popup.js +++ b/popup.js @@ -55,12 +55,19 @@ async function loadOptions(lang) { // Fetch and cache list of BreezeWiki hosts if first time, // or if it has been 24 hrs since last refresh if (!host || !hostOptions || !hostFetchTimestamp || (Date.now() - 86400000 > hostFetchTimestamp)) { - fetch('http://bw.getindie.wiki/instances.json') + fetch('https://bw.getindie.wiki/instances.json') .then((response) => response.json()) .then((breezewikiHosts) => { // If host isn't set, or currently selected host is no longer available, select random host: if (!host || !breezewikiHosts.some(item => item.instance === host)) { - host = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance; + // Check if BreezeWiki's main site is available + let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com'); + if (breezewikiMain.length > 0) { + host = breezewikiMain[0].instance; + } else { + // If BreezeWiki.com is not available, set to a random mirror + host = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance; + } } // Populate dropdown selection of hosts const breezewikiHostSelect = document.getElementById('breezewikiHostSelect'); @@ -333,10 +340,17 @@ function setBreezeWiki(setting) { breezewikiHost.style.display = 'block'; chrome.storage.sync.get({ 'breezewikiHost': null }, function (host) { if (!host.breezewikiHost) { - fetch('http://bw.getindie.wiki/instances.json') + fetch('https://bw.getindie.wiki/instances.json') .then((response) => response.json()) .then((breezewikiHosts) => { - host.breezewikiHost = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance; + // Check if BreezeWiki's main site is available + let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com'); + if (breezewikiMain.length > 0) { + host.breezewikiHost = breezewikiMain[0].instance; + } else { + // If BreezeWiki.com is not available, set to a random mirror + host.breezewikiHost = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance; + } chrome.storage.sync.set({ 'breezewikiHost': host.breezewikiHost }); chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts }); chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });