Using "select all" makes the option the default for future wikis + bugfix related to notifications
parent
adc464ab3e
commit
01f4a66ab7
|
@ -129,9 +129,13 @@ async function main(eventInfo, eventName) {
|
|||
// Get user's settings for the wiki
|
||||
let settings = storage.siteSettings || {};
|
||||
let id = site['id'];
|
||||
let siteSetting = 'alert';
|
||||
let siteSetting = '';
|
||||
if (settings.hasOwnProperty(id) && settings[id].hasOwnProperty('action')) {
|
||||
siteSetting = settings[id].action;
|
||||
} else if (storage.defaultActionSetting) {
|
||||
siteSetting = storage.defaultActionSetting;
|
||||
} else {
|
||||
siteSetting = 'alert';
|
||||
}
|
||||
// Check if redirects are enabled for the site:
|
||||
if (siteSetting === 'redirect') {
|
||||
|
|
135
content.js
135
content.js
|
@ -125,9 +125,13 @@ function filterSearchResults(fandomSearchResults, searchEngine, storage) {
|
|||
// Get user's settings for the wiki
|
||||
let settings = storage.siteSettings || {};
|
||||
let id = site['id'];
|
||||
let searchFilterSetting = 'true';
|
||||
let searchFilterSetting = '';
|
||||
if (settings.hasOwnProperty(id) && settings[id].searchFilter) {
|
||||
searchFilterSetting = settings[id].searchFilter;
|
||||
} else if (storage.defaultSearchFilterSetting) {
|
||||
searchFilterSetting = storage.defaultSearchFilterSetting;
|
||||
} else {
|
||||
searchFilterSetting = 'true';
|
||||
}
|
||||
if (searchFilterSetting === 'true') {
|
||||
let cssQuery = '';
|
||||
|
@ -188,83 +192,70 @@ function main(mutations = null, observer = null) {
|
|||
// Check if on Fandom or BreezeWiki
|
||||
// If on BreezeWiki, check if there is a pathname (which indicates we are looking at a wiki)
|
||||
if (currentURL.hostname.match(fandomRegex) || (currentURL.hostname.match(breezeWikiRegex) && currentURL.pathname.length > 1)) {
|
||||
// Check if notifications are enabled:
|
||||
if ((storage.notifications ?? 'on') === 'on') {
|
||||
let origin = currentURL;
|
||||
// If on a BreezeWiki site, convert to Fandom link to match with our list of wikis:
|
||||
if (currentURL.hostname.match(breezeWikiRegex)) {
|
||||
origin = String(currentURL.pathname).split('/')[1] + '.fandom.com/wiki/';
|
||||
if (currentURL.search.includes('?q=')) {
|
||||
origin = origin + currentURL.search.substring(3).split('&')[0];
|
||||
} else {
|
||||
origin = origin + currentURL.pathname.split('/')[3];
|
||||
}
|
||||
let origin = currentURL;
|
||||
// If on a BreezeWiki site, convert to Fandom link to match with our list of wikis:
|
||||
if (currentURL.hostname.match(breezeWikiRegex)) {
|
||||
origin = String(currentURL.pathname).split('/')[1] + '.fandom.com/wiki/';
|
||||
if (currentURL.search.includes('?q=')) {
|
||||
origin = origin + currentURL.search.substring(3).split('&')[0];
|
||||
} else {
|
||||
origin = origin + currentURL.pathname.split('/')[3];
|
||||
}
|
||||
getData().then(sites => {
|
||||
// Check if site is in our list of wikis:
|
||||
let matchingSites = sites.filter(el => String(origin).replace(/^https?:\/\//, '').startsWith(el.origin_base_url));
|
||||
if (matchingSites.length > 0) {
|
||||
// Select match with longest base URL
|
||||
let closestMatch = "";
|
||||
matchingSites.forEach(site => {
|
||||
if (site.origin_base_url.length > closestMatch.length) {
|
||||
closestMatch = site.origin_base_url;
|
||||
}
|
||||
});
|
||||
let site = matchingSites.find(site => site.origin_base_url === closestMatch);
|
||||
if (site) {
|
||||
// Get user's settings for the wiki
|
||||
let settings = storage.siteSettings || {};
|
||||
let id = site['id'];
|
||||
let siteSetting = 'alert';
|
||||
if (settings.hasOwnProperty(id) && settings[id].hasOwnProperty('action')) {
|
||||
siteSetting = settings[id].action;
|
||||
}
|
||||
// Notify if enabled for the wiki:
|
||||
if (siteSetting === 'alert') {
|
||||
// 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 = String(origin).split(site['origin_base_url'] + site['origin_content_path'])[1];
|
||||
// Set up URL to redirect user to based on wiki platform:
|
||||
if (article || (!article && !url.href.split(site['origin_base_url'] + '/')[1])) {
|
||||
let newURL = '';
|
||||
if (article) {
|
||||
let searchParams = '';
|
||||
switch (site['destination_platform']) {
|
||||
case 'mediawiki':
|
||||
searchParams = '?title=Special:Search&search=' + article;
|
||||
break;
|
||||
case 'doku':
|
||||
searchParams = 'start?do=search&q=' + article;
|
||||
break;
|
||||
}
|
||||
newURL = 'https://' + site["destination_base_url"] + site["destination_content_path"] + searchParams;
|
||||
} else {
|
||||
newURL = 'https://' + site["destination_base_url"];
|
||||
}
|
||||
getData().then(sites => {
|
||||
// Check if site is in our list of wikis:
|
||||
let matchingSites = sites.filter(el => String(origin).replace(/^https?:\/\//, '').startsWith(el.origin_base_url));
|
||||
if (matchingSites.length > 0) {
|
||||
// Select match with longest base URL
|
||||
let closestMatch = "";
|
||||
matchingSites.forEach(site => {
|
||||
if (site.origin_base_url.length > closestMatch.length) {
|
||||
closestMatch = site.origin_base_url;
|
||||
}
|
||||
});
|
||||
let site = matchingSites.find(site => site.origin_base_url === closestMatch);
|
||||
if (site) {
|
||||
// Get user's settings for the wiki
|
||||
let settings = storage.siteSettings || {};
|
||||
let id = site['id'];
|
||||
let siteSetting = '';
|
||||
if (settings.hasOwnProperty(id) && settings[id].hasOwnProperty('action')) {
|
||||
siteSetting = settings[id].action;
|
||||
} else if (storage.defaultActionSetting) {
|
||||
siteSetting = storage.defaultActionSetting;
|
||||
} else {
|
||||
siteSetting = 'alert';
|
||||
}
|
||||
// Notify if enabled for the wiki:
|
||||
if (siteSetting === 'alert') {
|
||||
// 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 = String(origin).split(site['origin_base_url'] + site['origin_content_path'])[1];
|
||||
// Set up URL to redirect user to based on wiki platform:
|
||||
if (article || (!article && !url.href.split(site['origin_base_url'] + '/')[1])) {
|
||||
let newURL = '';
|
||||
if (article) {
|
||||
let searchParams = '';
|
||||
switch (site['destination_platform']) {
|
||||
case 'mediawiki':
|
||||
searchParams = '?title=Special:Search&search=' + article;
|
||||
break;
|
||||
case 'doku':
|
||||
searchParams = 'start?do=search&q=' + article;
|
||||
break;
|
||||
}
|
||||
// Notify that another wiki is available
|
||||
displayRedirectBanner(newURL, site['destination'], storage);
|
||||
|
||||
// Unused code to notify user of alternative via browser notification:
|
||||
// let notifID = 'independent-wiki-redirector-notification-' + Math.floor(Math.random() * 1E16);
|
||||
// chrome.notifications.create(notifID, {
|
||||
// "type": "basic",
|
||||
// "iconUrl": 'images/logo-48.png',
|
||||
// "title": "An independent wiki is available!",
|
||||
// "message": "Check out " + site['destination']
|
||||
// });
|
||||
// chrome.notifications.onClicked.addListener(function () {
|
||||
// chrome.tabs.update(undefined, { url: newURL });
|
||||
// });
|
||||
// chrome.storage.sync.set({ 'countAlerts': (storage.countAlerts ?? 0) + 1 });
|
||||
// setTimeout(function () { chrome.notifications.clear(notifID); }, 6000);
|
||||
newURL = 'https://' + site["destination_base_url"] + site["destination_content_path"] + searchParams;
|
||||
} else {
|
||||
newURL = 'https://' + site["destination_base_url"];
|
||||
}
|
||||
// Notify that another wiki is available
|
||||
displayRedirectBanner(newURL, site['destination'], storage);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (currentURL.hostname.includes('www.google.')) {
|
||||
// Check if doing a Google search:
|
||||
function filterGoogle() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Indie Wiki Buddy",
|
||||
"version": "1.0.4",
|
||||
"version": "1.1.0",
|
||||
"description": "Helping you discover quality independent wikis through alerts, redirects, and search filtering",
|
||||
"permissions": [
|
||||
"storage",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Indie Wiki Buddy",
|
||||
"version": "1.0.4",
|
||||
"version": "1.1.0",
|
||||
"description": "Helping you discover quality independent wikis through alerts, redirects, and search filtering",
|
||||
"permissions": [
|
||||
"storage",
|
||||
|
|
30
popup.js
30
popup.js
|
@ -148,20 +148,39 @@ async function loadOptions(lang) {
|
|||
inputFilter.title = 'Filter from search results on Google, Bing, and DuckDuckGo';
|
||||
inputFilter.id = key + '-filter';
|
||||
|
||||
// Check radio button based on user's settings (default alert):
|
||||
// Check radio button based on user's settings
|
||||
// Will default to alert or the last "select all" setting the user chose
|
||||
if (siteSettings[key] && siteSettings[key].action === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (siteSettings[key] && siteSettings[key].action === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
} else {
|
||||
} else if (siteSettings[key] && siteSettings[key].action === 'alert') {
|
||||
inputAlert.checked = true;
|
||||
} else {
|
||||
chrome.storage.sync.get({ 'defaultActionSetting': 'alert' }, function (response) {
|
||||
if (response.defaultActionSetting === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (response.defaultActionSetting === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Check search filter checkbox based on user's settings (default filter):
|
||||
if (siteSettings[key] && siteSettings[key].searchFilter === 'false') {
|
||||
inputFilter.checked = false;
|
||||
} else {
|
||||
} else if (siteSettings[key] && siteSettings[key].searchFilter === 'true') {
|
||||
inputFilter.checked = true;
|
||||
} else {
|
||||
chrome.storage.sync.get({ 'defaultSearchFilterSetting': 'true' }, function (response) {
|
||||
if (response.defaultSearchFilterSetting === 'true') {
|
||||
inputFilter.checked = true;
|
||||
} else {
|
||||
inputFilter.checked = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add listeners for when user clicks control:
|
||||
|
@ -261,6 +280,7 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('action', 'redirect');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultActionSetting': 'redirect' });
|
||||
});
|
||||
|
||||
var setAllAlert = document.getElementById('setAllAlert');
|
||||
|
@ -271,6 +291,7 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('action', 'alert');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultActionSetting': 'alert' });
|
||||
});
|
||||
|
||||
var setAllDisabled = document.getElementById('setAllDisabled');
|
||||
|
@ -281,6 +302,7 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('action', 'disabled');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultActionSetting': 'disabled' });
|
||||
});
|
||||
|
||||
var setAllSearchFilter = document.getElementById('setAllSearchFilter');
|
||||
|
@ -291,6 +313,7 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('searchFilter', 'true');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSetting': 'true' });
|
||||
});
|
||||
|
||||
var setNoneSearchFilter = document.getElementById('setNoneSearchFilter');
|
||||
|
@ -301,6 +324,7 @@ async function loadOptions(lang) {
|
|||
siteSettings.get(toggles[i].name).set('searchFilter', 'false');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSetting': 'false' });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue