From 6519d31d52a946d65bc17257b80d52c45295e6c0 Mon Sep 17 00:00:00 2001 From: Kevin Payravi Date: Sun, 7 Jan 2024 04:18:55 -0600 Subject: [PATCH] Removing content prefix from main page redirects --- background.js | 4 ++-- content-banners.js | 4 ++-- content-search-filtering.js | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/background.js b/background.js index 10a3760..69f4b78 100644 --- a/background.js +++ b/background.js @@ -286,7 +286,7 @@ async function main(url, tabId) { // We can't just take the last part of the path due to subpages; // Instead, we take everything after the wiki's base URL + content path let originArticle = decodeURIComponent(url.split(site['origin_base_url'] + site['origin_content_path'])[1] || ''); - let destinationArticle = originArticle; + let destinationArticle = site['destination_content_prefix'] + originArticle; // Set up URL to redirect user to based on wiki platform let newURL = ''; if (originArticle) { @@ -307,7 +307,7 @@ async function main(url, tabId) { let searchParams = ''; switch (site['destination_platform']) { case 'mediawiki': - searchParams = '?search=' + site['destination_content_prefix'] + destinationArticle; + searchParams = '?search=' + destinationArticle; break; case 'doku': searchParams = 'start?do=search&q=' + destinationArticle; diff --git a/content-banners.js b/content-banners.js index 5d97fee..dd48432 100644 --- a/content-banners.js +++ b/content-banners.js @@ -411,7 +411,7 @@ function main() { // We can't just take the last part of the path due to subpages; // Instead, we take everything after the wiki's base URL + content path: let originArticle = decodeURIComponent(String(origin).split(site['origin_base_url'] + site['origin_content_path'])[1] || ''); - let destinationArticle = originArticle; + let destinationArticle = site['destination_content_prefix'] + originArticle; // Set up URL to redirect user to based on wiki platform: let newURL = ''; if (originArticle) { @@ -432,7 +432,7 @@ function main() { let searchParams = ''; switch (site['destination_platform']) { case 'mediawiki': - searchParams = '?search=' + site['destination_content_prefix'] + destinationArticle; + searchParams = '?search=' + destinationArticle; break; case 'doku': searchParams = 'start?do=search&q=' + destinationArticle; diff --git a/content-search-filtering.js b/content-search-filtering.js index bfa5ae7..d823f90 100644 --- a/content-search-filtering.js +++ b/content-search-filtering.js @@ -196,7 +196,7 @@ function escapeRegex(string) { function replaceSearchResults(searchResultContainer, site, link) { // Build new URL: let originArticle = decodeURIComponent((link.split(site['origin_base_url'] + site['origin_content_path'])[1] || '').split('#')[0].split('?')[0].split('&')[0]); - let destinationArticle = originArticle; + let destinationArticle = site['destination_content_prefix'] + originArticle; let newURL = ''; if (originArticle) { // Check if main page @@ -216,7 +216,7 @@ function replaceSearchResults(searchResultContainer, site, link) { let searchParams = ''; switch (site['destination_platform']) { case 'mediawiki': - searchParams = '?search=' + site['destination_content_prefix'] + destinationArticle; + searchParams = '?search=' + destinationArticle; break; case 'doku': searchParams = 'start?do=search&q=' + destinationArticle; @@ -248,10 +248,11 @@ function replaceSearchResults(searchResultContainer, site, link) { indieResultFaviconContainer.append(indieResultFavicon); let indieResultText = document.createElement('span'); if (originArticle && originArticle !== site['origin_main_page']) { + destinationArticleTitle = destinationArticle.replace(site['destination_content_prefix'], '').replaceAll('_', ' '); if (site['lang'] === 'EN' && link.match(/fandom\.com\/[a-z]{2}\/wiki\//)) { - indieResultText.innerText = 'Look up "' + decodeURIComponent(decodeURIComponent(destinationArticle.replaceAll('_', ' '))) + '" on ' + site.destination + ' (EN)'; + indieResultText.innerText = 'Look up "' + decodeURIComponent(decodeURIComponent(destinationArticleTitle)) + '" on ' + site.destination + ' (EN)'; } else { - indieResultText.innerText = 'Look up "' + decodeURIComponent(decodeURIComponent(destinationArticle.replaceAll('_', ' '))) + '" on ' + site.destination; + indieResultText.innerText = 'Look up "' + decodeURIComponent(decodeURIComponent(destinationArticleTitle)) + '" on ' + site.destination; } } else { if (site['lang'] === 'EN' && link.match(/fandom\.com\/[a-z]{2}\/wiki\//)) {