In BreezeWiki, append bw-redirect query param to Fandom links

pull/416/head
Kevin Payravi 2024-01-04 03:12:31 -06:00
parent 5fb980f4da
commit 0131ebcd2c
2 changed files with 17 additions and 8 deletions

View File

@ -70,7 +70,7 @@ chrome.runtime.onInstalled.addListener(async (detail) => {
} }
chrome.storage.sync.set({ 'defaultSearchAction': defaultSearchAction }); chrome.storage.sync.set({ 'defaultSearchAction': defaultSearchAction });
} }
// Remove old objects: // Remove old objects:
chrome.storage.sync.remove('defaultActionSettings'); chrome.storage.sync.remove('defaultActionSettings');
chrome.storage.sync.remove('defaultSearchFilterSettings'); chrome.storage.sync.remove('defaultSearchFilterSettings');
@ -80,7 +80,7 @@ chrome.runtime.onInstalled.addListener(async (detail) => {
let siteSettings = storage.siteSettings || {}; let siteSettings = storage.siteSettings || {};
let searchEngineSettings = storage.searchEngineSettings || {}; let searchEngineSettings = storage.searchEngineSettings || {};
let wikiSettings = storage.wikiSettings || {}; let wikiSettings = storage.wikiSettings || {};
sites.forEach((site) => { sites.forEach((site) => {
if (!searchEngineSettings[site.id]) { if (!searchEngineSettings[site.id]) {
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) { if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
@ -93,18 +93,18 @@ chrome.runtime.onInstalled.addListener(async (detail) => {
searchEngineSettings[site.id] = defaultSearchAction; searchEngineSettings[site.id] = defaultSearchAction;
} }
} }
if (!wikiSettings[site.id]) { if (!wikiSettings[site.id]) {
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction; wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
} }
}); });
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings }); chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
chrome.storage.sync.set({ 'wikiSettings': wikiSettings }); chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
// Remove old object: // Remove old object:
chrome.storage.sync.remove('siteSettings'); chrome.storage.sync.remove('siteSettings');
// Mark v3 migration as complete: // Mark v3 migration as complete:
chrome.storage.sync.set({ 'v3migration': 'done' }); chrome.storage.sync.set({ 'v3migration': 'done' });
} }
@ -160,7 +160,7 @@ function redirectToBreezeWiki(storage, tabId, url) {
} }
} }
if (url.includes('fandom.com/wiki/')) { if (url.includes('fandom.com/wiki/') && !url.includes('bw-redirect=no')) {
if (!(storage.breezewikiHost ?? null)) { if (!(storage.breezewikiHost ?? null)) {
fetch('https://bw.getindie.wiki/instances.json') fetch('https://bw.getindie.wiki/instances.json')
.then((response) => { .then((response) => {
@ -293,7 +293,7 @@ async function main(url, tabId) {
if (article === site['origin_main_page']) { if (article === site['origin_main_page']) {
article = site['destination_main_page']; article = site['destination_main_page'];
} }
// Replace underscores with spaces as that performs better in search // Replace underscores with spaces as that performs better in search
article = article.replaceAll('_', ' '); article = article.replaceAll('_', ' ');

View File

@ -4,4 +4,13 @@ bwTopBanners.forEach((banner) => {
if (banner.innerText.includes('affiliated browser extension')) { if (banner.innerText.includes('affiliated browser extension')) {
banner.style.display = 'none'; banner.style.display = 'none';
} }
});
// Append bw-redirect query param to Fandom links
// This allows users to click a Fandom link without being redirected back to BW
const bwFandomLinks = document.querySelectorAll('a[href*=".fandom.com"]');
bwFandomLinks.forEach((link) => {
const url = new URL(link);
url.searchParams.append('bw-redirect', 'no');
link.href = url;
}); });