diff --git a/background.js b/background.js index 197f105..d3db240 100644 --- a/background.js +++ b/background.js @@ -347,7 +347,7 @@ async function main(url, tabId) { // Get article name from the end of the URL; // 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 article = decodeURIComponent(url.split(site['origin_base_url'] + site['origin_content_path'])[1]); + let article = decodeURIComponent(url.split(site['origin_base_url'] + site['origin_content_path'])[1] || ''); // Set up URL to redirect user to based on wiki platform let newURL = ''; if (article) { diff --git a/content-banners.js b/content-banners.js index b341d4e..5b8849a 100644 --- a/content-banners.js +++ b/content-banners.js @@ -285,7 +285,7 @@ function main() { // Get article name from the end of the URL; // 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 article = decodeURIComponent(String(origin).split(site['origin_content_path'])[1]); + let article = decodeURIComponent(String(origin).split(site['origin_base_url'] + site['origin_content_path'])[1] || ''); // Set up URL to redirect user to based on wiki platform: let newURL = ''; if (article) { diff --git a/content-search-filtering.js b/content-search-filtering.js index 0506a77..669d3c2 100644 --- a/content-search-filtering.js +++ b/content-search-filtering.js @@ -195,7 +195,7 @@ function escapeRegex(string) { function replaceSearchResults(searchResultContainer, site, link) { // Build new URL: - let article = decodeURIComponent(link.split(site['origin_content_path'])[1]?.split('#')[0].split('?')[0].split('&')[0]); + let article = decodeURIComponent((link.split(site['origin_base_url'] + site['origin_content_path'])[1] || '').split('#')[0].split('?')[0].split('&')[0]); let newURL = ''; if (article) { // Check if main page @@ -423,7 +423,8 @@ function filterSearchResults(searchResults, searchEngine, storage) { if (crossLanguageSetting === 'on') { matchingSites = sites.filter(el => link.replace(/.*https?:\/\//, '').startsWith(el.origin_base_url)); } else { - matchingSites = sites.filter(el => link.replace(/.*https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path)); + matchingSites = sites.filter(el => link.replace(/.*https?:\/\//, '') === (el.origin_base_url)); + matchingSites = matchingSites.concat(sites.filter(el => link.replace(/.*https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path))); } if (matchingSites.length > 0) { // Select match with longest base URL