Update search engine toggle / Fix storage

Need to wrap storage retrieval in a promise for Firefox manifest v2. Also setting API variable based on browser.
toggle-search-engines
Kevin Payravi 2024-04-18 19:46:27 +02:00
parent 27f57fab87
commit 998bb7b8eb
12 changed files with 392 additions and 664 deletions

View File

@ -4,9 +4,29 @@ if (typeof importScripts !== 'undefined') {
let cachedStorage = {};
function getLocalStorageData() {
// Wrap the extensionAPI.storage.sync.get method in a promise
// Needed for Firefox manifest v2
return new Promise((resolve, reject) => {
extensionAPI.storage.local.get(null, (items) => {
resolve(items);
});
});
}
function getSyncStorageData() {
// Wrap the extensionAPI.storage.sync.get method in a promise
// Needed for Firefox manifest v2
return new Promise((resolve, reject) => {
extensionAPI.storage.sync.get(null, (items) => {
resolve(items);
});
});
}
async function updateCachedStorage() {
let localStorage = await chrome.storage.local.get();
let syncStorage = await chrome.storage.sync.get();
let localStorage = await getLocalStorageData();
let syncStorage = await getSyncStorageData();
cachedStorage = {...localStorage, ...syncStorage};
}
@ -21,11 +41,11 @@ async function getCachedStorage() {
updateCachedStorage();
// Capture web requests
chrome.webRequest.onBeforeSendHeaders.addListener(
extensionAPI.webRequest.onBeforeSendHeaders.addListener(
async (event) => {
if (event.documentLifecycle !== 'prerender') {
if (event.frameType === 'sub_frame') {
let tabInfo = await chrome.tabs.get(event.tabId);
let tabInfo = await extensionAPI.tabs.get(event.tabId);
main(tabInfo.url, event.tabId);
} else {
main(event.url, event.tabId);
@ -36,45 +56,46 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
);
// Listen for user turning extension on or off, to update icon
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
extensionAPI.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (msg.action === 'updateIcon') {
setPowerIcon(msg.value);
} else if (msg.action === 'getStorage') {
getCachedStorage().then((res) => {
sendResponse(res)
sendResponse(res);
return res;
});
return true;
}
});
// Listen for browser starting, to set initial icon state
chrome.runtime.onStartup.addListener(() => {
chrome.storage.local.get({ 'power': 'on' }, (item) => {
extensionAPI.runtime.onStartup.addListener(() => {
extensionAPI.storage.local.get({ 'power': 'on' }, (item) => {
setPowerIcon(item.power);
});
});
// Listen for changes to stored data, and updated our cached data
chrome.storage.onChanged.addListener(() => {
extensionAPI.storage.onChanged.addListener(() => {
updateCachedStorage();
})
// Listen for extension installed/updating
chrome.runtime.onInstalled.addListener(async (detail) => {
extensionAPI.runtime.onInstalled.addListener(async (detail) => {
// Set initial icon state
chrome.storage.local.get({ 'power': 'on' }, (item) => {
extensionAPI.storage.local.get({ 'power': 'on' }, (item) => {
setPowerIcon(item.power);
});
// If new install, open settings with starter guide
if (detail.reason === 'install') {
chrome.tabs.create({ url: 'pages/settings/index.html?newinstall=true' });
extensionAPI.tabs.create({ url: 'pages/settings/index.html?newinstall=true' });
}
// If update, open changelog if setting is enabled
chrome.storage.sync.get({ 'openChangelog': 'off' }, (item) => {
extensionAPI.storage.sync.get({ 'openChangelog': 'off' }, (item) => {
if (item.openChangelog === 'on' && detail.reason === 'update') {
chrome.tabs.create({ url: 'https://getindie.wiki/changelog/?updated=true', active: false });
extensionAPI.tabs.create({ url: 'https://getindie.wiki/changelog/?updated=true', active: false });
}
});
@ -85,18 +106,18 @@ chrome.runtime.onInstalled.addListener(async (detail) => {
});
function setPowerIcon(status) {
const manifestVersion = chrome.runtime.getManifest().manifest_version;
const manifestVersion = extensionAPI.runtime.getManifest().manifest_version;
if (status === 'on') {
if (manifestVersion === 2) {
chrome.browserAction.setIcon({ path: "/images/logo-128.png" });
extensionAPI.browserAction.setIcon({ path: "/images/logo-128.png" });
} else {
chrome.action.setIcon({ path: "/images/logo-128.png" });
extensionAPI.action.setIcon({ path: "/images/logo-128.png" });
}
} else {
if (manifestVersion === 2) {
chrome.browserAction.setIcon({ path: "/images/logo-off.png" });
extensionAPI.browserAction.setIcon({ path: "/images/logo-off.png" });
} else {
chrome.action.setIcon({ path: "/images/logo-off.png" });
extensionAPI.action.setIcon({ path: "/images/logo-off.png" });
}
}
}
@ -111,25 +132,25 @@ function redirectToBreezeWiki(storage, tabId, url) {
// Perform redirect
if (article) {
chrome.tabs.update(tabId, { url: host + '/' + subdomain + '/wiki/' + article });
extensionAPI.tabs.update(tabId, { url: host + '/' + subdomain + '/wiki/' + article });
} else {
chrome.tabs.update(tabId, { url: host + '/' + subdomain });
extensionAPI.tabs.update(tabId, { url: host + '/' + subdomain });
}
// Increase BreezeWiki stat count
chrome.storage.sync.set({ 'countBreezeWiki': (storage.countBreezeWiki ?? 0) + 1 });
extensionAPI.storage.sync.set({ 'countBreezeWiki': (storage.countBreezeWiki ?? 0) + 1 });
if ((storage.notifications ?? 'on') === 'on') {
// Notify that user is being redirected to BreezeWiki
let notifID = 'independent-wiki-redirector-notification-' + Math.floor(Math.random() * 1E16);
chrome.notifications.create(notifID, {
extensionAPI.notifications.create(notifID, {
"type": "basic",
"iconUrl": 'images/logo-48.png',
"title": "You've been redirected to BreezeWiki!",
"message": "Indie Wiki Buddy has sent you to BreezeWiki for a cleaner, ad-free experience on Fandom."
});
// Self-clear notification after 6 seconds
setTimeout(() => { chrome.notifications.clear(notifID); }, 6000);
setTimeout(() => { extensionAPI.notifications.clear(notifID); }, 6000);
}
}
@ -143,7 +164,7 @@ function redirectToBreezeWiki(storage, tabId, url) {
throw new Error('Indie Wiki Buddy failed to get BreezeWiki data.');
}).then((breezewikiHosts) => {
breezewikiHosts = breezewikiHosts.filter(host =>
chrome.runtime.getManifest().version.localeCompare(host.iwb_version,
extensionAPI.runtime.getManifest().version.localeCompare(host.iwb_version,
undefined,
{ numeric: true, sensitivity: 'base' }
) >= 0
@ -151,21 +172,21 @@ function redirectToBreezeWiki(storage, tabId, url) {
// Check if BreezeWiki's main site is available
let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com');
if (breezewikiMain.length > 0) {
chrome.storage.sync.set({ 'breezewikiHost': breezewikiMain[0].instance });
extensionAPI.storage.sync.set({ 'breezewikiHost': breezewikiMain[0].instance });
} else {
// If BreezeWiki.com is not available, set to a random mirror
try {
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance });
extensionAPI.storage.sync.set({ 'breezewikiHost': breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance });
} catch (e) {
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
}
}
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
extensionAPI.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
extensionAPI.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
processRedirect(host);
}).catch((e) => {
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
chrome.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
extensionAPI.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
});
} else {
if (storage.breezewikiHost === 'CUSTOM') {
@ -195,23 +216,23 @@ async function main(url, tabId) {
let newURL = commonFunctionGetNewURL(url, matchingSite);
// Perform redirect
chrome.tabs.update(tabId, { url: newURL });
extensionAPI.tabs.update(tabId, { url: newURL });
// Increase redirect count
chrome.storage.sync.set({ 'countRedirects': (storage.countRedirects ?? 0) + 1 });
extensionAPI.storage.sync.set({ 'countRedirects': (storage.countRedirects ?? 0) + 1 });
// Notify if enabled
if ((storage.notifications ?? 'on') === 'on') {
// Notify that user is being redirected
let notifID = 'independent-wiki-redirector-notification-' + Math.floor(Math.random() * 1E16);
chrome.notifications.create(notifID, {
extensionAPI.notifications.create(notifID, {
"type": "basic",
"iconUrl": 'images/logo-48.png',
"title": "You've been redirected!",
"message": "Indie Wiki Buddy has sent you from " + matchingSite['origin'] + " to " + matchingSite['destination']
});
// Self-clear notification after 6 seconds
setTimeout(() => { chrome.notifications.clear(notifID); }, 6000);
setTimeout(() => { extensionAPI.notifications.clear(notifID); }, 6000);
}
} else if ((storage.breezewiki ?? 'off') === 'on' || (storage.breezewiki ?? 'off') === 'redirect') {
redirectToBreezeWiki(storage, tabId, url);

View File

@ -46,6 +46,11 @@ a:visited {
color: var(--text-link-color);
}
fieldset hr {
color: var(--base-color-outline-light);
background-color: var(--base-color-outline-light);
margin: 2px;
}
hr {
height: 1px;
border: none;
@ -197,6 +202,9 @@ select {
.options label {
display: inline-block;
}
.searchEngineToggles label {
white-space: nowrap;
}
.settingToggle {
width: fit-content;

View File

@ -1,23 +1,23 @@
// Set setting toggle values on-load:
chrome.storage.local.get({ 'power': 'on' }, (item) => {
extensionAPI.storage.local.get({ 'power': 'on' }, (item) => {
setPower(item.power, false);
});
chrome.storage.sync.get({ 'notifications': 'on' }, (item) => {
extensionAPI.storage.sync.get({ 'notifications': 'on' }, (item) => {
setNotifications(item.notifications, false);
});
chrome.storage.sync.get({ 'hiddenResultsBanner': 'on' }, (item) => {
extensionAPI.storage.sync.get({ 'hiddenResultsBanner': 'on' }, (item) => {
setHiddenResultsBanner(item.hiddenResultsBanner, false);
});
chrome.storage.sync.get({ 'crossLanguage': 'off' }, (item) => {
extensionAPI.storage.sync.get({ 'crossLanguage': 'off' }, (item) => {
setCrossLanguage(item.crossLanguage, false);
});
chrome.storage.sync.get({ 'reorderResults': 'on' }, (item) => {
extensionAPI.storage.sync.get({ 'reorderResults': 'on' }, (item) => {
setReorder(item.reorderResults, false);
});
chrome.storage.sync.get({ 'openChangelog': 'off' }, (item) => {
extensionAPI.storage.sync.get({ 'openChangelog': 'off' }, (item) => {
setOpenChangelog(item.openChangelog, false);
});
chrome.storage.sync.get({ 'breezewiki': 'off' }, (item) => {
extensionAPI.storage.sync.get({ 'breezewiki': 'off' }, (item) => {
// Account for legacy 'on' setting for BreezeWiki
if (item.breezewiki === 'on') {
setBreezeWiki('redirect');
@ -33,7 +33,7 @@ chrome.storage.sync.get({ 'breezewiki': 'off' }, (item) => {
// Add event listener for power toggle
document.getElementById('powerCheckbox').addEventListener('change', () => {
chrome.storage.local.get({ 'power': 'on' }, (item) => {
extensionAPI.storage.local.get({ 'power': 'on' }, (item) => {
if (item.power === 'on') {
setPower('off');
} else {
@ -42,24 +42,49 @@ document.getElementById('powerCheckbox').addEventListener('change', () => {
});
});
// Event listeners for toggling search engines
const searchEngineToggles = document.querySelectorAll('.searchEngineToggles label');
console.log(searchEngineToggles);
searchEngineToggles.forEach((engine) => {
let engineInput = engine.querySelector('input');
let engineName = engineInput.getAttribute('data-search-engine');
engine.addEventListener('change', () => {
if (engineInput.checked) {
commonFunctionRequestSearchEngineAccess(engineName);
extensionAPI.storage.sync.get({'searchEngineToggles': {}}, (settings) => {
settings.searchEngineToggles[engineName] = 'on';
extensionAPI.storage.sync.set({
'searchEngineToggles': settings.searchEngineToggles
});
});
engineInput.checked = true;
} else {
commonFunctionRemoveSearchEngineAccess(engineName);
extensionAPI.storage.sync.get( { 'searchEngineToggles': {} }, (settings) => {
settings.searchEngineToggles[engineName] = 'off';
extensionAPI.storage.sync.set({
'searchEngineToggles': settings.searchEngineToggles
});
});
engineInput.checked = false;
}
});
});
document.querySelectorAll('.searchEngineToggles input').forEach((el) => {
const searchEngineName = el.getAttribute('data-search-engine');
extensionAPI.storage.sync.get({
'searchEngineToggles': {}
}, (settings) => {
if (settings.searchEngineToggles[searchEngineName] === 'on' || !settings.searchEngineToggles.hasOwnProperty(searchEngineName)) {
el.checked = true;
} else {
el.checked = false;
}
});
});
// Set notifications setting
function setNotifications(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'notifications': setting });
extensionAPI.storage.sync.set({ 'notifications': setting });
}
const notificationsIcon = document.getElementById('notificationsIcon');
if (setting === 'on') {
@ -74,7 +99,7 @@ function setNotifications(setting, storeSetting = true) {
// Set search results hidden banner setting
function setHiddenResultsBanner(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'hiddenResultsBanner': setting });
extensionAPI.storage.sync.set({ 'hiddenResultsBanner': setting });
}
const hiddenResultsBannerIcon = document.getElementById('hiddenResultsBannerIcon');
if (setting === 'on') {
@ -89,7 +114,7 @@ function setHiddenResultsBanner(setting, storeSetting = true) {
// Set cross-language setting
function setCrossLanguage(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'crossLanguage': setting });
extensionAPI.storage.sync.set({ 'crossLanguage': setting });
}
const crossLanguageIcon = document.getElementById('crossLanguageIcon');
@ -105,7 +130,7 @@ function setCrossLanguage(setting, storeSetting = true) {
// Set re-order setting
function setReorder(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'reorderResults': setting });
extensionAPI.storage.sync.set({ 'reorderResults': setting });
}
if (setting === 'on') {
@ -118,7 +143,7 @@ function setReorder(setting, storeSetting = true) {
// Set open changelog setting
function setOpenChangelog(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.sync.set({ 'openChangelog': setting });
extensionAPI.storage.sync.set({ 'openChangelog': setting });
}
const openChangelogIcon = document.getElementById('openChangelogIcon');
@ -133,7 +158,7 @@ function setOpenChangelog(setting, storeSetting = true) {
// Event listeners for general setting toggles
document.getElementById('notificationsCheckbox').addEventListener('change', () => {
chrome.storage.sync.get({ 'notifications': 'on' }, (item) => {
extensionAPI.storage.sync.get({ 'notifications': 'on' }, (item) => {
if (item.notifications === 'on') {
setNotifications('off');
} else {
@ -142,7 +167,7 @@ document.getElementById('notificationsCheckbox').addEventListener('change', () =
});
});
document.getElementById('hiddenResultsBannerCheckbox').addEventListener('change', () => {
chrome.storage.sync.get({ 'hiddenResultsBanner': 'on' }, (item) => {
extensionAPI.storage.sync.get({ 'hiddenResultsBanner': 'on' }, (item) => {
if (item.hiddenResultsBanner === 'on') {
setHiddenResultsBanner('off');
} else {
@ -151,7 +176,7 @@ document.getElementById('hiddenResultsBannerCheckbox').addEventListener('change'
});
});
document.getElementById('crossLanguageCheckbox').addEventListener('change', () => {
chrome.storage.sync.get({ 'crossLanguage': 'off' }, (item) => {
extensionAPI.storage.sync.get({ 'crossLanguage': 'off' }, (item) => {
if (item.crossLanguage === 'on') {
setCrossLanguage('off');
} else {
@ -160,7 +185,7 @@ document.getElementById('crossLanguageCheckbox').addEventListener('change', () =
});
});
document.getElementById('reorderResultsCheckbox').addEventListener('change', () => {
chrome.storage.sync.get({ 'reorderResults': 'on' }, (item) => {
extensionAPI.storage.sync.get({ 'reorderResults': 'on' }, (item) => {
if (item.reorderResults === 'on') {
setReorder('off');
} else {
@ -169,7 +194,7 @@ document.getElementById('reorderResultsCheckbox').addEventListener('change', ()
});
});
document.getElementById('openChangelogCheckbox').addEventListener('change', () => {
chrome.storage.sync.get({ 'openChangelog': 'off' }, (item) => {
extensionAPI.storage.sync.get({ 'openChangelog': 'off' }, (item) => {
if (item.openChangelog === 'on') {
setOpenChangelog('off');
} else {
@ -180,7 +205,7 @@ document.getElementById('openChangelogCheckbox').addEventListener('change', () =
document.querySelectorAll('[name="breezewikiSetting"]').forEach((el) => {
el.addEventListener('change', async () => {
const settingValue = document.options.breezewikiSetting.value;
chrome.storage.sync.set({ 'breezewiki': settingValue });
extensionAPI.storage.sync.set({ 'breezewiki': settingValue });
setBreezeWiki(settingValue);
if (settingValue !== 'off') {
loadBreezewikiOptions();
@ -197,7 +222,7 @@ function setBreezeWiki(setting, storeSetting = true) {
// Store BreezeWiki setting
if (storeSetting) {
chrome.storage.sync.set({ 'breezewiki': setting });
extensionAPI.storage.sync.set({ 'breezewiki': setting });
}
// Set BreezeWiki value on radio group
@ -207,7 +232,7 @@ function setBreezeWiki(setting, storeSetting = true) {
const breezewikiHost = document.getElementById('breezewikiHost');
if (setting !== 'off') {
breezewikiHost.style.display = 'block';
chrome.storage.sync.get({ 'breezewikiHost': null }, (host) => {
extensionAPI.storage.sync.get({ 'breezewikiHost': null }, (host) => {
if (!host.breezewikiHost) {
fetch('https://bw.getindie.wiki/instances.json')
.then((response) => {
@ -217,7 +242,7 @@ function setBreezeWiki(setting, storeSetting = true) {
throw new Error('Indie Wiki Buddy failed to get BreezeWiki data.');
}).then((breezewikiHosts) => {
breezewikiHosts = breezewikiHosts.filter(host =>
chrome.runtime.getManifest().version.localeCompare(host.iwb_version,
extensionAPI.runtime.getManifest().version.localeCompare(host.iwb_version,
undefined,
{ numeric: true, sensitivity: 'base' }
) >= 0
@ -234,16 +259,16 @@ function setBreezeWiki(setting, storeSetting = true) {
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
}
}
chrome.storage.sync.set({ 'breezewikiHost': host.breezewikiHost });
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
extensionAPI.storage.sync.set({ 'breezewikiHost': host.breezewikiHost });
extensionAPI.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
extensionAPI.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
document.getElementById('breezewikiHostSelect').value = host.breezewikiHost;
}).catch((e) => {
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
// If fetch fails and no host is set, default to breezewiki.com:
if (!host) {
chrome.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
extensionAPI.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
}
});
} else {
@ -295,7 +320,7 @@ function populateBreezewikiHosts(breezewikiHosts, selectedHost, customHostName)
// Populate BreezeWiki dropdown when enabled
async function loadBreezewikiOptions() {
// Load BreezeWiki options:
chrome.storage.sync.get(['breezewikiHostOptions', 'breezewikiHostFetchTimestamp', 'breezewikiHost', 'breezewikiCustomHost'], (item) => {
extensionAPI.storage.sync.get(['breezewikiHostOptions', 'breezewikiHostFetchTimestamp', 'breezewikiHost', 'breezewikiCustomHost'], (item) => {
let hostOptions = item.breezewikiHostOptions;
let hostFetchTimestamp = item.breezewikiHostFetchTimestamp;
let host = item.breezewikiHost;
@ -312,7 +337,7 @@ async function loadBreezewikiOptions() {
throw new Error('Indie Wiki Buddy failed to get BreezeWiki data.');
}).then((breezewikiHosts) => {
breezewikiHosts = breezewikiHosts.filter(host =>
chrome.runtime.getManifest().version.localeCompare(host.iwb_version,
extensionAPI.runtime.getManifest().version.localeCompare(host.iwb_version,
undefined,
{ numeric: true, sensitivity: 'base' }
) >= 0
@ -335,15 +360,15 @@ async function loadBreezewikiOptions() {
populateBreezewikiHosts(breezewikiHosts, host, customHost);
// Store BreezeWiki host details
chrome.storage.sync.set({ 'breezewikiHost': host });
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
extensionAPI.storage.sync.set({ 'breezewikiHost': host });
extensionAPI.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
extensionAPI.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
}).catch((e) => {
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
// If fetch fails and no host is set, default to breezewiki.com:
if (!host) {
chrome.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
extensionAPI.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
}
});
} else {
@ -355,7 +380,7 @@ async function loadBreezewikiOptions() {
populateBreezewikiHosts(hostOptions, host, customHost);
// Store BreezeWiki host details
chrome.storage.sync.set({ 'breezewikiHost': host });
extensionAPI.storage.sync.set({ 'breezewikiHost': host });
}
});
}
}

View File

@ -119,6 +119,59 @@
indie English wikis there is no same-lang wiki
</label>
</div>
<div class="settingToggle">
<label>
<input id="openChangelogCheckbox" type="checkbox" />
<span id="openChangelogIcon" aria-hidden="true"></span>
Open changelog when Indie Wiki Buddy is updated
</label>
</div>
</fieldset>
<fieldset id="generalSettings">
<legend><span aria-hidden="true">🔍</span> Search engine filtering settings</legend>
<div class="settingToggle searchEngineToggles">
<label>
<input id="googleCheckbox" data-search-engine="google" type="checkbox" />
Google
</label>
<label>
<input id="bingCheckbox" data-search-engine="bing" type="checkbox" />
Bing
</label>
<label>
<input id="duckduckgoCheckbox" data-search-engine="duckduckgo" type="checkbox" />
DuckDuckGo
</label>
<label>
<input id="braveCheckbox" data-search-engine="brave" type="checkbox" />
Brave
</label>
<label>
<input id="ecosiaCheckbox" data-search-engine="ecosia" type="checkbox" />
Ecosia
</label>
<label>
<input id="kagiCheckbox" data-search-engine="kagi" type="checkbox" />
Kagi
</label>
<label>
<input id="qwantCheckbox" data-search-engine="qwant" type="checkbox" />
Qwant
</label>
<label>
<input id="startpageCheckbox" data-search-engine="startpage" type="checkbox" />
Startpage
</label>
<label>
<input id="yahooCheckbox" data-search-engine="yahoo" type="checkbox" />
Yahoo
</label>
<label>
<input id="yandexCheckbox" data-search-engine="yandex" type="checkbox" />
Yandex
</label>
</div>
<hr>
<div class="settingToggle">
<label>
<input id="reorderResultsCheckbox" type="checkbox" />
@ -127,13 +180,6 @@
search results on Google
</label>
</div>
<div class="settingToggle">
<label>
<input id="openChangelogCheckbox" type="checkbox" />
<span id="openChangelogIcon" aria-hidden="true"></span>
Open changelog when Indie Wiki Buddy is updated
</label>
</div>
</fieldset>
<fieldset id="breezewikiSettings">
<legend>

View File

@ -1,11 +1,11 @@
// Set power setting
function setPower(setting) {
chrome.storage.local.set({ 'power': setting });
extensionAPI.storage.local.set({ 'power': setting });
var powerImage = document.getElementById('powerImage');
powerImage.src = '../../images/power-' + setting + '.png';
powerImage.alt = 'Indie Wiki Buddy is ' + setting;
chrome.runtime.sendMessage({
extensionAPI.runtime.sendMessage({
action: 'updateIcon',
value: setting
});
@ -18,7 +18,7 @@ async function migrateData() {
// Set power setting
function setPower(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.local.set({ 'power': setting });
extensionAPI.storage.local.set({ 'power': setting });
}
var powerImage = document.getElementById('powerImage');
powerImage.src = '../../images/power-' + setting + '.png';
@ -29,14 +29,14 @@ function setPower(setting, storeSetting = true) {
document.getElementById('powerCheckbox').checked = false;
}
chrome.runtime.sendMessage({
extensionAPI.runtime.sendMessage({
action: 'updateIcon',
value: setting
});
}
// Set default action setting
chrome.storage.sync.get(['defaultWikiAction'], (item) => {
extensionAPI.storage.sync.get(['defaultWikiAction'], (item) => {
if (item.defaultWikiAction === 'disabled') {
document.options.defaultWikiAction.value = 'disabled';
} else if (item.defaultWikiAction === 'redirect') {
@ -46,7 +46,7 @@ chrome.storage.sync.get(['defaultWikiAction'], (item) => {
}
});
// Set default search engine setting
chrome.storage.sync.get(['defaultSearchAction'], (item) => {
extensionAPI.storage.sync.get(['defaultSearchAction'], (item) => {
if (item.defaultSearchAction === 'disabled') {
document.options.defaultSearchAction.value = 'disabled';
} else if (item.defaultSearchAction === 'hide') {
@ -61,12 +61,12 @@ document.addEventListener('DOMContentLoaded', () => {
// If running Opera, show note about search engine access
if (navigator.userAgent.match(/OPR\//)) {
const notificationBannerOpera = document.getElementById('notificationBannerOpera');
chrome.storage.local.get({ 'hideOperaPermissionsNote': false }, (item) => {
extensionAPI.storage.local.get({ 'hideOperaPermissionsNote': false }, (item) => {
if (!item.hideOperaPermissionsNote) {
notificationBannerOpera.style.display = 'block';
document.getElementById('operaPermsHideLink').addEventListener('click', () => {
chrome.storage.local.set({ 'hideOperaPermissionsNote': true });
extensionAPI.storage.local.set({ 'hideOperaPermissionsNote': true });
notificationBannerOpera.style.display = 'none';
});
}
@ -75,11 +75,11 @@ document.addEventListener('DOMContentLoaded', () => {
// Listener for settings links:
document.getElementById('openSettingsButton').addEventListener('click', () => {
chrome.tabs.create({ 'url': chrome.runtime.getURL('pages/settings/index.html') });
extensionAPI.tabs.create({ 'url': extensionAPI.runtime.getURL('pages/settings/index.html') });
window.close();
});
document.getElementById('openSettingsLink').addEventListener('click', () => {
chrome.tabs.create({ 'url': chrome.runtime.getURL('pages/settings/index.html') });
extensionAPI.tabs.create({ 'url': extensionAPI.runtime.getURL('pages/settings/index.html') });
window.close();
});
@ -91,7 +91,7 @@ document.addEventListener('DOMContentLoaded', () => {
} else {
document.getElementById('breezewikiCustomHost').style.display = 'none';
}
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
extensionAPI.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
});
document.options.addEventListener("submit", function (e) {
@ -101,26 +101,26 @@ document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('[name="defaultWikiAction"]').forEach((el) => {
el.addEventListener('change', async () => {
chrome.storage.sync.set({ 'defaultWikiAction': document.options.defaultWikiAction.value })
extensionAPI.storage.sync.set({ 'defaultWikiAction': document.options.defaultWikiAction.value })
let wikiSettings = {};
sites = await commonFunctionGetSiteDataByDestination();
sites.forEach((site) => {
wikiSettings[site.id] = document.options.defaultWikiAction.value;
});
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
});
document.querySelectorAll('[name="defaultSearchAction"]').forEach((el) => {
el.addEventListener('change', async () => {
chrome.storage.sync.set({ 'defaultSearchAction': document.options.defaultSearchAction.value })
extensionAPI.storage.sync.set({ 'defaultSearchAction': document.options.defaultSearchAction.value })
let searchEngineSettings = {};
sites = await commonFunctionGetSiteDataByDestination();
sites.forEach((site) => {
searchEngineSettings[site.id] = document.options.defaultSearchAction.value;
});
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
extensionAPI.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
});
});

View File

@ -1,264 +0,0 @@
const searchEngineOrigins = {
bing: [
"https://*.bing.com/search*"
],
brave: [
"https://search.brave.com/search*"
],
duckduckgo: [
"https://*.duckduckgo.com/*"
],
ecosia: [
"https://*.ecosia.org/*",
],
kagi: [
"https://kagi.com/search*",
],
google: [
"https://www.google.com/search*",
"https://www.google.ad/search*",
"https://www.google.ae/search*",
"https://www.google.com.af/search*",
"https://www.google.com.ag/search*",
"https://www.google.com.ai/search*",
"https://www.google.al/search*",
"https://www.google.am/search*",
"https://www.google.co.ao/search*",
"https://www.google.com.ar/search*",
"https://www.google.as/search*",
"https://www.google.at/search*",
"https://www.google.com.au/search*",
"https://www.google.az/search*",
"https://www.google.ba/search*",
"https://www.google.com.bd/search*",
"https://www.google.be/search*",
"https://www.google.bf/search*",
"https://www.google.bg/search*",
"https://www.google.com.bh/search*",
"https://www.google.bi/search*",
"https://www.google.bj/search*",
"https://www.google.com.bn/search*",
"https://www.google.com.bo/search*",
"https://www.google.com.br/search*",
"https://www.google.bs/search*",
"https://www.google.bt/search*",
"https://www.google.co.bw/search*",
"https://www.google.by/search*",
"https://www.google.com.bz/search*",
"https://www.google.ca/search*",
"https://www.google.cd/search*",
"https://www.google.cf/search*",
"https://www.google.cg/search*",
"https://www.google.ch/search*",
"https://www.google.ci/search*",
"https://www.google.co.ck/search*",
"https://www.google.cl/search*",
"https://www.google.cm/search*",
"https://www.google.cn/search*",
"https://www.google.com.co/search*",
"https://www.google.co.cr/search*",
"https://www.google.com.cu/search*",
"https://www.google.cv/search*",
"https://www.google.com.cy/search*",
"https://www.google.cz/search*",
"https://www.google.de/search*",
"https://www.google.dj/search*",
"https://www.google.dk/search*",
"https://www.google.dm/search*",
"https://www.google.com.do/search*",
"https://www.google.dz/search*",
"https://www.google.com.ec/search*",
"https://www.google.ee/search*",
"https://www.google.com.eg/search*",
"https://www.google.es/search*",
"https://www.google.com.et/search*",
"https://www.google.fi/search*",
"https://www.google.com.fj/search*",
"https://www.google.fm/search*",
"https://www.google.fr/search*",
"https://www.google.ga/search*",
"https://www.google.ge/search*",
"https://www.google.gg/search*",
"https://www.google.com.gh/search*",
"https://www.google.com.gi/search*",
"https://www.google.gl/search*",
"https://www.google.gm/search*",
"https://www.google.gr/search*",
"https://www.google.com.gt/search*",
"https://www.google.gy/search*",
"https://www.google.com.hk/search*",
"https://www.google.hn/search*",
"https://www.google.hr/search*",
"https://www.google.ht/search*",
"https://www.google.hu/search*",
"https://www.google.co.id/search*",
"https://www.google.ie/search*",
"https://www.google.co.il/search*",
"https://www.google.im/search*",
"https://www.google.co.in/search*",
"https://www.google.iq/search*",
"https://www.google.is/search*",
"https://www.google.it/search*",
"https://www.google.je/search*",
"https://www.google.com.jm/search*",
"https://www.google.jo/search*",
"https://www.google.co.jp/search*",
"https://www.google.co.ke/search*",
"https://www.google.com.kh/search*",
"https://www.google.ki/search*",
"https://www.google.kg/search*",
"https://www.google.co.kr/search*",
"https://www.google.com.kw/search*",
"https://www.google.kz/search*",
"https://www.google.la/search*",
"https://www.google.com.lb/search*",
"https://www.google.li/search*",
"https://www.google.lk/search*",
"https://www.google.co.ls/search*",
"https://www.google.lt/search*",
"https://www.google.lu/search*",
"https://www.google.lv/search*",
"https://www.google.com.ly/search*",
"https://www.google.co.ma/search*",
"https://www.google.md/search*",
"https://www.google.me/search*",
"https://www.google.mg/search*",
"https://www.google.mk/search*",
"https://www.google.ml/search*",
"https://www.google.com.mm/search*",
"https://www.google.mn/search*",
"https://www.google.ms/search*",
"https://www.google.com.mt/search*",
"https://www.google.mu/search*",
"https://www.google.mv/search*",
"https://www.google.mw/search*",
"https://www.google.com.mx/search*",
"https://www.google.com.my/search*",
"https://www.google.co.mz/search*",
"https://www.google.com.na/search*",
"https://www.google.com.ng/search*",
"https://www.google.com.ni/search*",
"https://www.google.ne/search*",
"https://www.google.nl/search*",
"https://www.google.no/search*",
"https://www.google.com.np/search*",
"https://www.google.nr/search*",
"https://www.google.nu/search*",
"https://www.google.co.nz/search*",
"https://www.google.com.om/search*",
"https://www.google.com.pa/search*",
"https://www.google.com.pe/search*",
"https://www.google.com.pg/search*",
"https://www.google.com.ph/search*",
"https://www.google.com.pk/search*",
"https://www.google.pl/search*",
"https://www.google.pn/search*",
"https://www.google.com.pr/search*",
"https://www.google.ps/search*",
"https://www.google.pt/search*",
"https://www.google.com.py/search*",
"https://www.google.com.qa/search*",
"https://www.google.ro/search*",
"https://www.google.ru/search*",
"https://www.google.rw/search*",
"https://www.google.com.sa/search*",
"https://www.google.com.sb/search*",
"https://www.google.sc/search*",
"https://www.google.se/search*",
"https://www.google.com.sg/search*",
"https://www.google.sh/search*",
"https://www.google.si/search*",
"https://www.google.sk/search*",
"https://www.google.com.sl/search*",
"https://www.google.sn/search*",
"https://www.google.so/search*",
"https://www.google.sm/search*",
"https://www.google.sr/search*",
"https://www.google.st/search*",
"https://www.google.com.sv/search*",
"https://www.google.td/search*",
"https://www.google.tg/search*",
"https://www.google.co.th/search*",
"https://www.google.com.tj/search*",
"https://www.google.tl/search*",
"https://www.google.tm/search*",
"https://www.google.tn/search*",
"https://www.google.to/search*",
"https://www.google.com.tr/search*",
"https://www.google.tt/search*",
"https://www.google.com.tw/search*",
"https://www.google.co.tz/search*",
"https://www.google.com.ua/search*",
"https://www.google.co.ug/search*",
"https://www.google.co.uk/search*",
"https://www.google.com.uy/search*",
"https://www.google.co.uz/search*",
"https://www.google.com.vc/search*",
"https://www.google.co.ve/search*",
"https://www.google.vg/search*",
"https://www.google.co.vi/search*",
"https://www.google.com.vn/search*",
"https://www.google.vu/search*",
"https://www.google.ws/search*",
"https://www.google.rs/search*",
"https://www.google.co.za/search*",
"https://www.google.co.zm/search*",
"https://www.google.co.zw/search*",
"https://www.google.cat/search*"
],
qwant: [
"https://*.qwant.com/*"
],
startpage: [
"https://*.startpage.com/*"
],
yahoo: [
"https://*.search.yahoo.com/*"
],
yandex: [
"https://*.ya.ru/*",
"https://*.yandex.az/*",
"https://*.yandex.by/*",
"https://*.yandex.co.il/*",
"https://*.yandex.com.am/*",
"https://*.yandex.com.ge/*",
"https://*.yandex.com.tr/*",
"https://*.yandex.com/*",
"https://*.yandex.ee/*",
"https://*.yandex.eu/*",
"https://*.yandex.fr/*",
"https://*.yandex.kz/*",
"https://*.yandex.lt/*",
"https://*.yandex.lv/*",
"https://*.yandex.md/*",
"https://*.yandex.ru/*",
"https://*.yandex.tj/*",
"https://*.yandex.tm/*",
"https://*.yandex.uz/*"
]
};
function commonFunctionRequestSearchEngineAccess(searchEngine) {
chrome.permissions.request({
origins: searchEngineOrigins[searchEngine]
}, (granted) => {
// Callback is true if the user granted the permissions.
if (!granted) {
document.querySelector(`[data-search-engine="${searchEngine}"`).checked = false;
return false;
}
chrome.scripting.registerContentScripts([{
id: `content-search-filtering-${searchEngine}`,
matches: searchEngineOrigins[searchEngine],
js: ['/scripts/common-functions.js', '/scripts/content-search-filtering.js'],
runAt: "document_start"
}]);
});
}
function commonFunctionRemoveSearchEngineAccess(searchEngine) {
chrome.permissions.remove({
origins: searchEngineOrigins[searchEngine]
});
}

View File

@ -1,167 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<link rel="icon" href="../../images/logo.png" />
<title>Indie Wiki Buddy Search Engine Update</title>
<style>
/* ELEMENTS */
body {
max-width: 700px;
margin: 0 auto;
padding: 20px;
background-color: #2b2a33;
font-family: Helvetica, Sans-Serif;
font-size: .9em;
}
a {
text-decoration-style: dotted;
text-decoration-thickness: 1px;
color: #005799;
}
a:visited {
color: #005799;
}
hr {
height: 1px;
border: none;
color: #005799;
background-color: #005799;
margin: .5em 0px;
}
h1 {
font-size: 1.3rem;
padding: .5em 0;
margin: 0;
}
h2 {
font-size: 1.2rem;
text-align: center;
padding: .5em 0 0 0;
margin: 0;
}
p {
padding: 1em;
margin: 0;
}
ul {
list-style-type: none;
margin: 1em 1em 1em -.5em;
}
.container {
background: #fff;
}
/* HEADER */
#header {
text-align: center;
line-height: 1.5em;
padding: .5em 1em;
box-sizing: border-box;
background-color: #005799;
color: #fff;
width: 100%;
}
#links {
background-color: #e5f4ff;
padding: .5em 1em;
}
/* CONTENT */
#content {
background-color: #fff;
box-sizing: border-box;
padding-bottom: 1.5em;
}
.gallery {
width: fit-content;
margin: 0 auto;
display: flex;
flex-direction: row;
gap: 2em;
padding: 1em;
text-align: center;
}
.gallery div {
border: 2px solid #005799;
border-radius: 5px;
padding: 1em;
}
.gallery img {
padding-bottom: 1em;
}
.gallery span {
font-weight: 600;
}
@media (max-width: 500px) {
.gallery {
flex-direction: column;
}
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<h1>Indie Wiki Buddy</h1>
<h1>Search Engine Permissions Change!</h1>
</div>
<div id="content">
<p>
Apologies for this one-time notice, but it's important!
</p>
<div class="gallery">
<div>
<img src="../../images/search-engines-opt-out.png" alt="Google, Bing, and DuckDuckGo" height="150">
<br />
<span>
Enabled by default
</span>
</div>
<div>
<img src="../../images/search-engines-opt-in.png" alt="Yahoo, Brave, Ecosia, Startpage, Qwant, Kagi, and Yandex" height="150">
<br />
<span>
Disabled and opt-in
</span>
</div>
</div>
<p>
Starting with version 3.7.0,
<b>Indie Wiki Buddy now only has permission to filter search results on
Google, Bing, and DuckDuckGo by-default</b>.
<br /><br />
If you would like to re-enable Indie Wiki Buddy's search filtering on any other search engines
(that includes Yahoo!, Brave, Ecosia, Startpage, Qwant, Kagi, and Yandex),
or if you would like to disable Indie Wiki Buddy's access to Google, Bing, or DuckDuckGo,
you can do so on the <b><a href="../settings/index.html">settings page</a></b>.
<br /><br />
This change is being done to be more privacy-friendly.
Indie Wiki Buddy now supports 10 search engines, but most users only use one or two,
so it makes sense to have most search engines be opt-in.
<br /><br />
In addition, when we add support for more search engines in future updates,
you won't have to deal with those annoying requests for new permissions
since they will be opt-in!
<br /><br />
As always, if you have any questions, don't hesitate to
<a href="https://getindie.wiki/#contact">get in touch</a>. Thank you!
</p>
</div>
</div>
</body>
</html>

View File

@ -110,14 +110,6 @@
indie English wikis when no same-language wiki exists
</label>
</div>
<div class="settingToggle">
<label>
<input id="reorderResultsCheckbox" type="checkbox" />
<img src="../../images/toggle-replace.png" height="12" alt="" />
Move indie wiki results to the top of
search results on Google
</label>
</div>
<div class="settingToggle">
<label>
<input id="openChangelogCheckbox" type="checkbox" />
@ -127,7 +119,7 @@
</div>
</fieldset>
<fieldset id="generalSettings">
<legend><span aria-hidden="true">🔍</span> Search engine settings</legend>
<legend><span aria-hidden="true">🔍</span> Search engine filtering settings</legend>
<div class="settingToggle searchEngineToggles">
<label>
<input id="googleCheckbox" data-search-engine="google" type="checkbox" />
@ -154,8 +146,8 @@
Kagi
</label>
<label>
<input id="qwuantCheckbox" data-search-engine="qwant" type="checkbox" />
Qwuant
<input id="qwantCheckbox" data-search-engine="qwant" type="checkbox" />
Qwant
</label>
<label>
<input id="startpageCheckbox" data-search-engine="startpage" type="checkbox" />
@ -170,6 +162,15 @@
Yandex
</label>
</div>
<hr>
<div class="settingToggle">
<label>
<input id="reorderResultsCheckbox" type="checkbox" />
<img src="../../images/toggle-replace.png" height="12" alt="" />
Move indie wiki results to the top of
search results on Google
</label>
</div>
</fieldset>
<fieldset id="breezewikiSettings">
<legend>
@ -395,7 +396,7 @@
</div>
</body>
<script type="text/javascript" src="../../scripts/common-functions.js"></script>
<script type="text/javascript" src="../search-engine-permissions.js"></script>
<script type="text/javascript" src="../../scripts/common-search-permissions.js"></script>
<script type="text/javascript" src="../common-page-functions.js"></script>
<script type="text/javascript" src="settings.js"></script>

View File

@ -35,8 +35,8 @@ async function loadOptions(lang, textFilter = '') {
site.destination_base_url.toLowerCase().includes(textFilter))
));
chrome.storage.local.get((localStorage) => {
chrome.storage.sync.get(async (syncStorage) => {
extensionAPI.storage.local.get((localStorage) => {
extensionAPI.storage.sync.get(async (syncStorage) => {
const storage = { ...syncStorage, ...localStorage };
let wikiSettings = await commonFunctionDecompressJSON(storage.wikiSettings || {});
let searchEngineSettings = await commonFunctionDecompressJSON(storage.searchEngineSettings || {});
@ -44,7 +44,7 @@ async function loadOptions(lang, textFilter = '') {
let defaultSearchAction = storage.defaultSearchAction || null;
// Load defaults for newly added wikis:
chrome.storage.sync.get(['defaultWikiAction'], (item) => {
extensionAPI.storage.sync.get(['defaultWikiAction'], (item) => {
if (item.defaultWikiAction === 'disabled') {
document.options.defaultWikiAction.value = 'disabled';
} else if (item.defaultWikiAction === 'redirect') {
@ -53,7 +53,7 @@ async function loadOptions(lang, textFilter = '') {
document.options.defaultWikiAction.value = 'alert';
}
});
chrome.storage.sync.get(['defaultSearchAction'], (item) => {
extensionAPI.storage.sync.get(['defaultSearchAction'], (item) => {
if (item.defaultSearchAction === 'disabled') {
document.options.defaultSearchAction.value = 'disabled';
} else if (item.defaultSearchAction === 'hide') {
@ -180,51 +180,51 @@ async function loadOptions(lang, textFilter = '') {
// Add listeners for when user clicks control:
inputDisabled.addEventListener('click', (input) => {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
var key = input.target.getAttribute('data-wiki-key');
wikiSettings[key] = 'disabled';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
});
inputAlert.addEventListener('click', (input) => {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
var key = input.target.getAttribute('data-wiki-key');
wikiSettings[key] = 'alert';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
});
inputRedirect.addEventListener('click', (input) => {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
var key = input.target.getAttribute('data-wiki-key');
wikiSettings[key] = 'redirect';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
});
inputSearchEngineDisabled.addEventListener('click', (input) => {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
let searchEngineSettings = await commonFunctionDecompressJSON(response.searchEngineSettings);
var key = input.target.getAttribute('data-wiki-key');
searchEngineSettings[key] = 'disabled';
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
extensionAPI.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
});
inputSearchEngineReplace.addEventListener('click', (input) => {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
let searchEngineSettings = await commonFunctionDecompressJSON(response.searchEngineSettings);
var key = input.target.getAttribute('data-wiki-key');
searchEngineSettings[key] = 'replace';
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
extensionAPI.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
});
inputSearchEngineHide.addEventListener('click', (input) => {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
let searchEngineSettings = await commonFunctionDecompressJSON(response.searchEngineSettings);
var key = input.target.getAttribute('data-wiki-key');
searchEngineSettings[key] = 'hide';
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
extensionAPI.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
});
@ -319,7 +319,7 @@ async function loadOptions(lang, textFilter = '') {
toggles[i].checked = true;
wikiSettings[toggles[i].getAttribute('data-wiki-key')] = 'redirect';
}
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
const setAllAlert = document.getElementById('setAllAlert');
@ -329,7 +329,7 @@ async function loadOptions(lang, textFilter = '') {
toggles[i].checked = true;
wikiSettings[toggles[i].getAttribute('data-wiki-key')] = 'alert';
}
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
const setAllDisabled = document.getElementById('setAllDisabled');
@ -339,7 +339,7 @@ async function loadOptions(lang, textFilter = '') {
toggles[i].checked = true;
wikiSettings[toggles[i].getAttribute('data-wiki-key')] = 'disabled';
}
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
const setAllSearchEngineDisabled = document.getElementById('setAllSearchEngineDisabled');
@ -349,7 +349,7 @@ async function loadOptions(lang, textFilter = '') {
toggles[i].checked = true;
searchEngineSettings[toggles[i].getAttribute('data-wiki-key')] = 'disabled';
}
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
extensionAPI.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
const setAllSearchEngineHide = document.getElementById('setAllSearchEngineHide');
@ -359,7 +359,7 @@ async function loadOptions(lang, textFilter = '') {
toggles[i].checked = true;
searchEngineSettings[toggles[i].getAttribute('data-wiki-key')] = 'hide';
}
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
extensionAPI.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
const setAllSearchEngineReplace = document.getElementById('setAllSearchEngineReplace');
@ -369,7 +369,7 @@ async function loadOptions(lang, textFilter = '') {
toggles[i].checked = true;
searchEngineSettings[toggles[i].getAttribute('data-wiki-key')] = 'replace';
}
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
extensionAPI.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
});
});
@ -396,13 +396,23 @@ function displayCustomSearchEngine(customSearchEngineHostname, customSearchEngin
customSearchEngineDeleteButton.addEventListener('click', () => {
listItem.remove();
chrome.storage.sync.get({ 'customSearchEngines': {} }, (item) => {
extensionAPI.storage.sync.get({ 'customSearchEngines': {} }, (item) => {
let customSearchEngines = item.customSearchEngines;
delete customSearchEngines[customSearchEngineHostname];
chrome.storage.sync.set({ 'customSearchEngines': customSearchEngines });
extensionAPI.storage.sync.set({ 'customSearchEngines': customSearchEngines });
});
chrome.scripting.unregisterContentScripts({ ids: [`content-search-filtering-${customSearchEngineHostname}`] });
let customSearchEngine = customSearchEngineHostname;
// Add "https://" if not already present
if (!customSearchEngine.includes('://')) {
customSearchEngine = 'https://' + customSearchEngine;
}
customSearchEngine = new URL(customSearchEngine);
extensionAPI.permissions.remove({
origins: [ `${customSearchEngine}*` ]
});
extensionAPI.scripting.unregisterContentScripts({ ids: [`content-search-filtering-${customSearchEngineHostname}`] });
});
listItem.appendChild(customSearchEngineHostnameLabel);
@ -415,7 +425,7 @@ function displayCustomSearchEngine(customSearchEngineHostname, customSearchEngin
// Set power setting
function setPower(setting, storeSetting = true) {
if (storeSetting) {
chrome.storage.local.set({ 'power': setting });
extensionAPI.storage.local.set({ 'power': setting });
}
const powerText = document.getElementById('powerText');
powerText.textContent = 'Extension is ' + setting;
@ -428,7 +438,7 @@ function setPower(setting, storeSetting = true) {
powerIcon.innerText = '🪫';
}
chrome.runtime.sendMessage({
extensionAPI.runtime.sendMessage({
action: 'updateIcon',
value: setting
});
@ -448,12 +458,12 @@ document.addEventListener('DOMContentLoaded', () => {
// If running Opera, show note about search engine access
if (navigator.userAgent.match(/OPR\//)) {
const notificationBannerOpera = document.getElementById('notificationBannerOpera');
chrome.storage.local.get({ 'hideOperaPermissionsNote': false }, (item) => {
extensionAPI.storage.local.get({ 'hideOperaPermissionsNote': false }, (item) => {
if (!item.hideOperaPermissionsNote) {
notificationBannerOpera.style.display = 'block';
document.getElementById('operaPermsHideLink').addEventListener('click', () => {
chrome.storage.local.set({ 'hideOperaPermissionsNote': true });
extensionAPI.storage.local.set({ 'hideOperaPermissionsNote': true });
notificationBannerOpera.style.display = 'none';
});
}
@ -462,13 +472,13 @@ document.addEventListener('DOMContentLoaded', () => {
// Count number of times settings have been opened
// Purposefully using local storage instead of sync
chrome.storage.local.get({ 'countSettingsOpened': 0 }, (item) => {
extensionAPI.storage.local.get({ 'countSettingsOpened': 0 }, (item) => {
const countSettingsOpened = item.countSettingsOpened;
chrome.storage.local.set({ 'countSettingsOpened': countSettingsOpened + 1 });
extensionAPI.storage.local.set({ 'countSettingsOpened': countSettingsOpened + 1 });
// Show review reminder every 5 opens,
// and if the banner hasn't been previously dismissed
chrome.storage.local.get({ 'hideReviewReminder': false }, (item) => {
extensionAPI.storage.local.get({ 'hideReviewReminder': false }, (item) => {
if (!item.hideReviewReminder && ((countSettingsOpened - 1) % 5 === 0)) {
const notificationBannerReview = document.getElementById('notificationBannerReview');
@ -477,13 +487,13 @@ document.addEventListener('DOMContentLoaded', () => {
// Disable future review reminders if user clicks links:
document.getElementById('reviewReminderChromeLink').addEventListener('click', () => {
chrome.storage.local.set({ 'hideReviewReminder': true });
extensionAPI.storage.local.set({ 'hideReviewReminder': true });
});
document.getElementById('reviewReminderFirefoxLink').addEventListener('click', () => {
chrome.storage.local.set({ 'hideReviewReminder': true });
extensionAPI.storage.local.set({ 'hideReviewReminder': true });
});
document.getElementById('reviewReminderHideLink').addEventListener('click', () => {
chrome.storage.local.set({ 'hideReviewReminder': true });
extensionAPI.storage.local.set({ 'hideReviewReminder': true });
notificationBannerReview.style.display = 'none';
});
}
@ -491,11 +501,11 @@ document.addEventListener('DOMContentLoaded', () => {
});
// Adding version to popup:
const version = chrome.runtime.getManifest().version;
const version = extensionAPI.runtime.getManifest().version;
document.getElementById('version').textContent = 'v' + version;
// Get user's last set language
chrome.storage.sync.get({ 'lang': 'EN' }, (item) => {
extensionAPI.storage.sync.get({ 'lang': 'EN' }, (item) => {
langSelect.value = item.lang;
const filterInput = document.getElementById('filterInput').value;
loadOptions(item.lang, filterInput);
@ -503,7 +513,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Add event listener for language select
const langSelect = document.getElementById("langSelect");
langSelect.addEventListener('change', () => {
chrome.storage.sync.set({ 'lang': langSelect.value });
extensionAPI.storage.sync.set({ 'lang': langSelect.value });
const filterInput = document.getElementById('filterInput').value;
loadOptions(langSelect.value, filterInput);
});
@ -517,7 +527,7 @@ document.addEventListener('DOMContentLoaded', () => {
} else {
document.getElementById('breezewikiCustomHost').style.display = 'none';
}
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
extensionAPI.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
});
function setCustomBreezewikiDomain() {
@ -531,18 +541,18 @@ document.addEventListener('DOMContentLoaded', () => {
breezewikiCustomDomain = breezewikiCustomDomain.protocol + "//" + breezewikiCustomDomain.hostname
breezewikiCustomDomain = breezewikiCustomDomain.toString();
chrome.permissions.request({
extensionAPI.permissions.request({
origins: [breezewikiCustomDomain + '/*']
}, (granted) => {
// The callback argument will be true if the user granted the permissions.
if (granted) {
chrome.scripting.registerContentScripts([{
extensionAPI.scripting.registerContentScripts([{
id: 'content-banners',
matches: [breezewikiCustomDomain + '/*'],
js: ['/scripts/common-functions.js', '/scripts/content-banners.js', '/scripts/content-breezewiki.js'],
runAt: "document_idle"
}]);
chrome.storage.sync.set({ 'breezewikiCustomHost': breezewikiCustomDomain });
extensionAPI.storage.sync.set({ 'breezewikiCustomHost': breezewikiCustomDomain });
document.getElementById('breezewikiCustomHostStatus').innerText = 'Successfully added';
} else {
document.getElementById('breezewikiCustomHostStatus').innerText = 'Failed to set host';
@ -581,25 +591,29 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
chrome.permissions.request({
extensionAPI.permissions.request({
origins: [ `${customSearchEngine}*` ]
}, (granted) => {
// Callback is true if the user granted the permissions.
if (!granted) return;
chrome.scripting.registerContentScripts([{
id: `content-search-filtering-${customSearchEngine.hostname}`,
matches: [customSearchEngine + '*'],
js: [ '/scripts/common-functions.js', '/scripts/content-search-filtering.js' ],
runAt: "document_start"
}]);
try {
extensionAPI.scripting.registerContentScripts([{
id: `content-search-filtering-${customSearchEngine.hostname}`,
matches: [customSearchEngine + '*'],
js: [ '/scripts/common-functions.js', '/scripts/content-search-filtering.js' ],
runAt: "document_start"
}]);
} catch(e) {
(`Could not register content script for ${customSearchEngine}.`)
}
let customSearchEnginePreset = document.getElementById('newCustomSearchEnginePreset').value;
chrome.storage.sync.get({ 'customSearchEngines': {} }, (item) => {
extensionAPI.storage.sync.get({ 'customSearchEngines': {} }, (item) => {
let customSearchEngines = item.customSearchEngines;
customSearchEngines[customSearchEngine.hostname] = customSearchEnginePreset;
chrome.storage.sync.set({ 'customSearchEngines': customSearchEngines });
extensionAPI.storage.sync.set({ 'customSearchEngines': customSearchEngines });
});
displayCustomSearchEngine(customSearchEngine.hostname, customSearchEnginePreset);
@ -617,7 +631,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
chrome.storage.sync.get({ 'customSearchEngines': {} }, (item) => {
extensionAPI.storage.sync.get({ 'customSearchEngines': {} }, (item) => {
Object.keys(item.customSearchEngines).forEach((key) => {
displayCustomSearchEngine(key, item.customSearchEngines[key]);
});
@ -626,12 +640,12 @@ document.addEventListener('DOMContentLoaded', () => {
// Add event listeners for default action selections
document.querySelectorAll('[name="defaultWikiAction"]').forEach((el) => {
el.addEventListener('change', () => {
chrome.storage.sync.set({ 'defaultWikiAction': document.options.defaultWikiAction.value })
extensionAPI.storage.sync.set({ 'defaultWikiAction': document.options.defaultWikiAction.value })
});
});
document.querySelectorAll('[name="defaultSearchAction"]').forEach((el) => {
el.addEventListener('change', () => {
chrome.storage.sync.set({ 'defaultSearchAction': document.options.defaultSearchAction.value })
extensionAPI.storage.sync.set({ 'defaultSearchAction': document.options.defaultSearchAction.value })
});
});
@ -642,19 +656,19 @@ document.addEventListener('DOMContentLoaded', () => {
});
// Get and display stat counts
chrome.storage.sync.get({ 'countAlerts': 0 }, (item) => {
extensionAPI.storage.sync.get({ 'countAlerts': 0 }, (item) => {
var key = Object.keys(item)[0];
document.getElementById('countAlerts').textContent = item[key];
});
chrome.storage.sync.get({ 'countRedirects': 0 }, (item) => {
extensionAPI.storage.sync.get({ 'countRedirects': 0 }, (item) => {
var key = Object.keys(item)[0];
document.getElementById('countRedirects').textContent = item[key];
});
chrome.storage.sync.get({ 'countSearchFilters': 0 }, (item) => {
extensionAPI.storage.sync.get({ 'countSearchFilters': 0 }, (item) => {
var key = Object.keys(item)[0];
document.getElementById('countSearchFilters').textContent = item[key];
});
chrome.storage.sync.get({ 'countBreezeWiki': 0 }, (item) => {
extensionAPI.storage.sync.get({ 'countBreezeWiki': 0 }, (item) => {
var key = Object.keys(item)[0];
document.getElementById('countBreezeWiki').textContent = item[key];
});

View File

@ -1,5 +1,6 @@
var LANGS = ["DE", "EN", "ES", "FI", "FR", "HU", "IT", "JA", "LZH", "KO", "PL", "PT", "RU", "TH", "TOK", "UK", "ZH"];
var BASE64REGEX = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
const extensionAPI = typeof browser === "undefined" ? chrome : browser;
function b64decode(str) {
const binary_string = atob(str);
@ -61,7 +62,7 @@ async function commonFunctionGetSiteDataByDestination() {
var sites = [];
let promises = [];
for (let i = 0; i < LANGS.length; i++) {
promises.push(fetch(chrome.runtime.getURL('data/sites' + LANGS[i] + '.json'))
promises.push(fetch(extensionAPI.runtime.getURL('data/sites' + LANGS[i] + '.json'))
.then((resp) => resp.json())
.then((jsonData) => {
jsonData.forEach((site) => site.language = LANGS[i]);
@ -77,7 +78,7 @@ async function populateSiteDataByOrigin() {
let sites = [];
let promises = [];
for (let i = 0; i < LANGS.length; i++) {
promises.push(fetch(chrome.runtime.getURL('data/sites' + LANGS[i] + '.json'))
promises.push(fetch(extensionAPI.runtime.getURL('data/sites' + LANGS[i] + '.json'))
.then((resp) => resp.json())
.then((jsonData) => {
jsonData.forEach((site) => {
@ -211,7 +212,7 @@ function commonFunctionGetNewURL(originURL, matchingSite) {
// Temporary function to migrate user data to IWB version 3.0+
async function commonFunctionMigrateToV3() {
await chrome.storage.sync.get(async (storage) => {
await extensionAPI.storage.sync.get(async (storage) => {
if (!storage.v3migration) {
let defaultWikiAction = storage.defaultWikiAction || 'alert';
let defaultSearchAction = storage.defaultSearchAction || 'replace';
@ -221,7 +222,7 @@ async function commonFunctionMigrateToV3() {
if (storage.defaultActionSettings && storage.defaultActionSettings['EN']) {
defaultWikiAction = storage.defaultActionSettings['EN'];
}
chrome.storage.sync.set({ 'defaultWikiAction': defaultWikiAction });
extensionAPI.storage.sync.set({ 'defaultWikiAction': defaultWikiAction });
}
if (!storage.defaultSearchAction) {
if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings['EN']) {
@ -231,12 +232,12 @@ async function commonFunctionMigrateToV3() {
defaultSearchAction = 'replace';
}
}
chrome.storage.sync.set({ 'defaultSearchAction': defaultSearchAction });
extensionAPI.storage.sync.set({ 'defaultSearchAction': defaultSearchAction });
}
// Remove old objects:
chrome.storage.sync.remove('defaultActionSettings');
chrome.storage.sync.remove('defaultSearchFilterSettings');
extensionAPI.storage.sync.remove('defaultActionSettings');
extensionAPI.storage.sync.remove('defaultSearchFilterSettings');
// Migrate wiki settings to new searchEngineSettings and wikiSettings objects
sites = await commonFunctionGetSiteDataByOrigin();
@ -262,14 +263,14 @@ async function commonFunctionMigrateToV3() {
}
});
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
// Remove old object:
chrome.storage.sync.remove('siteSettings');
extensionAPI.storage.sync.remove('siteSettings');
// Mark v3 migration as complete:
chrome.storage.sync.set({ 'v3migration': 'done' });
extensionAPI.storage.sync.set({ 'v3migration': 'done' });
}
});
}

View File

@ -102,7 +102,7 @@ function processBreezeWikiBanner(storage) {
throw new Error('Indie Wiki Buddy failed to get BreezeWiki data.');
}).then((breezewikiHosts) => {
breezewikiHosts = breezewikiHosts.filter(host =>
chrome.runtime.getManifest().version.localeCompare(host.iwb_version,
extensionAPI.runtime.getManifest().version.localeCompare(host.iwb_version,
undefined,
{ numeric: true, sensitivity: 'base' }
) >= 0
@ -110,21 +110,21 @@ function processBreezeWikiBanner(storage) {
// Check if BreezeWiki's main site is available
let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com');
if (breezewikiMain.length > 0) {
chrome.storage.sync.set({ 'breezewikiHost': breezewikiMain[0].instance });
extensionAPI.storage.sync.set({ 'breezewikiHost': breezewikiMain[0].instance });
} else {
// If BreezeWiki.com is not available, set to a random mirror
try {
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance });
extensionAPI.storage.sync.set({ 'breezewikiHost': breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance });
} catch (e) {
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
}
}
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
extensionAPI.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
extensionAPI.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
breezewikiHost = host;
}).catch((e) => {
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
chrome.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
extensionAPI.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
});
} else {
if (storage.breezewikiHost === 'CUSTOM') {
@ -198,10 +198,10 @@ function displayRedirectBanner(newUrl, id, destinationName, destinationLanguage,
bannerRestoreLink.textContent = '⎌ Restore banner';
bannerControls.appendChild(bannerRestoreLink);
bannerRestoreLink.onclick = function (e) {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
wikiSettings[id] = 'alert';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
e.target.textContent = '✓ Banner restored';
e.target.classList.add('indie-wiki-banner-disabled');
bannerControls.querySelector('.indie-wiki-banner-redirect').textContent = '↪ Auto redirect this wiki';
@ -220,10 +220,10 @@ function displayRedirectBanner(newUrl, id, destinationName, destinationLanguage,
bannerDisableLink.textContent = '✕ Disable banner for this wiki';
bannerControls.appendChild(bannerDisableLink);
bannerDisableLink.onclick = function (e) {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
wikiSettings[id] = 'disabled';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
e.target.textContent = '✓ Banner disabled';
e.target.classList.add('indie-wiki-banner-disabled');
bannerControls.querySelector('.indie-wiki-banner-restore').textContent = '⎌ Restore banner';
@ -240,10 +240,10 @@ function displayRedirectBanner(newUrl, id, destinationName, destinationLanguage,
bannerRedirectLink.textContent = '↪ Auto redirect this wiki';
bannerControls.appendChild(bannerRedirectLink);
bannerRedirectLink.onclick = function (e) {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
extensionAPI.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
wikiSettings[id] = 'redirect';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
extensionAPI.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
e.target.textContent = '✓ Redirect enabled';
e.target.classList.add('indie-wiki-banner-disabled');
bannerControls.querySelector('.indie-wiki-banner-disable').classList.add('indie-wiki-banner-hidden');
@ -290,10 +290,10 @@ function displayRedirectBanner(newUrl, id, destinationName, destinationLanguage,
// Increment banner count
if (storage.breezewiki === 'on') {
if (currentURL.hostname.match(breezewikiRegex) || (storage.breezewikiHost === 'CUSTOM' && storage.breezewikiCustomHost?.includes(currentURL.hostname))) {
chrome.storage.sync.set({ 'countAlerts': (storage.countAlerts ?? 0) + 1 });
extensionAPI.storage.sync.set({ 'countAlerts': (storage.countAlerts ?? 0) + 1 });
}
} else {
chrome.storage.sync.set({ 'countAlerts': (storage.countAlerts ?? 0) + 1 });
extensionAPI.storage.sync.set({ 'countAlerts': (storage.countAlerts ?? 0) + 1 });
}
// Hide duplicative indie wiki notice on BreezeWiki instances
@ -315,7 +315,7 @@ function displayRedirectBanner(newUrl, id, destinationName, destinationLanguage,
}
function main() {
chrome.runtime.sendMessage({action: 'getStorage'}).then((storage) => {
extensionAPI.runtime.sendMessage({action: 'getStorage'}, (storage) => {
// Check if extension is on:
if ((storage.power ?? 'on') === 'on') {
// Check if there is a pathname, to ensure we're looking at an article

View File

@ -183,7 +183,7 @@ function replaceSearchResults(searchResultContainer, site, link) {
indieResultFavicon.alt = '';
indieResultFavicon.width = '12';
indieResultFavicon.height = '12';
indieResultFavicon.src = chrome.runtime.getURL('favicons/' + site.language.toLowerCase() + '/' + site.destination_icon);
indieResultFavicon.src = extensionAPI.runtime.getURL('favicons/' + site.language.toLowerCase() + '/' + site.destination_icon);
indieResultFaviconContainer.append(indieResultFavicon);
let indieResultText = document.createElement('span');
if (originArticle && originArticle !== site['origin_main_page']) {
@ -623,19 +623,19 @@ async function filterSearchResults(searchResults, searchEngine, storage, reorder
// If any results were filtered, update search filter count
if (countFiltered > 0) {
chrome.storage.sync.set({ 'countSearchFilters': (storage.countSearchFilters ?? 0) + countFiltered });
extensionAPI.storage.sync.set({ 'countSearchFilters': (storage.countSearchFilters ?? 0) + countFiltered });
}
}
function main(mutations = null, observer = null) {
function main(searchEngine, storage, mutations = null, observer = null) {
if (observer) {
observer.disconnect();
}
chrome.runtime.sendMessage({action: 'getStorage'}).then((storage) => {
// Check if extension is on:
if ((storage.power ?? 'on') === 'on') {
// Determine which search engine we're on
if (currentURL.hostname.includes('www.google.')) {
// Check if extension is on:
if ((storage.power ?? 'on') === 'on') {
// Determine which search engine we're on
switch (searchEngine) {
case 'google':
// Function to filter search results in Google
function filterGoogle(reorderedHrefs) {
let searchResults = document.querySelectorAll(`
@ -654,7 +654,8 @@ function main(mutations = null, observer = null) {
// Filtering happens after re-ordering, so that we can filter anything that matches what we re-ordered
filterGoogle(r);
});
} else if (currentURL.hostname.includes('duckduckgo.com') && (currentURL.search.includes('q=') || currentURL.pathname.includes('html'))) {
break;
case 'duckduckgo':
// Function to filter search results in DuckDuckGo
function filterDuckDuckGo() {
let searchResults = document.querySelectorAll('h2>a[href*=".fandom.com"], h2>a[href*=".wiki.fextralife.com"], h2>a[href*=".neoseeker.com/wiki/"]');
@ -662,7 +663,8 @@ function main(mutations = null, observer = null) {
}
filterDuckDuckGo();
} else if (currentURL.hostname.endsWith('.bing.com')) {
break;
case 'bing':
// Function to filter search results in Bing
function filterBing() {
let searchResultsEncoded = document.querySelectorAll('li.b_algo h2 a, li.b_algo .b_algoheader a');
@ -690,7 +692,8 @@ function main(mutations = null, observer = null) {
}
filterBing();
} else if (currentURL.hostname.includes('search.brave.com')) {
break;
case 'brave':
// Function to filter search results in Brave
function filterBrave() {
let searchResults = Array.from(document.querySelectorAll('div.snippet[data-type="web"] a')).filter(el =>
@ -701,7 +704,8 @@ function main(mutations = null, observer = null) {
}
filterBrave();
} else if (currentURL.hostname.includes('ecosia.org')) {
break;
case 'ecosia':
// Function to filter search results in Ecosia
function filterEcosia() {
let searchResults = Array.from(document.querySelectorAll('section.mainline .result__title a.result__link')).filter(el =>
@ -712,7 +716,8 @@ function main(mutations = null, observer = null) {
}
filterEcosia();
} else if (currentURL.hostname.includes('qwant.com')) {
break;
case 'qwant':
// Function to filter search results in Qwant
function filterQwant() {
let searchResults = Array.from(document.querySelectorAll('a[data-testid=serTitle]')).filter(el => el.href.includes('fandom.com') || el.href.includes('fextralife.com'));
@ -720,7 +725,8 @@ function main(mutations = null, observer = null) {
}
filterQwant();
} else if (currentURL.hostname.includes('startpage.com')) {
break;
case 'startpage':
// Function to filter search results in Startpage
function filterStartpage() {
let searchResults = Array.from(document.querySelectorAll('a.result-link')).filter(el =>
@ -731,7 +737,8 @@ function main(mutations = null, observer = null) {
}
filterStartpage();
} else if (currentURL.hostname.includes('yandex.') || currentURL.hostname.includes('ya.ru')) {
break;
case 'yandex':
// Function to filter search results in Yandex
function filterYandex() {
let searchResults = Array.from(document.querySelectorAll('.serp-item a.link, .serp-item a.Link, .MMOrganicSnippet a, .viewer-snippet a')).filter(el =>
@ -742,7 +749,8 @@ function main(mutations = null, observer = null) {
}
filterYandex();
} else if (currentURL.hostname.includes('yahoo.com')) {
break;
case 'yahoo':
// Function to filter search results in Yahoo
function filterYahoo() {
let searchResultsEncoded = document.querySelectorAll('#web > ol > li a:not(.thmb), #main-algo section.algo a:not(.thmb)');
@ -773,7 +781,8 @@ function main(mutations = null, observer = null) {
}
filterYahoo();
} else if (currentURL.hostname.includes('kagi.com')) {
break;
case 'kagi':
// Function to filter search results in Kagi
function filterKagi() {
let searchResults = Array.from(document.querySelectorAll('h3>a, a.__sri-url')).filter(el =>
@ -784,39 +793,73 @@ function main(mutations = null, observer = null) {
}
filterKagi();
} else if (storage.customSearchEngines) {
function filterSearXNG() {
let searchResults = Array.from(document.querySelectorAll('h3>a')).filter(el =>
el.href?.includes('.fandom.com') ||
el.href?.includes('.wiki.fextralife.com') ||
el.href?.includes('.neoseeker.com/wiki/'));
filterSearchResults(searchResults, 'searxng', storage);
}
break;
default:
if (storage.customSearchEngines) {
function filterSearXNG() {
let searchResults = Array.from(document.querySelectorAll('h3>a')).filter(el =>
el.href?.includes('.fandom.com') ||
el.href?.includes('.wiki.fextralife.com') ||
el.href?.includes('.neoseeker.com/wiki/'));
filterSearchResults(searchResults, 'searxng', storage);
}
function filterWhoogle() {
let searchResults = Array.from(document.querySelectorAll('div>a')).filter(el =>
el.href?.includes('.fandom.com') ||
el.href?.includes('.wiki.fextralife.com') ||
el.href?.includes('.neoseeker.com/wiki/'));
filterSearchResults(searchResults, 'whoogle', storage);
}
function filterWhoogle() {
let searchResults = Array.from(document.querySelectorAll('div>a')).filter(el =>
el.href?.includes('.fandom.com') ||
el.href?.includes('.wiki.fextralife.com') ||
el.href?.includes('.neoseeker.com/wiki/'));
filterSearchResults(searchResults, 'whoogle', storage);
}
function filter(searchEngine) {
if (searchEngine === 'searxng') {
filterSearXNG();
} else if (searchEngine === 'whoogle') {
filterWhoogle();
function filter(searchEngine) {
if (searchEngine === 'searxng') {
filterSearXNG();
} else if (searchEngine === 'whoogle') {
filterWhoogle();
}
}
let customSearchEngines = storage.customSearchEngines;
if (customSearchEngines[currentURL.hostname]) {
let customSearchEnginePreset = customSearchEngines[currentURL.hostname];
filter(customSearchEnginePreset);
}
}
}
}
}
let customSearchEngines = storage.customSearchEngines;
if (customSearchEngines[currentURL.hostname]) {
let customSearchEnginePreset = customSearchEngines[currentURL.hostname];
filter(customSearchEnginePreset);
}
}
// Check if user has enabled filtering for the current search engine
// If so, call main function to start filtering process
function checkIfEnabled(searchEngine) {
extensionAPI.runtime.sendMessage({action: 'getStorage'}, (storage) => {
searchEngineToggles = storage.searchEngineToggles || {};
if (searchEngineToggles[searchEngine] === 'on' || !searchEngineToggles.hasOwnProperty(searchEngine)) {
main(searchEngine, storage);
}
});
}
main();
// Figure out which search engine we're on
if (currentURL.hostname.includes('www.google.')) {
checkIfEnabled('google');
} else if (currentURL.hostname.includes('duckduckgo.com') && (currentURL.search.includes('q=') || currentURL.pathname.includes('html'))) {
checkIfEnabled('duckduckgo');
} else if (currentURL.hostname.endsWith('.bing.com')) {
checkIfEnabled('bing');
} else if (currentURL.hostname.includes('search.brave.com')) {
checkIfEnabled('brave');
} else if (currentURL.hostname.includes('ecosia.org')) {
checkIfEnabled('ecosia');
} else if (currentURL.hostname.includes('qwant.com')) {
checkIfEnabled('qwant');
} else if (currentURL.hostname.includes('startpage.com')) {
checkIfEnabled('startpage');
} else if (currentURL.hostname.includes('yandex.') || currentURL.hostname.includes('ya.ru')) {
checkIfEnabled('yandex');
} else if (currentURL.hostname.includes('yahoo.com')) {
checkIfEnabled('yahoo');
} else if (currentURL.hostname.includes('kagi.com')) {
checkIfEnabled('kagi');
}