Split repeat BreezeWiki code into new function
parent
702915cd9f
commit
61536a5af9
|
@ -1,5 +1,5 @@
|
||||||
const LANGS = ["DE", "EN", "ES", "FR", "IT", "KO", "PL", "PT", "TOK", "UK", "ZH"];
|
const LANGS = ["DE", "EN", "ES", "FR", "IT", "KO", "PL", "PT", "TOK", "UK", "ZH"];
|
||||||
const breezeWikiRegex = /breezewiki\.com$|breeze\.hostux\.net$|bw\.projectsegfau\.lt$|antifandom\.com$|breezewiki\.pussthecat\.org$|bw\.vern\.cc$|breezewiki\.esmailelbob\.xyz$|bw\.artemislena\.eu$|bw\.hamstro\.dev$|nerd\.whatever\.social$|breeze\.nohost\.network$|breeze\.whateveritworks\.org$/;
|
const breezewikiRegex = /breezewiki\.com$|breeze\.hostux\.net$|bw\.projectsegfau\.lt$|antifandom\.com$|breezewiki\.pussthecat\.org$|bw\.vern\.cc$|breezewiki\.esmailelbob\.xyz$|bw\.artemislena\.eu$|bw\.hamstro\.dev$|nerd\.whatever\.social$|breeze\.nohost\.network$|breeze\.whateveritworks\.org$/;
|
||||||
const currentURL = new URL(document.location);
|
const currentURL = new URL(document.location);
|
||||||
|
|
||||||
// Create object prototypes for getting and setting attributes:
|
// Create object prototypes for getting and setting attributes:
|
||||||
|
@ -205,7 +205,7 @@ function displayRedirectBanner(origin, newUrl, id, destinationName, destinationL
|
||||||
|
|
||||||
// Increment banner count
|
// Increment banner count
|
||||||
if (storage.breezewiki === 'on') {
|
if (storage.breezewiki === 'on') {
|
||||||
if (currentURL.hostname.match(breezeWikiRegex)) {
|
if (currentURL.hostname.match(breezewikiRegex)) {
|
||||||
chrome.storage.sync.set({ 'countAlerts': (storage.countAlerts ?? 0) + 1 });
|
chrome.storage.sync.set({ 'countAlerts': (storage.countAlerts ?? 0) + 1 });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -232,7 +232,7 @@ function main() {
|
||||||
if (currentURL.pathname.length > 1) {
|
if (currentURL.pathname.length > 1) {
|
||||||
let origin = currentURL;
|
let origin = currentURL;
|
||||||
// If on a BreezeWiki site, convert to Fandom link to match with our list of wikis:
|
// If on a BreezeWiki site, convert to Fandom link to match with our list of wikis:
|
||||||
if (currentURL.hostname.match(breezeWikiRegex)) {
|
if (currentURL.hostname.match(breezewikiRegex)) {
|
||||||
origin = String(currentURL.pathname).split('/')[1] + '.fandom.com/wiki/';
|
origin = String(currentURL.pathname).split('/')[1] + '.fandom.com/wiki/';
|
||||||
if (currentURL.search.includes('?q=')) {
|
if (currentURL.search.includes('?q=')) {
|
||||||
origin = origin + currentURL.search.substring(3).split('&')[0];
|
origin = origin + currentURL.search.substring(3).split('&')[0];
|
||||||
|
|
73
settings.js
73
settings.js
|
@ -41,6 +41,31 @@ async function getData() {
|
||||||
return sites;
|
return sites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function populateBreezewikiHosts(breezewikiHosts, selectedHost) {
|
||||||
|
// Populate dropdown selection of hosts
|
||||||
|
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
||||||
|
while (breezewikiHostSelect.firstChild) {
|
||||||
|
// Remove any existing options
|
||||||
|
breezewikiHostSelect.removeChild(breezewikiHostSelect.lastChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add known BreezeWiki domains:
|
||||||
|
for (var i = 0; i < breezewikiHosts.length; i++) {
|
||||||
|
let option = document.createElement('option');
|
||||||
|
option.value = breezewikiHosts[i].instance;
|
||||||
|
let textContent = breezewikiHosts[i].instance.replace('https://', '');
|
||||||
|
const numberOfPeriods = (textContent.match(/\./g) || []).length;
|
||||||
|
if (numberOfPeriods > 1) {
|
||||||
|
textContent = textContent.substring(textContent.indexOf('.') + 1);
|
||||||
|
}
|
||||||
|
option.textContent = textContent;
|
||||||
|
breezewikiHostSelect.appendChild(option);
|
||||||
|
if (option.value === selectedHost) {
|
||||||
|
breezewikiHostSelect.value = selectedHost;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Populate BreezeWiki dropdown when enabled
|
// Populate BreezeWiki dropdown when enabled
|
||||||
async function loadBreezeWikiOptions() {
|
async function loadBreezeWikiOptions() {
|
||||||
// Load BreezeWiki options:
|
// Load BreezeWiki options:
|
||||||
|
@ -79,26 +104,9 @@ async function loadBreezeWikiOptions() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Populate dropdown selection of hosts
|
|
||||||
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
populateBreezewikiHosts(breezewikiHosts, host);
|
||||||
while (breezewikiHostSelect.firstChild) {
|
|
||||||
// Remove any existing options
|
|
||||||
breezewikiHostSelect.removeChild(breezewikiHostSelect.lastChild);
|
|
||||||
}
|
|
||||||
for (var i = 0; i < breezewikiHosts.length; i++) {
|
|
||||||
let option = document.createElement('option');
|
|
||||||
option.value = breezewikiHosts[i].instance;
|
|
||||||
let textContent = breezewikiHosts[i].instance.replace('https://', '');
|
|
||||||
const numberOfPeriods = (textContent.match(/\./g) || []).length;
|
|
||||||
if (numberOfPeriods > 1) {
|
|
||||||
textContent = textContent.substring(textContent.indexOf('.') + 1);
|
|
||||||
}
|
|
||||||
option.textContent = textContent;
|
|
||||||
breezewikiHostSelect.appendChild(option);
|
|
||||||
if (option.value === host) {
|
|
||||||
breezewikiHostSelect.value = host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Store BreezeWiki host details
|
// Store BreezeWiki host details
|
||||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||||
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
||||||
|
@ -116,33 +124,16 @@ async function loadBreezeWikiOptions() {
|
||||||
if (!hostOptions.some(item => item.instance === host)) {
|
if (!hostOptions.some(item => item.instance === host)) {
|
||||||
host = hostOptions[Math.floor(Math.random() * hostOptions.length)].instance;
|
host = hostOptions[Math.floor(Math.random() * hostOptions.length)].instance;
|
||||||
}
|
}
|
||||||
// Populate dropdown selection of hosts
|
|
||||||
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
populateBreezewikiHosts(hostOptions, host);
|
||||||
while (breezewikiHostSelect.firstChild) {
|
|
||||||
// Remove any existing options
|
|
||||||
breezewikiHostSelect.removeChild(breezewikiHostSelect.lastChild);
|
|
||||||
}
|
|
||||||
for (var i = 0; i < hostOptions.length; i++) {
|
|
||||||
let option = document.createElement('option');
|
|
||||||
option.value = hostOptions[i].instance;
|
|
||||||
let textContent = hostOptions[i].instance.replace('https://', '');
|
|
||||||
const numberOfPeriods = (textContent.match(/\./g) || []).length;
|
|
||||||
if (numberOfPeriods > 1) {
|
|
||||||
textContent = textContent.substring(textContent.indexOf('.') + 1);
|
|
||||||
}
|
|
||||||
option.textContent = textContent;
|
|
||||||
breezewikiHostSelect.appendChild(option);
|
|
||||||
if (option.value === host) {
|
|
||||||
breezewikiHostSelect.value = host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Store BreezeWiki host details
|
// Store BreezeWiki host details
|
||||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate popup settings and toggles
|
// Populate settings and toggles
|
||||||
async function loadOptions(lang) {
|
async function loadOptions(lang) {
|
||||||
sites = await getData();
|
sites = await getData();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue