Removing query params for article name detection

pull/400/merge
Kevin Payravi 2024-01-07 05:14:10 -06:00
parent a7626e014d
commit d30b8434de
3 changed files with 22 additions and 8 deletions

View File

@ -280,6 +280,12 @@ async function main(url, tabId) {
let settings = storage.wikiSettings || {}; let settings = storage.wikiSettings || {};
let id = site['id']; let id = site['id'];
let siteSetting = settings[id] || storage.defaultWikiAction || 'alert'; let siteSetting = settings[id] || storage.defaultWikiAction || 'alert';
// Remove query paramters
let urlObj = new URL(url);
urlObj.search = '';
url = String(decodeURIComponent(urlObj.toString()));
// Check if redirects are enabled for the site // Check if redirects are enabled for the site
if (siteSetting === 'redirect') { if (siteSetting === 'redirect') {
// Get article name from the end of the URL; // Get article name from the end of the URL;

View File

@ -365,27 +365,31 @@ function main() {
if (currentURL.pathname.length > 1) { if (currentURL.pathname.length > 1) {
processBreezeWikiBanner(storage); processBreezeWikiBanner(storage);
let origin = currentURL; let origin = currentURL.toString();
// If on a BreezeWiki site, convert to Fandom link to match with our list of wikis: // If on a BreezeWiki site, convert to Fandom link to match with our list of wikis:
if (currentURL.hostname.match(breezewikiRegex) || (storage.breezewikiHost === 'CUSTOM' && storage.breezewikiCustomHost?.includes(currentURL.hostname))) { if (currentURL.hostname.match(breezewikiRegex) || (storage.breezewikiHost === 'CUSTOM' && storage.breezewikiCustomHost?.includes(currentURL.hostname))) {
origin = String(currentURL.pathname).split('/')[1] + '.fandom.com/wiki/'; origin = String(currentURL.pathname).split('/')[1] + '.fandom.com/wiki/';
if (currentURL.search.includes('?q=')) { if (currentURL.search.includes('?q=')) {
origin = origin + currentURL.search.substring(3).split('&')[0]; origin = 'https://' + origin + currentURL.search.substring(3).split('&')[0];
} else { } else {
origin = origin + currentURL.pathname.split('/')[3]; origin = 'https://' + origin + currentURL.pathname.split('/')[3];
} }
} }
// Remove query paramters
let urlObj = new URL(origin);
urlObj.search = '';
origin = String(decodeURIComponent(urlObj.toString()));
getData().then(sites => { getData().then(sites => {
let crossLanguageSetting = storage.crossLanguage || 'off'; let crossLanguageSetting = storage.crossLanguage || 'off';
// Check if site is in our list of wikis: // Check if site is in our list of wikis:
// let matchingSites = sites.filter(el => String(origin).replace(/^https?:\/\//, '').startsWith(el.origin_base_url));
let matchingSites = []; let matchingSites = [];
if (crossLanguageSetting === 'on') { if (crossLanguageSetting === 'on') {
matchingSites = sites.filter(el => String(origin).replace(/^https?:\/\//, '').startsWith(el.origin_base_url)); matchingSites = sites.filter(el => origin.replace(/^https?:\/\//, '').startsWith(el.origin_base_url));
} else { } else {
matchingSites = sites.filter(el => String(origin).replace(/^https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path)); matchingSites = sites.filter(el => origin.replace(/^https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path));
} }
if (matchingSites.length > 0) { if (matchingSites.length > 0) {
// Select match with longest base URL // Select match with longest base URL
@ -405,12 +409,13 @@ function main() {
} else if (storage.defaultWikiAction) { } else if (storage.defaultWikiAction) {
siteSetting = storage.defaultWikiAction; siteSetting = storage.defaultWikiAction;
} }
// Notify if enabled for the wiki: // Notify if enabled for the wiki:
if (siteSetting === 'alert') { if (siteSetting === 'alert') {
// Get article name from the end of the URL; // Get article name from the end of the URL;
// We can't just take the last part of the path due to subpages; // 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: // 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 originArticle = decodeURIComponent(origin.split(site['origin_base_url'] + site['origin_content_path'])[1] || '');
let destinationArticle = site['destination_content_prefix'] + originArticle; let destinationArticle = site['destination_content_prefix'] + originArticle;
// Set up URL to redirect user to based on wiki platform: // Set up URL to redirect user to based on wiki platform:
let newURL = ''; let newURL = '';

View File

@ -416,7 +416,10 @@ function filterSearchResults(searchResults, searchEngine, storage) {
} else { } else {
searchResultLink = searchResult.closest('a[href]').href; searchResultLink = searchResult.closest('a[href]').href;
} }
let link = String(decodeURIComponent(searchResultLink));
let urlObj = new URL(searchResultLink);
urlObj.search = '';
let link = String(decodeURIComponent(urlObj.toString()));
if (searchEngine === 'google') { if (searchEngine === 'google') {
// Break if image result: // Break if image result: