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 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);
|
||||
|
||||
// Create object prototypes for getting and setting attributes:
|
||||
|
@ -205,7 +205,7 @@ function displayRedirectBanner(origin, newUrl, id, destinationName, destinationL
|
|||
|
||||
// Increment banner count
|
||||
if (storage.breezewiki === 'on') {
|
||||
if (currentURL.hostname.match(breezeWikiRegex)) {
|
||||
if (currentURL.hostname.match(breezewikiRegex)) {
|
||||
chrome.storage.sync.set({ 'countAlerts': (storage.countAlerts ?? 0) + 1 });
|
||||
}
|
||||
} else {
|
||||
|
@ -232,7 +232,7 @@ function main() {
|
|||
if (currentURL.pathname.length > 1) {
|
||||
let origin = currentURL;
|
||||
// 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/';
|
||||
if (currentURL.search.includes('?q=')) {
|
||||
origin = origin + currentURL.search.substring(3).split('&')[0];
|
||||
|
|
73
settings.js
73
settings.js
|
@ -41,6 +41,31 @@ async function getData() {
|
|||
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
|
||||
async function loadBreezeWikiOptions() {
|
||||
// Load BreezeWiki options:
|
||||
|
@ -79,26 +104,9 @@ async function loadBreezeWikiOptions() {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Populate dropdown selection of hosts
|
||||
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
populateBreezewikiHosts(breezewikiHosts, host);
|
||||
|
||||
// Store BreezeWiki host details
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
||||
|
@ -116,33 +124,16 @@ async function loadBreezeWikiOptions() {
|
|||
if (!hostOptions.some(item => item.instance === host)) {
|
||||
host = hostOptions[Math.floor(Math.random() * hostOptions.length)].instance;
|
||||
}
|
||||
// Populate dropdown selection of hosts
|
||||
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
populateBreezewikiHosts(hostOptions, host);
|
||||
|
||||
// Store BreezeWiki host details
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Populate popup settings and toggles
|
||||
// Populate settings and toggles
|
||||
async function loadOptions(lang) {
|
||||
sites = await getData();
|
||||
|
||||
|
|
Loading…
Reference in New Issue