2023-09-18 03:46:56 +00:00
|
|
|
// Capture web requests
|
|
|
|
chrome.webRequest.onBeforeSendHeaders.addListener(
|
2023-12-13 10:10:55 +00:00
|
|
|
async (event) => {
|
2023-11-05 05:52:22 +00:00
|
|
|
if (event.documentLifecycle !== 'prerender') {
|
2023-11-27 08:14:00 +00:00
|
|
|
if (event.frameType === 'sub_frame') {
|
|
|
|
let tabInfo = await chrome.tabs.get(event.tabId);
|
|
|
|
main(tabInfo.url, event.tabId);
|
|
|
|
} else {
|
|
|
|
main(event.url, event.tabId);
|
|
|
|
}
|
2023-11-05 05:52:22 +00:00
|
|
|
}
|
2023-09-18 03:46:56 +00:00
|
|
|
},
|
2023-11-05 05:52:22 +00:00
|
|
|
{ urls: ['*://*.fandom.com/*', '*://*.wiki.fextralife.com/*'], types: ['main_frame', 'sub_frame'] }
|
2023-09-18 03:46:56 +00:00
|
|
|
);
|
2023-02-06 00:48:53 +00:00
|
|
|
|
2023-06-23 04:34:04 +00:00
|
|
|
// Listen for user turning extension on or off, to update icon
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
2023-09-18 03:46:56 +00:00
|
|
|
if (msg.action === 'updateIcon') {
|
2023-06-23 04:34:04 +00:00
|
|
|
setPowerIcon(msg.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Listen for browser starting, to set initial icon state
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.runtime.onStartup.addListener(() => {
|
|
|
|
chrome.storage.local.get({ 'power': 'on' }, (item) => {
|
2023-06-23 04:34:04 +00:00
|
|
|
setPowerIcon(item.power);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-09-18 09:05:46 +00:00
|
|
|
// Listen for extension installed/updating
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.runtime.onInstalled.addListener(async (detail) => {
|
2023-09-18 09:05:46 +00:00
|
|
|
// Set initial icon state
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.storage.local.get({ 'power': 'on' }, (item) => {
|
2023-06-23 04:34:04 +00:00
|
|
|
setPowerIcon(item.power);
|
|
|
|
});
|
2023-09-18 09:05:46 +00:00
|
|
|
|
|
|
|
// If new install, open settings with starter guide
|
|
|
|
if (detail.reason === 'install') {
|
|
|
|
chrome.tabs.create({ url: 'settings.html?newinstall=true' });
|
|
|
|
}
|
2023-10-16 06:08:08 +00:00
|
|
|
|
2023-11-16 10:07:24 +00:00
|
|
|
// If update, open changelog if setting is enabled
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.storage.sync.get({ 'openChangelog': 'off' }, (item) => {
|
2023-11-16 10:07:24 +00:00
|
|
|
if (item.openChangelog === 'on' && detail.reason === 'update') {
|
2023-11-27 08:19:14 +00:00
|
|
|
chrome.tabs.create({ url: 'https://getindie.wiki/changelog/?updated=true', active: false });
|
2023-11-16 10:07:24 +00:00
|
|
|
}
|
|
|
|
});
|
2023-11-04 07:54:41 +00:00
|
|
|
|
|
|
|
// Temporary functions for 3.0 migration
|
2023-11-02 08:12:35 +00:00
|
|
|
if (detail.reason === 'update') {
|
2023-11-06 04:52:35 +00:00
|
|
|
await chrome.storage.sync.get(async (storage) => {
|
|
|
|
if (!storage.v3migration) {
|
2023-11-06 06:21:03 +00:00
|
|
|
let defaultWikiAction = storage.defaultWikiAction || 'alert';
|
|
|
|
let defaultSearchAction = storage.defaultSearchAction || 'replace';
|
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
// Set new default action settings:
|
|
|
|
if (!storage.defaultWikiAction) {
|
|
|
|
if (storage.defaultActionSettings && storage.defaultActionSettings['EN']) {
|
2023-11-06 06:21:03 +00:00
|
|
|
defaultWikiAction = storage.defaultActionSettings['EN'];
|
2023-11-02 08:12:35 +00:00
|
|
|
}
|
2023-11-06 06:21:03 +00:00
|
|
|
chrome.storage.sync.set({ 'defaultWikiAction': defaultWikiAction });
|
2023-11-06 04:52:35 +00:00
|
|
|
}
|
|
|
|
if (!storage.defaultSearchAction) {
|
|
|
|
if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings['EN']) {
|
|
|
|
if (storage.defaultSearchFilterSettings['EN'] === 'false') {
|
2023-11-06 06:21:03 +00:00
|
|
|
defaultSearchAction = 'disabled';
|
2023-11-06 04:52:35 +00:00
|
|
|
} else {
|
2023-11-06 06:21:03 +00:00
|
|
|
defaultSearchAction = 'replace';
|
2023-11-02 08:12:35 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-06 06:21:03 +00:00
|
|
|
chrome.storage.sync.set({ 'defaultSearchAction': defaultSearchAction });
|
2023-11-06 04:52:35 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 06:21:03 +00:00
|
|
|
// Remove old objects:
|
2023-11-06 04:52:35 +00:00
|
|
|
chrome.storage.sync.remove('defaultActionSettings');
|
|
|
|
chrome.storage.sync.remove('defaultSearchFilterSettings');
|
2023-11-06 06:21:03 +00:00
|
|
|
|
2023-11-06 04:52:35 +00:00
|
|
|
// Migrate wiki settings to new searchEngineSettings and wikiSettings objects
|
|
|
|
sites = await getData();
|
|
|
|
let siteSettings = storage.siteSettings || {};
|
|
|
|
let searchEngineSettings = storage.searchEngineSettings || {};
|
|
|
|
let wikiSettings = storage.wikiSettings || {};
|
|
|
|
|
|
|
|
sites.forEach((site) => {
|
|
|
|
if (!searchEngineSettings[site.id]) {
|
|
|
|
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
|
|
|
|
if (siteSettings[site.id].searchFilter === 'false') {
|
|
|
|
searchEngineSettings[site.id] = 'disabled';
|
|
|
|
} else {
|
|
|
|
searchEngineSettings[site.id] = 'replace';
|
|
|
|
}
|
2023-11-04 07:54:41 +00:00
|
|
|
} else {
|
2023-11-06 04:52:35 +00:00
|
|
|
searchEngineSettings[site.id] = defaultSearchAction;
|
2023-11-04 07:54:41 +00:00
|
|
|
}
|
2023-11-03 09:20:57 +00:00
|
|
|
}
|
2023-11-06 04:52:35 +00:00
|
|
|
|
|
|
|
if (!wikiSettings[site.id]) {
|
|
|
|
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
|
|
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
|
|
|
|
2023-11-06 06:21:03 +00:00
|
|
|
// Remove old object:
|
2023-11-06 04:52:35 +00:00
|
|
|
chrome.storage.sync.remove('siteSettings');
|
|
|
|
|
|
|
|
// Mark v3 migration as complete:
|
|
|
|
chrome.storage.sync.set({ 'v3migration': 'done' });
|
|
|
|
}
|
2023-11-03 09:20:57 +00:00
|
|
|
});
|
2023-11-02 08:12:35 +00:00
|
|
|
}
|
2023-06-23 04:34:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function setPowerIcon(status) {
|
|
|
|
const manifestVersion = chrome.runtime.getManifest().manifest_version;
|
|
|
|
if (status === 'on') {
|
|
|
|
if (manifestVersion === 2) {
|
|
|
|
chrome.browserAction.setIcon({ path: "/images/logo-128.png" });
|
|
|
|
} else {
|
|
|
|
chrome.action.setIcon({ path: "/images/logo-128.png" });
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (manifestVersion === 2) {
|
|
|
|
chrome.browserAction.setIcon({ path: "/images/logo-off.png" });
|
|
|
|
} else {
|
|
|
|
chrome.action.setIcon({ path: "/images/logo-off.png" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 03:00:08 +00:00
|
|
|
if (chrome.declarativeNetRequest) {
|
|
|
|
// Whenever stored settings change, update the header
|
|
|
|
// that is sent to BreezeWiki instances to inform them the user has IWB
|
|
|
|
updateDeclarativeRule();
|
|
|
|
chrome.storage.onChanged.addListener(event => updateDeclarativeRule());
|
2023-04-29 05:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateDeclarativeRule() {
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.storage.local.get((localStorage) => {
|
|
|
|
chrome.storage.sync.get((syncStorage) => {
|
2023-04-29 05:43:24 +00:00
|
|
|
const storage = { ...syncStorage, ...localStorage };
|
|
|
|
const headerValue = JSON.stringify({
|
|
|
|
'power': storage.power ?? 'on',
|
|
|
|
'breezewiki': storage.breezewiki ?? 'off'
|
|
|
|
});
|
2023-11-27 03:00:08 +00:00
|
|
|
let urls = [
|
|
|
|
"breezewiki.com",
|
|
|
|
"antifandom.com",
|
|
|
|
"bw.projectsegfau.lt",
|
|
|
|
"breeze.hostux.net",
|
|
|
|
"breezewiki.pussthecat.org",
|
|
|
|
"bw.vern.cc",
|
|
|
|
"breezewiki.esmailelbob.xyz",
|
|
|
|
"bw.artemislena.eu",
|
|
|
|
"bw.hamstro.dev",
|
|
|
|
"nerd.whatever.social",
|
|
|
|
"breeze.nohost.network",
|
|
|
|
"breeze.whateveritworks.org"
|
|
|
|
];
|
|
|
|
if (storage.breezewikiCustomHost) {
|
|
|
|
urls.push(storage.breezewikiCustomHost.replace(/^https?:\/\//, ''));
|
|
|
|
};
|
|
|
|
|
2023-04-29 05:43:24 +00:00
|
|
|
chrome.declarativeNetRequest.updateDynamicRules({
|
|
|
|
removeRuleIds: [1],
|
|
|
|
addRules: [
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"priority": 1,
|
|
|
|
"action": {
|
|
|
|
"type": "modifyHeaders",
|
|
|
|
"requestHeaders": [
|
|
|
|
{
|
|
|
|
"operation": "set",
|
|
|
|
"header": "x-indie-wiki",
|
|
|
|
"value": headerValue
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"condition": {
|
2023-11-27 03:00:08 +00:00
|
|
|
"requestDomains": urls,
|
2023-04-29 05:43:24 +00:00
|
|
|
"resourceTypes": [
|
|
|
|
"main_frame"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-27 08:14:00 +00:00
|
|
|
function redirectToBreezeWiki(storage, tabId, url) {
|
2023-02-06 00:48:53 +00:00
|
|
|
function processRedirect(host) {
|
2023-12-12 10:03:31 +00:00
|
|
|
// Extract article from URL
|
2023-11-27 08:14:00 +00:00
|
|
|
const urlFormatted = new URL(url);
|
|
|
|
const subdomain = urlFormatted.hostname.split(".")[0];
|
|
|
|
const article = url.split('fandom.com/wiki/')[1].replaceAll('%20', '_');
|
2023-09-18 03:46:56 +00:00
|
|
|
|
2023-12-12 10:03:31 +00:00
|
|
|
// Perform redirect
|
2023-02-06 00:48:53 +00:00
|
|
|
if (article) {
|
2023-11-27 08:14:00 +00:00
|
|
|
chrome.tabs.update(tabId, { url: host + '/' + subdomain + '/wiki/' + article });
|
2023-02-06 00:48:53 +00:00
|
|
|
} else {
|
2023-11-27 08:14:00 +00:00
|
|
|
chrome.tabs.update(tabId, { url: host + '/' + subdomain });
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
2023-09-18 03:46:56 +00:00
|
|
|
|
|
|
|
// Increase BreezeWiki stat count
|
|
|
|
chrome.storage.sync.set({ 'countBreezeWiki': (storage.countBreezeWiki ?? 0) + 1 });
|
|
|
|
|
2023-02-06 00:48:53 +00:00
|
|
|
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, {
|
|
|
|
"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."
|
|
|
|
});
|
2023-09-18 03:46:56 +00:00
|
|
|
// Self-clear notification after 6 seconds
|
2023-12-13 10:10:55 +00:00
|
|
|
setTimeout(() => { chrome.notifications.clear(notifID); }, 6000);
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 08:14:00 +00:00
|
|
|
if (url.includes('fandom.com/wiki/')) {
|
2023-02-06 00:48:53 +00:00
|
|
|
if (!(storage.breezewikiHost ?? null)) {
|
2023-02-06 12:23:21 +00:00
|
|
|
fetch('https://bw.getindie.wiki/instances.json')
|
2023-04-28 06:19:55 +00:00
|
|
|
.then((response) => {
|
|
|
|
if (response.ok) {
|
|
|
|
return response.json();
|
|
|
|
}
|
|
|
|
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,
|
2023-04-29 05:43:24 +00:00
|
|
|
undefined,
|
2023-04-28 06:19:55 +00:00
|
|
|
{ numeric: true, sensitivity: 'base' }
|
|
|
|
) >= 0
|
|
|
|
);
|
2023-02-06 12:23:21 +00:00
|
|
|
// 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 });
|
|
|
|
} else {
|
|
|
|
// If BreezeWiki.com is not available, set to a random mirror
|
2023-04-28 06:19:55 +00:00
|
|
|
try {
|
|
|
|
chrome.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);
|
|
|
|
}
|
2023-02-06 12:23:21 +00:00
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
|
|
|
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
|
|
|
|
processRedirect(host);
|
2023-04-28 06:19:55 +00:00
|
|
|
}).catch((e) => {
|
|
|
|
console.log('Indie Wiki Buddy failed to get BreezeWiki data: ' + e);
|
2023-10-16 05:29:31 +00:00
|
|
|
chrome.storage.sync.set({ 'breezewikiHost': 'https://breezewiki.com' });
|
2023-02-06 00:48:53 +00:00
|
|
|
});
|
|
|
|
} else {
|
2023-11-27 03:00:08 +00:00
|
|
|
if (storage.breezewikiHost === 'CUSTOM') {
|
|
|
|
processRedirect(storage.breezewikiCustomHost || 'https://breezewiki.com');
|
|
|
|
} else {
|
|
|
|
processRedirect(storage.breezewikiHost);
|
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-18 03:46:56 +00:00
|
|
|
// Load website data
|
2023-02-06 00:48:53 +00:00
|
|
|
async function getData() {
|
2023-12-07 01:50:16 +00:00
|
|
|
const LANGS = ["DE", "EN", "ES", "FR", "IT", "KO", "PL", "PT", "RU", "TOK", "UK", "ZH"];
|
2023-02-06 00:48:53 +00:00
|
|
|
let sites = [];
|
|
|
|
let promises = [];
|
|
|
|
for (let i = 0; i < LANGS.length; i++) {
|
|
|
|
promises.push(fetch(chrome.runtime.getURL('data/sites' + LANGS[i] + '.json'))
|
|
|
|
.then((resp) => resp.json())
|
2023-12-13 10:10:55 +00:00
|
|
|
.then((jsonData) => {
|
2023-04-12 07:19:33 +00:00
|
|
|
jsonData.forEach((site) => {
|
|
|
|
site.origins.forEach((origin) => {
|
|
|
|
sites.push({
|
|
|
|
"id": site.id,
|
|
|
|
"origin": origin.origin,
|
|
|
|
"origin_base_url": origin.origin_base_url,
|
|
|
|
"origin_content_path": origin.origin_content_path,
|
2023-12-12 10:03:31 +00:00
|
|
|
"origin_main_page": origin.origin_main_page,
|
2023-04-12 07:19:33 +00:00
|
|
|
"destination": site.destination,
|
2023-04-29 05:43:24 +00:00
|
|
|
"destination_base_url": site.destination_base_url,
|
2023-12-12 10:03:31 +00:00
|
|
|
"destination_search_path": site.destination_search_path,
|
2023-07-17 04:41:11 +00:00
|
|
|
"destination_content_prefix": (site.destination_content_prefix ? site.destination_content_prefix : ""),
|
2023-04-29 05:43:24 +00:00
|
|
|
"destination_platform": site.destination_platform,
|
|
|
|
"destination_icon": site.destination_icon,
|
2023-12-12 10:03:31 +00:00
|
|
|
"destination_main_page": site.destination_main_page,
|
2023-04-12 07:19:33 +00:00
|
|
|
"lang": LANGS[i]
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
2023-02-06 00:48:53 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
await Promise.all(promises);
|
|
|
|
return sites;
|
|
|
|
}
|
|
|
|
|
2023-11-27 08:14:00 +00:00
|
|
|
async function main(url, tabId) {
|
2023-11-05 05:52:22 +00:00
|
|
|
// Create object prototypes for getting and setting attributes
|
|
|
|
Object.prototype.get = function (prop) {
|
|
|
|
this[prop] = this[prop] || {};
|
|
|
|
return this[prop];
|
|
|
|
};
|
|
|
|
Object.prototype.set = function (prop, value) {
|
|
|
|
this[prop] = value;
|
|
|
|
}
|
2023-09-18 03:46:56 +00:00
|
|
|
|
2023-11-05 05:52:22 +00:00
|
|
|
// Check if tab is actually available
|
|
|
|
// This is mainly to prevent background processes from triggering an event
|
|
|
|
let sites = [];
|
2023-02-06 00:48:53 +00:00
|
|
|
|
2023-11-05 05:52:22 +00:00
|
|
|
sites = await getData();
|
2023-02-06 00:48:53 +00:00
|
|
|
|
2023-12-13 10:10:55 +00:00
|
|
|
chrome.storage.local.get((localStorage) => {
|
|
|
|
chrome.storage.sync.get((syncStorage) => {
|
2023-11-05 05:52:22 +00:00
|
|
|
const storage = { ...syncStorage, ...localStorage };
|
|
|
|
if ((storage.power ?? 'on') === 'on') {
|
|
|
|
let crossLanguageSetting = storage.crossLanguage || 'off';
|
|
|
|
// Check if site is in our list of wikis:
|
|
|
|
let matchingSites = [];
|
|
|
|
if (crossLanguageSetting === 'on') {
|
2023-11-27 08:14:00 +00:00
|
|
|
matchingSites = sites.filter(el => url.replace(/^https?:\/\//, '').startsWith(el.origin_base_url));
|
2023-11-05 05:52:22 +00:00
|
|
|
} else {
|
2023-11-27 08:14:00 +00:00
|
|
|
matchingSites = sites.filter(el => url.replace(/^https?:\/\//, '').startsWith(el.origin_base_url + el.origin_content_path));
|
2023-11-05 05:52:22 +00:00
|
|
|
}
|
|
|
|
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.wikiSettings || {};
|
|
|
|
let id = site['id'];
|
|
|
|
let siteSetting = settings[id] || storage.defaultWikiAction || 'alert';
|
|
|
|
// Check if redirects are enabled for the site
|
|
|
|
if (siteSetting === 'redirect') {
|
|
|
|
// 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
|
2023-12-12 10:03:31 +00:00
|
|
|
let article = decodeURIComponent(url.split(site['origin_base_url'] + site['origin_content_path'])[1]);
|
2023-11-05 05:52:22 +00:00
|
|
|
// Set up URL to redirect user to based on wiki platform
|
|
|
|
let newURL = '';
|
|
|
|
if (article) {
|
2023-12-12 10:03:31 +00:00
|
|
|
// Check if main page
|
|
|
|
if (article === site['origin_main_page']) {
|
|
|
|
article = site['destination_main_page'];
|
|
|
|
}
|
|
|
|
|
2023-11-05 05:52:22 +00:00
|
|
|
let searchParams = '';
|
|
|
|
switch (site['destination_platform']) {
|
|
|
|
case 'mediawiki':
|
2023-12-12 10:03:31 +00:00
|
|
|
searchParams = '?search=' + site['destination_content_prefix'] + article;
|
2023-11-05 05:52:22 +00:00
|
|
|
break;
|
|
|
|
case 'doku':
|
|
|
|
searchParams = 'start?do=search&q=' + article;
|
|
|
|
break;
|
|
|
|
}
|
2023-12-12 10:03:31 +00:00
|
|
|
newURL = 'https://' + site["destination_base_url"] + site["destination_search_path"] + searchParams;
|
2023-11-05 05:52:22 +00:00
|
|
|
} else {
|
|
|
|
newURL = 'https://' + site["destination_base_url"];
|
2023-09-18 03:46:56 +00:00
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
|
2023-11-05 05:52:22 +00:00
|
|
|
// Perform redirect
|
2023-11-27 08:14:00 +00:00
|
|
|
chrome.tabs.update(tabId, { url: newURL });
|
2023-06-27 08:12:42 +00:00
|
|
|
|
2023-11-05 05:52:22 +00:00
|
|
|
// Increase redirect count
|
|
|
|
chrome.storage.sync.set({ 'countRedirects': (storage.countRedirects ?? 0) + 1 });
|
2023-02-06 00:48:53 +00:00
|
|
|
|
2023-11-05 05:52:22 +00:00
|
|
|
// 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, {
|
|
|
|
"type": "basic",
|
|
|
|
"iconUrl": 'images/logo-48.png',
|
|
|
|
"title": "You've been redirected!",
|
|
|
|
"message": "Indie Wiki Buddy has sent you from " + site['origin'] + " to " + site['destination']
|
|
|
|
});
|
|
|
|
// Self-clear notification after 6 seconds
|
2023-12-13 10:10:55 +00:00
|
|
|
setTimeout(() => { chrome.notifications.clear(notifID); }, 6000);
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
2023-11-05 05:52:22 +00:00
|
|
|
} else if ((storage.breezewiki ?? 'off') === 'on') {
|
2023-11-27 08:14:00 +00:00
|
|
|
redirectToBreezeWiki(storage, tabId, url);
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|
2023-09-18 03:46:56 +00:00
|
|
|
}
|
2023-11-05 05:52:22 +00:00
|
|
|
} else if ((storage.breezewiki ?? 'off') === 'on') {
|
2023-11-27 08:14:00 +00:00
|
|
|
redirectToBreezeWiki(storage, tabId, url);
|
2023-09-18 03:46:56 +00:00
|
|
|
}
|
2023-11-05 05:52:22 +00:00
|
|
|
}
|
2023-02-06 00:48:53 +00:00
|
|
|
});
|
2023-11-05 05:52:22 +00:00
|
|
|
});
|
2023-02-06 00:48:53 +00:00
|
|
|
}
|