Reworking popup / Most settings moved to new separate page
parent
9832f0c859
commit
1949608ef9
395
popup.html
395
popup.html
|
@ -5,95 +5,122 @@
|
|||
<meta charset="UTF-8" />
|
||||
<title>Indie Wiki Buddy</title>
|
||||
<style>
|
||||
/* ELEMENTS */
|
||||
body {
|
||||
width: 550px;
|
||||
max-width: 96%;
|
||||
margin: 10px;
|
||||
width: 450px;
|
||||
background-color: #005799;
|
||||
margin: 0px;
|
||||
font-family: Helvetica, Sans-Serif;
|
||||
font-size: .9em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.2rem;
|
||||
font-size: 1.3rem;
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
hr {
|
||||
height: 1px;
|
||||
border: none;
|
||||
color: #555;
|
||||
background-color: #555;
|
||||
color: #005799;
|
||||
background-color: #005799;
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
label {
|
||||
display: inline-block;
|
||||
height: 20px;
|
||||
#openSettingsContainer {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
#openSettings {
|
||||
background: #3174f1;
|
||||
border: 1px solid #333333;
|
||||
color: #fff;
|
||||
border-radius: 5px;
|
||||
padding: .5em;
|
||||
margin: 0 .5em .5em .5em;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
#openSettings:hover {
|
||||
cursor: pointer;
|
||||
background: #ffffff;
|
||||
border: 1px solid#3174f1;
|
||||
color: #3174f1;
|
||||
}
|
||||
|
||||
.visuallyHidden {
|
||||
position: absolute !important;
|
||||
width: 1px !important;
|
||||
height: 1px !important;
|
||||
padding: 0 !important;
|
||||
margin: -1px !important;
|
||||
overflow: hidden !important;
|
||||
clip: rect(0, 0, 0, 0) !important;
|
||||
white-space: nowrap !important;
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
.links {
|
||||
font-size: .8em;
|
||||
/* HEADER */
|
||||
#header {
|
||||
line-height: 1.5em;
|
||||
margin-left: 8px;
|
||||
padding: .5em 1em;
|
||||
box-sizing: border-box;
|
||||
background-color: #005799;
|
||||
color: #fff;
|
||||
width: 100%;
|
||||
}
|
||||
.links a, .links a:visited, .links a:active {
|
||||
text-decoration: none;
|
||||
border-bottom: 1px black dotted;
|
||||
#header .settingToggle label {
|
||||
background-color: #fff;
|
||||
border-radius: 20px;
|
||||
height: fit-content;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
/* POWER TOGGLE */
|
||||
#power {
|
||||
cursor: pointer;
|
||||
width: fit-content;
|
||||
vertical-align: middle;
|
||||
float: right;
|
||||
padding-top: .2em;
|
||||
}
|
||||
#power > label {
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
background-color: #fff;
|
||||
border-radius: 20px;
|
||||
}
|
||||
#power > input {
|
||||
height: 0;
|
||||
width: 0;
|
||||
margin: 0;
|
||||
border: none;
|
||||
appearance: none;
|
||||
}
|
||||
#power img {
|
||||
width: 30px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* CONTENT */
|
||||
#content {
|
||||
padding: .5em;
|
||||
background-color: #e5f4ff;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
#links {
|
||||
text-align: center;
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
/* GLOBAL SETTINGS SECTION */
|
||||
.options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 10px;
|
||||
user-select: none;
|
||||
margin-top: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
.options > div {
|
||||
flex: 50%;
|
||||
}
|
||||
.options > div {
|
||||
.options .settingToggleContainer {
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.options > div:last-child {
|
||||
.options .settingToggleContainer:last-child {
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#controls {
|
||||
margin: 0 auto;
|
||||
width: fit-content;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.control {
|
||||
background: #ffffff;
|
||||
border: 1px solid #333333;
|
||||
color: #333333;
|
||||
border-radius: 5px;
|
||||
padding: 3px 5px;
|
||||
margin: 3px 5px;
|
||||
}
|
||||
.control:hover {
|
||||
cursor: pointer;
|
||||
background: #3174f1;
|
||||
border: 1px solid#3174f1;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
/* GLOBAL SETTING TOGGLES */
|
||||
.settingToggleContainer {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.settingToggle {
|
||||
cursor: pointer;
|
||||
width: fit-content;
|
||||
|
@ -107,83 +134,6 @@
|
|||
.settingToggle label {
|
||||
cursor: pointer;
|
||||
}
|
||||
.settingToggle input {
|
||||
height: 0;
|
||||
width: 0;
|
||||
margin: 0;
|
||||
border: none;
|
||||
appearance: none;
|
||||
}
|
||||
.settingToggle img {
|
||||
width: 30px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.columns {
|
||||
display: grid;
|
||||
grid-auto-columns: 1fr;
|
||||
grid-auto-flow: column;
|
||||
}
|
||||
|
||||
#toggles {
|
||||
height: 16em;
|
||||
white-space: nowrap;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
position: relative;
|
||||
}
|
||||
#toggles > div:hover {
|
||||
background-color: #e8f0fe;
|
||||
}
|
||||
#toggles input {
|
||||
cursor: pointer;
|
||||
}
|
||||
#toggles > div {
|
||||
line-height: 1.2em;
|
||||
font-size: 1em;
|
||||
}
|
||||
#toggles img {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
max-height: 1.2em;
|
||||
}
|
||||
#toggles a {
|
||||
float: right;
|
||||
padding-right: 10px;
|
||||
clear: both;
|
||||
}
|
||||
#toggles span {
|
||||
padding-left: 10px;
|
||||
}
|
||||
#togglesKey {
|
||||
padding-left: 5px;
|
||||
}
|
||||
#togglesKey > div {
|
||||
display: inline-block;
|
||||
width: 17px;
|
||||
}
|
||||
|
||||
#langSelectContainer {
|
||||
font-size: 0.9em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
line-height: 1.4em;
|
||||
}
|
||||
.footer a {
|
||||
font-size: 0.9em;
|
||||
padding: 5px 0px;
|
||||
color: #3174f1;
|
||||
}
|
||||
|
||||
#toggles,
|
||||
#powerText,
|
||||
.settingToggleContainer,
|
||||
.footer {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
#breezewikiHost {
|
||||
display: none;
|
||||
|
@ -196,69 +146,38 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<div class="columns">
|
||||
<div class="links">
|
||||
<h1>Indie Wiki Buddy</h1>
|
||||
<span id="version"></span>
|
||||
<br />
|
||||
<a
|
||||
href="https://getindie.wiki/"
|
||||
target="_blank"
|
||||
>Info & Help</a
|
||||
>
|
||||
<br />
|
||||
<a
|
||||
href="https://getindie.wiki/changelog/"
|
||||
target="_blank"
|
||||
>Changelog</a
|
||||
>
|
||||
<br />
|
||||
<a
|
||||
href="https://getindie.wiki/#submit"
|
||||
target="_blank"
|
||||
>Submit a Wiki</a
|
||||
>
|
||||
<br />
|
||||
<a
|
||||
href="https://github.com/KevinPayravi/indie-wiki-buddy"
|
||||
target="_blank"
|
||||
>Source Code</a
|
||||
>
|
||||
<div id="header">
|
||||
<div id="power">
|
||||
<input id="powerCheckbox" type="checkbox" />
|
||||
<label for="powerCheckbox">
|
||||
<img id="powerImage" src="" alt="" width="30" />
|
||||
</label>
|
||||
</div>
|
||||
<h1>Indie Wiki Buddy</h1>
|
||||
</div>
|
||||
<div id="content">
|
||||
<div class="options">
|
||||
<div class="settingToggleContainer">
|
||||
<div id="power" class="settingToggle">
|
||||
<input id="powerButton" type="checkbox" />
|
||||
<label for="powerButton">
|
||||
<img id="powerImage" src="" alt="" />
|
||||
<span id="powerText"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingToggleContainer">
|
||||
<div id="notifications" class="settingToggle">
|
||||
<input id="notificationsButton" type="checkbox" />
|
||||
<label for="notificationsButton">
|
||||
<img id="notificationsImage" src="" alt="" />
|
||||
<span id="notificationsText"></span>
|
||||
<input id="notificationsCheckbox" type="checkbox" />
|
||||
<label for="notificationsCheckbox">
|
||||
<span id="notificationsText">🔔 Receive a browser notification when you are redirected</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingToggleContainer">
|
||||
<div id="searchFilter" class="settingToggle">
|
||||
<input id="searchFilterButton" type="checkbox" />
|
||||
<label for="searchFilterButton">
|
||||
<img id="searchFilterImage" src="" alt="" />
|
||||
<span id="searchFilterText"></span>
|
||||
<input id="searchFilterCheckbox" type="checkbox" />
|
||||
<label for="searchFilterCheckbox">
|
||||
<span id="searchFilterText">🔎 Filter non-indie wiki results in Google, Bing, & DuckDuckGo</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingToggleContainer">
|
||||
<div id="breezewiki" class="settingToggle">
|
||||
<input id="breezewikiButton" type="checkbox" />
|
||||
<label for="breezewikiButton">
|
||||
<img id="breezewikiImage" src="" alt="" />
|
||||
<span id="breezewikiText"></span>
|
||||
<input id="breezewikiCheckbox" type="checkbox" />
|
||||
<label for="breezewikiCheckbox">
|
||||
<span id="breezewikiText">🌬️ Use BreezeWiki on Fandom</span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -271,89 +190,45 @@
|
|||
</div>
|
||||
<div class="settingToggleContainer">
|
||||
<div id="breezewikiHost" class="settingToggle">
|
||||
<label for="breezewikiHostSelect">Host: </label>
|
||||
<label for="breezewikiHostSelect">BreezeWiki Host: </label>
|
||||
<select name="breezewikiHost" id="breezewikiHostSelect"></select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div id="controls">
|
||||
<div id="langSelectContainer">
|
||||
Viewing wikis in:
|
||||
<select name="lang" id="langSelect">
|
||||
<option value="DE">Deutsch</option>
|
||||
<option value="EN" selected>English</option>
|
||||
<option value="ES">Español</option>
|
||||
<option value="FR">Français</option>
|
||||
<option value="IT">Italiano</option>
|
||||
<option value="PL">Polski</option>
|
||||
<option value="TOK">Toki Pona</option>
|
||||
</select>
|
||||
<hr/>
|
||||
<div id="openSettingsContainer">
|
||||
<button id="openSettings">
|
||||
View All Settings
|
||||
</button>
|
||||
<br />
|
||||
View all settings to configure your settings per-wiki.
|
||||
</div>
|
||||
<button id="setAllDisabled" class="control">
|
||||
<img src="images/toggle-disabled.png" width="10" alt="" /> Disable all
|
||||
</button>
|
||||
<button id="setAllRedirect" class="control">
|
||||
<img src="images/toggle-redirect.png" width="10" alt="" /> Set all to
|
||||
redirect
|
||||
</button>
|
||||
<button id="setAllAlert" class="control">
|
||||
<img src="images/toggle-alert.png" width="10" alt="" /> Set all to
|
||||
notify
|
||||
</button>
|
||||
<br />
|
||||
<button id="setAllSearchFilter" class="control">
|
||||
<img src="images/toggle-search-filter.png" width="10" alt="" /> Filter
|
||||
search for all
|
||||
</button>
|
||||
<button id="setNoneSearchFilter" class="control">
|
||||
<img src="images/toggle-search-filter.png" width="10" alt="" /> Filter
|
||||
search for none
|
||||
</button>
|
||||
</div>
|
||||
<div id="togglesKey">
|
||||
<div>
|
||||
<img
|
||||
src="images/toggle-disabled.png"
|
||||
width="15"
|
||||
alt="Disable"
|
||||
title="Disable"
|
||||
/>
|
||||
<hr />
|
||||
<div id="links">
|
||||
<a
|
||||
href="https://getindie.wiki/#guide"
|
||||
target="_blank"
|
||||
>Guide</a
|
||||
>
|
||||
|
||||
<a
|
||||
href="https://getindie.wiki/changelog/"
|
||||
target="_blank"
|
||||
>Changelog</a
|
||||
>
|
||||
|
||||
<a
|
||||
href="https://getindie.wiki/#submit"
|
||||
target="_blank"
|
||||
>Submit a Wiki</a
|
||||
>
|
||||
|
||||
<a
|
||||
href="https://github.com/KevinPayravi/indie-wiki-buddy"
|
||||
target="_blank"
|
||||
>Source Code</a
|
||||
>
|
||||
</div>
|
||||
<div>
|
||||
<img
|
||||
src="images/toggle-redirect.png"
|
||||
width="15"
|
||||
alt="Automatically redirect to indie wiki"
|
||||
title="Automatically redirect to indie wiki"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<img
|
||||
src="images/toggle-alert.png"
|
||||
width="15"
|
||||
alt="Notify of indie wiki with banner"
|
||||
title="Notify of indie wiki with banner"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<img
|
||||
src="images/toggle-search-filter.png"
|
||||
width="15"
|
||||
alt="Filter results from search engines"
|
||||
title="Filter results from search engines"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div id="toggles"></div>
|
||||
<hr />
|
||||
<div class="footer">
|
||||
Indie wiki alerts: <span id="countAlerts"></span>
|
||||
|
|
||||
Redirections: <span id="countRedirects"></span>
|
||||
|
|
||||
Search engine results filtered: <span id="countSearchFilters"></span>
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript" src="popup.js"></script>
|
||||
|
|
495
popup.js
495
popup.js
|
@ -1,358 +1,85 @@
|
|||
const LANGS = ["DE", "EN", "ES", "FR", "IT", "PL", "TOK"];
|
||||
var sites = [];
|
||||
// Set power setting
|
||||
function setPower(setting) {
|
||||
chrome.storage.sync.set({ 'power': setting });
|
||||
var powerImage = document.getElementById('powerImage');
|
||||
powerImage.src = 'images/power-' + setting + '.png';
|
||||
powerImage.alt = 'Indie Wiki Buddy is ' + setting;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Clear wiki toggles
|
||||
// Used when switching languages
|
||||
function resetOptions() {
|
||||
var toggleContainer = document.getElementById('toggles');
|
||||
toggleContainer.textContent = "";
|
||||
|
||||
// Clone "select all" buttons to reset listeners
|
||||
document.getElementById('setAllRedirect').cloneNode(true);
|
||||
document.getElementById('setAllAlert').cloneNode(true);
|
||||
document.getElementById('setAllDisabled').cloneNode(true);
|
||||
document.getElementById('setAllSearchFilter').cloneNode(true);
|
||||
document.getElementById('setNoneSearchFilter').cloneNode(true);
|
||||
}
|
||||
|
||||
// Get wiki data from data folder
|
||||
async function getData() {
|
||||
var 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())
|
||||
.then(function (jsonData) {
|
||||
jsonData.forEach((site) => site.language = LANGS[i]);
|
||||
sites = sites.concat(jsonData);
|
||||
}));
|
||||
}
|
||||
await Promise.all(promises);
|
||||
return sites;
|
||||
chrome.runtime.sendMessage({
|
||||
action: 'updateIcon',
|
||||
value: setting
|
||||
});
|
||||
}
|
||||
|
||||
// Populate popup settings and toggles
|
||||
async function loadOptions(lang) {
|
||||
sites = await getData();
|
||||
|
||||
chrome.storage.sync.get(function (storage) {
|
||||
let siteSettings = storage.siteSettings || {};
|
||||
let defaultActionSettings = storage.defaultActionSettings || {};
|
||||
let defaultSearchFilterSettings = storage.defaultSearchFilterSettings || {};
|
||||
|
||||
// Load BreezeWiki options:
|
||||
chrome.storage.sync.get(['breezewikiHostOptions', 'breezewikiHostFetchTimestamp', 'breezewikiHost'], function (item) {
|
||||
let hostOptions = item.breezewikiHostOptions;
|
||||
let hostFetchTimestamp = item.breezewikiHostFetchTimestamp;
|
||||
let host = item.breezewikiHost;
|
||||
// Fetch and cache list of BreezeWiki hosts if first time,
|
||||
// or if it has been 24 hrs since last refresh
|
||||
if (!host || !hostOptions || !hostFetchTimestamp || (Date.now() - 86400000 > hostFetchTimestamp)) {
|
||||
fetch('https://bw.getindie.wiki/instances.json')
|
||||
.then((response) => response.json())
|
||||
.then((breezewikiHosts) => {
|
||||
// If host isn't set, or currently selected host is no longer available, select random host:
|
||||
if (!host || !breezewikiHosts.some(item => item.instance === host)) {
|
||||
// Check if BreezeWiki's main site is available
|
||||
let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com');
|
||||
if (breezewikiMain.length > 0) {
|
||||
host = breezewikiMain[0].instance;
|
||||
} else {
|
||||
// If BreezeWiki.com is not available, set to a random mirror
|
||||
host = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance;
|
||||
}
|
||||
}
|
||||
// Populate dropdown selection of hosts
|
||||
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
||||
for (var i = 0; i < breezewikiHosts.length; i++) {
|
||||
let option = document.createElement('option');
|
||||
option.value = breezewikiHosts[i].instance;
|
||||
let innerText = breezewikiHosts[i].instance.replace('https://', '');
|
||||
const numberOfPeriods = (innerText.match(/\./g)||[]).length;
|
||||
if (numberOfPeriods > 1) {
|
||||
innerText = innerText.substring(innerText.indexOf('.') + 1);
|
||||
}
|
||||
option.innerText = innerText;
|
||||
breezewikiHostSelect.appendChild(option);
|
||||
if (option.value === host) {
|
||||
breezewikiHostSelect.value = host;
|
||||
}
|
||||
}
|
||||
// Store BreezeWiki host details
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
||||
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
|
||||
});
|
||||
} else {
|
||||
// If currently selected host is no longer available, select random host:
|
||||
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');
|
||||
for (var i = 0; i < hostOptions.length; i++) {
|
||||
let option = document.createElement('option');
|
||||
option.value = hostOptions[i].instance;
|
||||
let innerText = hostOptions[i].instance.replace('https://', '');
|
||||
const numberOfPeriods = (innerText.match(/\./g)||[]).length;
|
||||
if (numberOfPeriods > 1) {
|
||||
innerText = innerText.substring(innerText.indexOf('.') + 1);
|
||||
}
|
||||
option.innerText = innerText;
|
||||
breezewikiHostSelect.appendChild(option);
|
||||
if (option.value === host) {
|
||||
breezewikiHostSelect.value = host;
|
||||
}
|
||||
}
|
||||
// Store BreezeWiki host details
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||
}
|
||||
});
|
||||
|
||||
// Populate individual wiki settings:
|
||||
var toggleContainer = document.getElementById('toggles');
|
||||
for (var i = 0; i < sites.length; i++) {
|
||||
if (sites[i].language === lang) {
|
||||
var key = sites[i].id;
|
||||
|
||||
// Create radio for disabled:
|
||||
let labelDisabled = document.createElement("label");
|
||||
let inputDisabled = document.createElement("input");
|
||||
inputDisabled.classList = 'disable';
|
||||
inputDisabled.type = "radio";
|
||||
inputDisabled.name = key;
|
||||
inputDisabled.title = 'Disable actions for ' + sites[i].origin;
|
||||
inputDisabled.id = key + '-redirect';
|
||||
inputDisabled.lang = lang;
|
||||
|
||||
// Create radio for redirect:
|
||||
let labelRedirect = document.createElement("label");
|
||||
let inputRedirect = document.createElement("input");
|
||||
inputRedirect.classList = 'redirect';
|
||||
inputRedirect.type = "radio";
|
||||
inputRedirect.name = key;
|
||||
inputRedirect.title = 'Automatically redirect from ' + sites[i].origin + ' to ' + sites[i].destination;
|
||||
inputRedirect.id = key + '-redirect';
|
||||
inputRedirect.lang = lang;
|
||||
|
||||
// Create radio for alert:
|
||||
let labelAlert = document.createElement("label");
|
||||
let inputAlert = document.createElement("input");
|
||||
inputAlert.classList = 'alert';
|
||||
inputAlert.type = "radio";
|
||||
inputAlert.name = key;
|
||||
inputAlert.title = 'Notify with banner when visiting ' + sites[i].origin;
|
||||
inputAlert.id = key + '-alert';
|
||||
inputAlert.lang = lang;
|
||||
|
||||
// Create checkbox for search filtering:
|
||||
let labelFilter = document.createElement("label");
|
||||
let inputFilter = document.createElement("input");
|
||||
inputFilter.classList = 'filter';
|
||||
inputFilter.type = 'checkbox';
|
||||
inputFilter.name = key;
|
||||
inputFilter.title = 'Filter from search results on Google, Bing, and DuckDuckGo';
|
||||
inputFilter.id = key + '-filter';
|
||||
inputFilter.lang = lang;
|
||||
|
||||
// Check radio button based on user's settings
|
||||
// Will default to alert or the last "select all" setting the user chose
|
||||
if (siteSettings[key] && siteSettings[key].action) {
|
||||
if (siteSettings[key].action === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (siteSettings[key].action === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
} else {
|
||||
let actionSetting = defaultActionSettings[lang];
|
||||
if (actionSetting) {
|
||||
if (actionSetting === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (actionSetting === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
async function loadBreezeWikiOptions() {
|
||||
// Load BreezeWiki options:
|
||||
chrome.storage.sync.get(['breezewikiHostOptions', 'breezewikiHostFetchTimestamp', 'breezewikiHost'], function (item) {
|
||||
let hostOptions = item.breezewikiHostOptions;
|
||||
let hostFetchTimestamp = item.breezewikiHostFetchTimestamp;
|
||||
let host = item.breezewikiHost;
|
||||
// Fetch and cache list of BreezeWiki hosts if first time,
|
||||
// or if it has been 24 hrs since last refresh
|
||||
if (!host || !hostOptions || !hostFetchTimestamp || (Date.now() - 86400000 > hostFetchTimestamp)) {
|
||||
fetch('https://bw.getindie.wiki/instances.json')
|
||||
.then((response) => response.json())
|
||||
.then((breezewikiHosts) => {
|
||||
// If host isn't set, or currently selected host is no longer available, select random host:
|
||||
if (!host || !breezewikiHosts.some(item => item.instance === host)) {
|
||||
// Check if BreezeWiki's main site is available
|
||||
let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com');
|
||||
if (breezewikiMain.length > 0) {
|
||||
host = breezewikiMain[0].instance;
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
// If BreezeWiki.com is not available, set to a random mirror
|
||||
host = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance;
|
||||
}
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check search filter checkbox based on user's settings (default filter):
|
||||
if (siteSettings[key] && siteSettings[key].searchFilter) {
|
||||
if (siteSettings[key].searchFilter === 'false') {
|
||||
inputFilter.checked = false;
|
||||
} else {
|
||||
inputFilter.checked = true;
|
||||
}
|
||||
} else {
|
||||
let searchFilterSetting = defaultSearchFilterSettings[lang];
|
||||
if (searchFilterSetting && searchFilterSetting === 'false') {
|
||||
inputFilter.checked = false;
|
||||
} else {
|
||||
inputFilter.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Add listeners for when user clicks control:
|
||||
inputRedirect.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
response.siteSettings.get(key).set('action', 'redirect');
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
});
|
||||
inputAlert.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
response.siteSettings.get(key).set('action', 'alert');
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
});
|
||||
inputDisabled.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
response.siteSettings.get(key).set('action', 'disabled');
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
});
|
||||
inputFilter.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
if (input.target.checked === true) {
|
||||
response.siteSettings.get(key).set('searchFilter', 'true');
|
||||
} else {
|
||||
response.siteSettings.get(key).set('searchFilter', 'false');
|
||||
// Populate dropdown selection of hosts
|
||||
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
||||
for (var i = 0; i < breezewikiHosts.length; i++) {
|
||||
let option = document.createElement('option');
|
||||
option.value = breezewikiHosts[i].instance;
|
||||
let innerText = breezewikiHosts[i].instance.replace('https://', '');
|
||||
const numberOfPeriods = (innerText.match(/\./g)||[]).length;
|
||||
if (numberOfPeriods > 1) {
|
||||
innerText = innerText.substring(innerText.indexOf('.') + 1);
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
option.innerText = innerText;
|
||||
breezewikiHostSelect.appendChild(option);
|
||||
if (option.value === host) {
|
||||
breezewikiHostSelect.value = host;
|
||||
}
|
||||
}
|
||||
// Store BreezeWiki host details
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
||||
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
|
||||
});
|
||||
|
||||
// Output disable radio button:
|
||||
let inputDisabledText = document.createElement('span');
|
||||
inputDisabledText.classList.add('visuallyHidden');
|
||||
inputDisabledText.textContent = 'Disable action for ' + sites[i].origin;
|
||||
labelDisabled.appendChild(inputDisabled);
|
||||
labelDisabled.appendChild(inputDisabledText);
|
||||
|
||||
// Output redirect radio button:
|
||||
let inputRedirectText = document.createElement('span');
|
||||
inputRedirectText.classList.add('visuallyHidden');
|
||||
inputRedirectText.textContent = 'Automatically redirect ' + sites[i].origin;
|
||||
labelRedirect.appendChild(inputRedirect);
|
||||
labelRedirect.appendChild(inputRedirectText);
|
||||
|
||||
// Output alert radio button:
|
||||
let inputAlertText = document.createElement('span');
|
||||
inputAlertText.classList.add('visuallyHidden');
|
||||
inputAlertText.textContent = 'Automatically alert for' + sites[i].origin;
|
||||
labelAlert.appendChild(inputAlert);
|
||||
labelAlert.appendChild(inputAlertText);
|
||||
|
||||
// Output search filter checkbox:
|
||||
let inputFilterText = document.createElement('span');
|
||||
inputFilterText.classList.add('visuallyHidden');
|
||||
inputFilterText.textContent = 'Filter ' + sites[i].origin + ' from search engine results';
|
||||
labelFilter.appendChild(inputFilter);
|
||||
labelFilter.appendChild(inputFilterText);
|
||||
|
||||
// Output icon
|
||||
let iconLink = document.createElement("a");
|
||||
iconLink.href = 'https://' + sites[i].destination_base_url + sites[i].destination_content_path;
|
||||
iconLink.title = 'Visit ' + sites[i].destination;
|
||||
iconLink.target = '_blank';
|
||||
let icon = document.createElement("img");
|
||||
icon.src = 'favicons/' + lang.toLowerCase() + '/' + sites[i].destination_icon;
|
||||
icon.alt = 'Visit ' + sites[i].destination;
|
||||
iconLink.appendChild(icon);
|
||||
|
||||
// Output text:
|
||||
let text = document.createElement('span');
|
||||
text.textContent = sites[i].origin + ' » ' + sites[i].destination;
|
||||
let siteContainer = document.createElement("div");
|
||||
|
||||
siteContainer.appendChild(labelDisabled);
|
||||
siteContainer.appendChild(labelRedirect);
|
||||
siteContainer.appendChild(labelAlert);
|
||||
siteContainer.appendChild(labelFilter);
|
||||
siteContainer.appendChild(iconLink);
|
||||
siteContainer.appendChild(text);
|
||||
|
||||
toggleContainer.appendChild(siteContainer);
|
||||
} else {
|
||||
// If currently selected host is no longer available, select random host:
|
||||
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');
|
||||
for (var i = 0; i < hostOptions.length; i++) {
|
||||
let option = document.createElement('option');
|
||||
option.value = hostOptions[i].instance;
|
||||
let innerText = hostOptions[i].instance.replace('https://', '');
|
||||
const numberOfPeriods = (innerText.match(/\./g)||[]).length;
|
||||
if (numberOfPeriods > 1) {
|
||||
innerText = innerText.substring(innerText.indexOf('.') + 1);
|
||||
}
|
||||
option.innerText = innerText;
|
||||
breezewikiHostSelect.appendChild(option);
|
||||
if (option.value === host) {
|
||||
breezewikiHostSelect.value = host;
|
||||
}
|
||||
}
|
||||
// Store BreezeWiki host details
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||
}
|
||||
|
||||
// Add "select all" button event listeners:
|
||||
var setAllRedirect = document.getElementById('setAllRedirect');
|
||||
setAllRedirect.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.redirect');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = true;
|
||||
siteSettings.get(toggles[i].name).set('action', 'redirect');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultActionSettings[toggles[0].lang] = 'redirect';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllAlert = document.getElementById('setAllAlert');
|
||||
setAllAlert.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.alert');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = true;
|
||||
siteSettings.get(toggles[i].name).set('action', 'alert');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultActionSettings[toggles[0].lang] = 'alert';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllDisabled = document.getElementById('setAllDisabled');
|
||||
setAllDisabled.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.disable');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = true;
|
||||
siteSettings.get(toggles[i].name).set('action', 'disabled');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultActionSettings[toggles[0].lang] = 'disabled';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllSearchFilter = document.getElementById('setAllSearchFilter');
|
||||
setAllSearchFilter.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.filter');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = true;
|
||||
siteSettings.get(toggles[i].name).set('searchFilter', 'true');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultSearchFilterSettings[toggles[0].lang] = 'true';
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSettings': defaultSearchFilterSettings });
|
||||
});
|
||||
|
||||
var setNoneSearchFilter = document.getElementById('setNoneSearchFilter');
|
||||
setNoneSearchFilter.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.filter');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = false;
|
||||
siteSettings.get(toggles[i].name).set('searchFilter', 'false');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultSearchFilterSettings[toggles[0].lang] = 'false';
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSettings': defaultSearchFilterSettings });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -361,8 +88,12 @@ function setPower(setting) {
|
|||
chrome.storage.sync.set({ 'power': setting });
|
||||
var powerImage = document.getElementById('powerImage');
|
||||
powerImage.src = 'images/power-' + setting + '.png';
|
||||
var powerText = document.getElementById('powerText');
|
||||
powerText.textContent = 'Indie Wiki Buddy is ' + setting;
|
||||
powerImage.alt = 'Indie Wiki Buddy is ' + setting;
|
||||
if (setting === 'on') {
|
||||
document.getElementById('powerCheckbox').checked = true;
|
||||
} else {
|
||||
document.getElementById('powerCheckbox').checked = false;
|
||||
}
|
||||
|
||||
chrome.runtime.sendMessage({
|
||||
action: 'updateIcon',
|
||||
|
@ -373,28 +104,31 @@ function setPower(setting) {
|
|||
// Set notifications setting
|
||||
function setNotifications(setting) {
|
||||
chrome.storage.sync.set({ 'notifications': setting });
|
||||
var notificationsImage = document.getElementById('notificationsImage');
|
||||
notificationsImage.src = 'images/bell-' + setting + '.png';
|
||||
var notificationsText = document.getElementById('notificationsText');
|
||||
notificationsText.textContent = 'Notify-on-redirect is ' + setting;
|
||||
if (setting === 'on') {
|
||||
document.getElementById('notificationsCheckbox').checked = true;
|
||||
} else {
|
||||
document.getElementById('notificationsCheckbox').checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set search filter setting
|
||||
function setSearchFilter(setting) {
|
||||
chrome.storage.sync.set({ 'searchFilter': setting });
|
||||
var searchFilterImage = document.getElementById('searchFilterImage');
|
||||
searchFilterImage.src = 'images/check-' + setting + '.png';
|
||||
var searchFilterText = document.getElementById('searchFilterText');
|
||||
searchFilterText.textContent = 'Search engine filtering is ' + setting;
|
||||
if (setting === 'on') {
|
||||
document.getElementById('searchFilterCheckbox').checked = true;
|
||||
} else {
|
||||
document.getElementById('searchFilterCheckbox').checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set BreezeWiki settings
|
||||
function setBreezeWiki(setting) {
|
||||
chrome.storage.sync.set({ 'breezewiki': setting });
|
||||
var breezewikiImage = document.getElementById('breezewikiImage');
|
||||
breezewikiImage.src = 'images/check-' + setting + '.png';
|
||||
var breezewikiText = document.getElementById('breezewikiText');
|
||||
breezewikiText.textContent = 'BreezeWiki is ' + setting;
|
||||
if (setting === 'on') {
|
||||
document.getElementById('breezewikiCheckbox').checked = true;
|
||||
} else {
|
||||
document.getElementById('breezewikiCheckbox').checked = false;
|
||||
}
|
||||
var breezewikiHost = document.getElementById('breezewikiHost');
|
||||
if (setting === 'on') {
|
||||
breezewikiHost.style.display = 'block';
|
||||
|
@ -427,22 +161,12 @@ function setBreezeWiki(setting) {
|
|||
|
||||
// Main function that runs on-load
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Adding version to popup:
|
||||
const version = chrome.runtime.getManifest().version;
|
||||
document.getElementById('version').textContent = 'Version ' + version;
|
||||
loadBreezeWikiOptions();
|
||||
|
||||
// Get user's last set language
|
||||
chrome.storage.sync.get({ 'lang': 'EN' }, function (item) {
|
||||
langSelect.value = item.lang;
|
||||
chrome.storage.sync.set({ 'lang': item.lang });
|
||||
loadOptions(item.lang);
|
||||
});
|
||||
// Add event listener for language select
|
||||
var langSelect = document.getElementById("langSelect");
|
||||
langSelect.addEventListener('change', function () {
|
||||
chrome.storage.sync.set({ 'lang': langSelect.value });
|
||||
resetOptions();
|
||||
loadOptions(langSelect.value);
|
||||
// Listener for settings page in new tab:
|
||||
document.getElementById('openSettings').addEventListener('click', function () {
|
||||
chrome.tabs.create({'url': chrome.extension.getURL('settings.html')});
|
||||
window.close();
|
||||
});
|
||||
|
||||
// Set setting toggle values:
|
||||
|
@ -460,7 +184,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
});
|
||||
|
||||
// Add event listeners for setting toggles
|
||||
document.getElementById('powerButton').addEventListener('change', function () {
|
||||
document.getElementById('powerCheckbox').addEventListener('change', function () {
|
||||
chrome.storage.sync.get({ 'power': 'on' }, function (item) {
|
||||
if (item.power === 'on') {
|
||||
setPower('off');
|
||||
|
@ -469,7 +193,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
}
|
||||
});
|
||||
});
|
||||
document.getElementById('notificationsButton').addEventListener('change', function () {
|
||||
document.getElementById('notificationsCheckbox').addEventListener('change', function () {
|
||||
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
|
||||
if (item.notifications === 'on') {
|
||||
setNotifications('off');
|
||||
|
@ -478,7 +202,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
}
|
||||
});
|
||||
});
|
||||
document.getElementById('searchFilterButton').addEventListener('change', function () {
|
||||
document.getElementById('searchFilterCheckbox').addEventListener('change', function () {
|
||||
chrome.storage.sync.get({ 'searchFilter': 'on' }, function (item) {
|
||||
if (item.searchFilter === 'on') {
|
||||
setSearchFilter('off');
|
||||
|
@ -487,7 +211,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
}
|
||||
});
|
||||
});
|
||||
document.getElementById('breezewikiButton').addEventListener('change', function () {
|
||||
document.getElementById('breezewikiCheckbox').addEventListener('change', function () {
|
||||
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
|
||||
if (item.breezewiki === 'on') {
|
||||
setBreezeWiki('off');
|
||||
|
@ -500,21 +224,4 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
breezewikiHostSelect.addEventListener('change', function () {
|
||||
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
|
||||
});
|
||||
|
||||
// Get and display stat counts
|
||||
chrome.storage.sync.get({ 'countAlerts': 0 }, function (item) {
|
||||
var key = Object.keys(item)[0];
|
||||
chrome.storage.sync.set({ 'countAlerts': item[key] });
|
||||
document.getElementById('countAlerts').textContent = item[key];
|
||||
});
|
||||
chrome.storage.sync.get({ 'countRedirects': 0 }, function (item) {
|
||||
var key = Object.keys(item)[0];
|
||||
chrome.storage.sync.set({ 'countRedirects': item[key] });
|
||||
document.getElementById('countRedirects').textContent = item[key];
|
||||
});
|
||||
chrome.storage.sync.get({ 'countSearchFilters': 0 }, function (item) {
|
||||
var key = Object.keys(item)[0];
|
||||
chrome.storage.sync.set({ 'countSearchFilters': item[key] });
|
||||
document.getElementById('countSearchFilters').textContent = item[key];
|
||||
});
|
||||
});
|
|
@ -0,0 +1,397 @@
|
|||
<!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 settings</title>
|
||||
<style>
|
||||
/* ELEMENTS */
|
||||
body {
|
||||
width: 600px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #2b2a33;
|
||||
font-family: Helvetica, Sans-Serif;
|
||||
font-size: .9em;
|
||||
}
|
||||
|
||||
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: .8em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
display: inline-block;
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
/* HEADER */
|
||||
#header {
|
||||
line-height: 1.5em;
|
||||
padding: .5em 1em;
|
||||
box-sizing: border-box;
|
||||
background-color: #005799;
|
||||
color: #fff;
|
||||
width: 100%;
|
||||
}
|
||||
#header .settingToggle label {
|
||||
background-color: #fff;
|
||||
border-radius: 20px;
|
||||
height: fit-content;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
#version {
|
||||
float: right;
|
||||
font-size: 1.2rem;
|
||||
margin: .5em 0;
|
||||
}
|
||||
|
||||
#links {
|
||||
background-color: #e5f4ff;
|
||||
padding: .5em 1em;
|
||||
}
|
||||
|
||||
/* CONTENT */
|
||||
#content {
|
||||
background-color: #fff;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* FOOTER */
|
||||
#footer {
|
||||
padding-bottom: 1em;
|
||||
text-align: center;
|
||||
line-height: 1.6em;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
#footer a {
|
||||
padding: 5px 0px;
|
||||
color: #3174f1;
|
||||
}
|
||||
|
||||
/* GLOBAL SETTINGS SECTION */
|
||||
.options {
|
||||
margin: 0 auto;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 10px;
|
||||
padding: 6px 0px 12px 10px;
|
||||
user-select: none;
|
||||
width: fit-content;
|
||||
}
|
||||
.options .settingToggleContainer {
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.options .settingToggleContainer:last-child {
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
/* GLOBAL SETTING TOGGLES */
|
||||
#power input {
|
||||
height: 0;
|
||||
width: 0;
|
||||
margin: 0;
|
||||
border: none;
|
||||
appearance: none;
|
||||
}
|
||||
#power img {
|
||||
margin-left: -8px;
|
||||
}
|
||||
|
||||
.settingToggle {
|
||||
cursor: pointer;
|
||||
width: fit-content;
|
||||
display: inline-block;
|
||||
}
|
||||
.settingToggle + div {
|
||||
display: inline-block;
|
||||
}
|
||||
.settingToggle input,
|
||||
.settingToggle label {
|
||||
cursor: pointer;
|
||||
}
|
||||
.settingToggle img {
|
||||
width: 30px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
#breezewikiHost {
|
||||
display: none;
|
||||
padding-left: 3em;
|
||||
}
|
||||
#breezewikiHost label {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* WIKI CONTROLS */
|
||||
#wikiControls {
|
||||
margin: 0 auto;
|
||||
width: fit-content;
|
||||
text-align: center;
|
||||
padding-bottom: .5em;
|
||||
}
|
||||
#wikiControls button {
|
||||
background: #ffffff;
|
||||
border: 1px solid #333333;
|
||||
color: #333333;
|
||||
border-radius: 5px;
|
||||
padding: 3px 5px;
|
||||
margin: 3px 5px;
|
||||
}
|
||||
#wikiControls button:hover {
|
||||
cursor: pointer;
|
||||
background: #3174f1;
|
||||
border: 1px solid#3174f1;
|
||||
color: #ffffff;
|
||||
}
|
||||
#wikiControls button:hover img {
|
||||
filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(288deg) brightness(100%) contrast(100%);
|
||||
}
|
||||
|
||||
#langSelectContainer {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#toggles {
|
||||
font-size: 0.8rem;
|
||||
white-space: nowrap;
|
||||
position: relative;
|
||||
padding: 0px 2px;
|
||||
}
|
||||
#toggles > div:hover {
|
||||
background-color: #e8f0fe;
|
||||
}
|
||||
#toggles input {
|
||||
cursor: pointer;
|
||||
}
|
||||
#toggles > div {
|
||||
line-height: 1.8em;
|
||||
}
|
||||
#toggles img {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
max-height: 1.2em;
|
||||
}
|
||||
#toggles a {
|
||||
float: right;
|
||||
padding-right: 10px;
|
||||
clear: both;
|
||||
}
|
||||
#toggles span {
|
||||
padding-left: .7em;
|
||||
}
|
||||
#togglesKey {
|
||||
padding-left: 7px;
|
||||
}
|
||||
#togglesKey > div {
|
||||
display: inline-block;
|
||||
width: 17px;
|
||||
}
|
||||
|
||||
#togglesKey>div:last-child, #toggles>div>label:last-of-type {
|
||||
margin-left: .5em;
|
||||
}
|
||||
|
||||
/* CONTROL CLASSES */
|
||||
.visuallyHidden {
|
||||
position: absolute !important;
|
||||
width: 1px !important;
|
||||
height: 1px !important;
|
||||
padding: 0 !important;
|
||||
margin: -1px !important;
|
||||
overflow: hidden !important;
|
||||
clip: rect(0, 0, 0, 0) !important;
|
||||
white-space: nowrap !important;
|
||||
border: 0 !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="header">
|
||||
<span id="version"></span>
|
||||
<h1>Indie Wiki Buddy</h1>
|
||||
</div>
|
||||
<div id="links">
|
||||
<a
|
||||
href="https://getindie.wiki/#guide"
|
||||
target="_blank"
|
||||
>Guide</a
|
||||
>
|
||||
|
||||
<a
|
||||
href="https://getindie.wiki/changelog/"
|
||||
target="_blank"
|
||||
>Changelog</a
|
||||
>
|
||||
|
||||
<a
|
||||
href="https://getindie.wiki/#submit"
|
||||
target="_blank"
|
||||
>Submit a Wiki</a
|
||||
>
|
||||
|
||||
<a
|
||||
href="https://github.com/KevinPayravi/indie-wiki-buddy"
|
||||
target="_blank"
|
||||
>Source Code</a
|
||||
>
|
||||
</div>
|
||||
<div id="content">
|
||||
<h2>Global settings</h2>
|
||||
<div class="options">
|
||||
<div class="settingToggleContainer">
|
||||
<div id="power" class="settingToggle">
|
||||
<input id="powerCheckbox" type="checkbox" />
|
||||
<label for="powerCheckbox">
|
||||
<img id="powerImage" src="" alt="" />
|
||||
<span id="powerText"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingToggleContainer">
|
||||
<div id="notifications" class="settingToggle">
|
||||
<input id="notificationsCheckbox" type="checkbox" />
|
||||
<label for="notificationsCheckbox">
|
||||
<span id="notificationsText">🔔 Receive desktop notifications when you are redirected to a wiki</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingToggleContainer">
|
||||
<div id="searchFilter" class="settingToggle">
|
||||
<input id="searchFilterCheckbox" type="checkbox" />
|
||||
<label for="searchFilterCheckbox">
|
||||
<span id="searchFilterText">🔎 Filter non-indie wiki results in Google, Bing, & DuckDuckGo</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingToggleContainer">
|
||||
<div id="breezewiki" class="settingToggle">
|
||||
<input id="breezewikiCheckbox" type="checkbox" />
|
||||
<label for="breezewikiCheckbox">
|
||||
<span id="breezewikiText">🌬️ Use BreezeWiki on Fandom</span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<div>
|
||||
(<a href="https://breezewiki.com/" target="_blank"
|
||||
>learn more</a
|
||||
>)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingToggleContainer">
|
||||
<div id="breezewikiHost" class="settingToggle">
|
||||
<label for="breezewikiHostSelect">BreezeWiki Host: </label>
|
||||
<select name="breezewikiHost" id="breezewikiHostSelect"></select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div id="wikiControls">
|
||||
<h2>Individual wiki settings</h2>
|
||||
<div id="langSelectContainer">
|
||||
Viewing wikis in:
|
||||
<select name="lang" id="langSelect">
|
||||
<option value="DE">Deutsch</option>
|
||||
<option value="EN" selected>English</option>
|
||||
<option value="ES">Español</option>
|
||||
<option value="FR">Français</option>
|
||||
<option value="IT">Italiano</option>
|
||||
<option value="PL">Polski</option>
|
||||
<option value="TOK">Toki Pona</option>
|
||||
</select>
|
||||
</div>
|
||||
Controls to change settings for all wikis:
|
||||
<br />
|
||||
<button id="setAllDisabled">
|
||||
<img src="images/toggle-disabled.png" width="10" alt="" /> Disable all
|
||||
</button>
|
||||
<button id="setAllRedirect">
|
||||
<img src="images/toggle-redirect.png" width="10" alt="" /> Set all to
|
||||
redirect to indie wikis
|
||||
</button>
|
||||
<button id="setAllAlert">
|
||||
<img src="images/toggle-alert.png" width="10" alt="" /> Set all to
|
||||
alert of indie wikis
|
||||
</button>
|
||||
<br />
|
||||
<button id="setAllSearchFilter">
|
||||
<img src="images/toggle-search-filter.png" width="10" alt="" /> Filter
|
||||
all wikis from search engines
|
||||
</button>
|
||||
<button id="setNoneSearchFilter">
|
||||
<img src="images/toggle-search-filter.png" width="10" alt="" /> Filter
|
||||
no wikis from search engines
|
||||
</button>
|
||||
</div>
|
||||
<div id="togglesKey">
|
||||
<div>
|
||||
<img
|
||||
src="images/toggle-disabled.png"
|
||||
width="15"
|
||||
alt="Disable"
|
||||
title="Disable"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<img
|
||||
src="images/toggle-redirect.png"
|
||||
width="15"
|
||||
alt="Automatically redirect to indie wiki"
|
||||
title="Automatically redirect to indie wiki"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<img
|
||||
src="images/toggle-alert.png"
|
||||
width="15"
|
||||
alt="Show a banner on wikis where an indie alterantive is available"
|
||||
title="Show a banner on wikis where an indie alterantive is available"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<img
|
||||
src="images/toggle-search-filter.png"
|
||||
width="15"
|
||||
alt="Filter results from search engines"
|
||||
title="Filter results from search engines"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div id="toggles"></div>
|
||||
<hr />
|
||||
<div id="footer">
|
||||
<h2>Fun Stats</h2>
|
||||
You have been alerted to indie wikis <span id="countAlerts"></span> times.
|
||||
<br />
|
||||
You have been automatically redirected to indie wikis <span id="countRedirects"></span> times.
|
||||
<br />
|
||||
You have had <span id="countSearchFilters"></span> search engine results filtered.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript" src="settings.js"></script>
|
||||
</html>
|
|
@ -0,0 +1,528 @@
|
|||
const LANGS = ["DE", "EN", "ES", "FR", "IT", "PL", "TOK"];
|
||||
var sites = [];
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Clear wiki toggles
|
||||
// Used when switching languages
|
||||
function resetOptions() {
|
||||
var toggleContainer = document.getElementById('toggles');
|
||||
toggleContainer.textContent = "";
|
||||
|
||||
// Clone "select all" buttons to reset listeners
|
||||
document.getElementById('setAllRedirect').cloneNode(true);
|
||||
document.getElementById('setAllAlert').cloneNode(true);
|
||||
document.getElementById('setAllDisabled').cloneNode(true);
|
||||
document.getElementById('setAllSearchFilter').cloneNode(true);
|
||||
document.getElementById('setNoneSearchFilter').cloneNode(true);
|
||||
}
|
||||
|
||||
// Get wiki data from data folder
|
||||
async function getData() {
|
||||
var 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())
|
||||
.then(function (jsonData) {
|
||||
jsonData.forEach((site) => site.language = LANGS[i]);
|
||||
sites = sites.concat(jsonData);
|
||||
}));
|
||||
}
|
||||
await Promise.all(promises);
|
||||
return sites;
|
||||
}
|
||||
|
||||
// Populate popup settings and toggles
|
||||
async function loadOptions(lang) {
|
||||
sites = await getData();
|
||||
|
||||
chrome.storage.sync.get(function (storage) {
|
||||
let siteSettings = storage.siteSettings || {};
|
||||
let defaultActionSettings = storage.defaultActionSettings || {};
|
||||
let defaultSearchFilterSettings = storage.defaultSearchFilterSettings || {};
|
||||
|
||||
// Load BreezeWiki options:
|
||||
chrome.storage.sync.get(['breezewikiHostOptions', 'breezewikiHostFetchTimestamp', 'breezewikiHost'], function (item) {
|
||||
let hostOptions = item.breezewikiHostOptions;
|
||||
let hostFetchTimestamp = item.breezewikiHostFetchTimestamp;
|
||||
let host = item.breezewikiHost;
|
||||
// Fetch and cache list of BreezeWiki hosts if first time,
|
||||
// or if it has been 24 hrs since last refresh
|
||||
if (!host || !hostOptions || !hostFetchTimestamp || (Date.now() - 86400000 > hostFetchTimestamp)) {
|
||||
fetch('https://bw.getindie.wiki/instances.json')
|
||||
.then((response) => response.json())
|
||||
.then((breezewikiHosts) => {
|
||||
// If host isn't set, or currently selected host is no longer available, select random host:
|
||||
if (!host || !breezewikiHosts.some(item => item.instance === host)) {
|
||||
// Check if BreezeWiki's main site is available
|
||||
let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com');
|
||||
if (breezewikiMain.length > 0) {
|
||||
host = breezewikiMain[0].instance;
|
||||
} else {
|
||||
// If BreezeWiki.com is not available, set to a random mirror
|
||||
host = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance;
|
||||
}
|
||||
}
|
||||
// Populate dropdown selection of hosts
|
||||
const breezewikiHostSelect = document.getElementById('breezewikiHostSelect');
|
||||
for (var i = 0; i < breezewikiHosts.length; i++) {
|
||||
let option = document.createElement('option');
|
||||
option.value = breezewikiHosts[i].instance;
|
||||
let innerText = breezewikiHosts[i].instance.replace('https://', '');
|
||||
const numberOfPeriods = (innerText.match(/\./g)||[]).length;
|
||||
if (numberOfPeriods > 1) {
|
||||
innerText = innerText.substring(innerText.indexOf('.') + 1);
|
||||
}
|
||||
option.innerText = innerText;
|
||||
breezewikiHostSelect.appendChild(option);
|
||||
if (option.value === host) {
|
||||
breezewikiHostSelect.value = host;
|
||||
}
|
||||
}
|
||||
// Store BreezeWiki host details
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
||||
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
|
||||
});
|
||||
} else {
|
||||
// If currently selected host is no longer available, select random host:
|
||||
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');
|
||||
for (var i = 0; i < hostOptions.length; i++) {
|
||||
let option = document.createElement('option');
|
||||
option.value = hostOptions[i].instance;
|
||||
let innerText = hostOptions[i].instance.replace('https://', '');
|
||||
const numberOfPeriods = (innerText.match(/\./g)||[]).length;
|
||||
if (numberOfPeriods > 1) {
|
||||
innerText = innerText.substring(innerText.indexOf('.') + 1);
|
||||
}
|
||||
option.innerText = innerText;
|
||||
breezewikiHostSelect.appendChild(option);
|
||||
if (option.value === host) {
|
||||
breezewikiHostSelect.value = host;
|
||||
}
|
||||
}
|
||||
// Store BreezeWiki host details
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host });
|
||||
}
|
||||
});
|
||||
|
||||
// Populate individual wiki settings:
|
||||
var toggleContainer = document.getElementById('toggles');
|
||||
for (var i = 0; i < sites.length; i++) {
|
||||
if (sites[i].language === lang) {
|
||||
var key = sites[i].id;
|
||||
|
||||
// Create radio for disabled:
|
||||
let labelDisabled = document.createElement("label");
|
||||
let inputDisabled = document.createElement("input");
|
||||
inputDisabled.classList = 'toggleDisable';
|
||||
inputDisabled.type = "radio";
|
||||
inputDisabled.name = key;
|
||||
inputDisabled.title = 'Disable actions for ' + sites[i].origin;
|
||||
inputDisabled.id = key + '-redirect';
|
||||
inputDisabled.lang = lang;
|
||||
|
||||
// Create radio for redirect:
|
||||
let labelRedirect = document.createElement("label");
|
||||
let inputRedirect = document.createElement("input");
|
||||
inputRedirect.classList = 'toggleRedirect';
|
||||
inputRedirect.type = "radio";
|
||||
inputRedirect.name = key;
|
||||
inputRedirect.title = 'Automatically redirect from ' + sites[i].origin + ' to ' + sites[i].destination;
|
||||
inputRedirect.id = key + '-redirect';
|
||||
inputRedirect.lang = lang;
|
||||
|
||||
// Create radio for alert:
|
||||
let labelAlert = document.createElement("label");
|
||||
let inputAlert = document.createElement("input");
|
||||
inputAlert.classList = 'toggleAlert';
|
||||
inputAlert.type = "radio";
|
||||
inputAlert.name = key;
|
||||
inputAlert.title = 'Notify with banner when visiting ' + sites[i].origin;
|
||||
inputAlert.id = key + '-alert';
|
||||
inputAlert.lang = lang;
|
||||
|
||||
// Create checkbox for search filtering:
|
||||
let labelFilter = document.createElement("label");
|
||||
let inputFilter = document.createElement("input");
|
||||
inputFilter.classList = 'toggleFilter';
|
||||
inputFilter.type = 'checkbox';
|
||||
inputFilter.name = key;
|
||||
inputFilter.title = 'Filter from search results on Google, Bing, and DuckDuckGo';
|
||||
inputFilter.id = key + '-filter';
|
||||
inputFilter.lang = lang;
|
||||
|
||||
// Check radio button based on user's settings
|
||||
// Will default to alert or the last "select all" setting the user chose
|
||||
if (siteSettings[key] && siteSettings[key].action) {
|
||||
if (siteSettings[key].action === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (siteSettings[key].action === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
} else {
|
||||
let actionSetting = defaultActionSettings[lang];
|
||||
if (actionSetting) {
|
||||
if (actionSetting === 'disabled') {
|
||||
inputDisabled.checked = true;
|
||||
} else if (actionSetting === 'redirect') {
|
||||
inputRedirect.checked = true;
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
} else {
|
||||
inputAlert.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check search filter checkbox based on user's settings (default filter):
|
||||
if (siteSettings[key] && siteSettings[key].searchFilter) {
|
||||
if (siteSettings[key].searchFilter === 'false') {
|
||||
inputFilter.checked = false;
|
||||
} else {
|
||||
inputFilter.checked = true;
|
||||
}
|
||||
} else {
|
||||
let searchFilterSetting = defaultSearchFilterSettings[lang];
|
||||
if (searchFilterSetting && searchFilterSetting === 'false') {
|
||||
inputFilter.checked = false;
|
||||
} else {
|
||||
inputFilter.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Add listeners for when user clicks control:
|
||||
inputRedirect.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
response.siteSettings.get(key).set('action', 'redirect');
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
});
|
||||
inputAlert.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
response.siteSettings.get(key).set('action', 'alert');
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
});
|
||||
inputDisabled.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
response.siteSettings.get(key).set('action', 'disabled');
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
});
|
||||
inputFilter.addEventListener('click', function (input) {
|
||||
chrome.storage.sync.get({ 'siteSettings': {} }, function (response) {
|
||||
var key = input.target.name;
|
||||
if (input.target.checked === true) {
|
||||
response.siteSettings.get(key).set('searchFilter', 'true');
|
||||
} else {
|
||||
response.siteSettings.get(key).set('searchFilter', 'false');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': response.siteSettings });
|
||||
});
|
||||
});
|
||||
|
||||
// Output disable radio button:
|
||||
let inputDisabledText = document.createElement('span');
|
||||
inputDisabledText.classList.add('visuallyHidden');
|
||||
inputDisabledText.textContent = 'Disable action for ' + sites[i].origin;
|
||||
labelDisabled.appendChild(inputDisabled);
|
||||
labelDisabled.appendChild(inputDisabledText);
|
||||
|
||||
// Output redirect radio button:
|
||||
let inputRedirectText = document.createElement('span');
|
||||
inputRedirectText.classList.add('visuallyHidden');
|
||||
inputRedirectText.textContent = 'Automatically redirect ' + sites[i].origin;
|
||||
labelRedirect.appendChild(inputRedirect);
|
||||
labelRedirect.appendChild(inputRedirectText);
|
||||
|
||||
// Output alert radio button:
|
||||
let inputAlertText = document.createElement('span');
|
||||
inputAlertText.classList.add('visuallyHidden');
|
||||
inputAlertText.textContent = 'Automatically alert for' + sites[i].origin;
|
||||
labelAlert.appendChild(inputAlert);
|
||||
labelAlert.appendChild(inputAlertText);
|
||||
|
||||
// Output search filter checkbox:
|
||||
let inputFilterText = document.createElement('span');
|
||||
inputFilterText.classList.add('visuallyHidden');
|
||||
inputFilterText.textContent = 'Filter ' + sites[i].origin + ' from search engine results';
|
||||
labelFilter.appendChild(inputFilter);
|
||||
labelFilter.appendChild(inputFilterText);
|
||||
|
||||
// Output icon
|
||||
let iconLink = document.createElement("a");
|
||||
iconLink.href = 'https://' + sites[i].destination_base_url + sites[i].destination_content_path;
|
||||
iconLink.title = 'Visit ' + sites[i].destination;
|
||||
iconLink.target = '_blank';
|
||||
let icon = document.createElement("img");
|
||||
icon.src = 'favicons/' + lang.toLowerCase() + '/' + sites[i].destination_icon;
|
||||
icon.alt = 'Visit ' + sites[i].destination;
|
||||
iconLink.appendChild(icon);
|
||||
|
||||
// Output text:
|
||||
let text = document.createElement('span');
|
||||
text.textContent = sites[i].origin + ' » ' + sites[i].destination;
|
||||
let siteContainer = document.createElement("div");
|
||||
|
||||
siteContainer.appendChild(labelDisabled);
|
||||
siteContainer.appendChild(labelRedirect);
|
||||
siteContainer.appendChild(labelAlert);
|
||||
siteContainer.appendChild(labelFilter);
|
||||
siteContainer.appendChild(iconLink);
|
||||
siteContainer.appendChild(text);
|
||||
|
||||
toggleContainer.appendChild(siteContainer);
|
||||
}
|
||||
}
|
||||
|
||||
// Add "select all" button event listeners:
|
||||
var setAllRedirect = document.getElementById('setAllRedirect');
|
||||
setAllRedirect.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.toggleRedirect');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = true;
|
||||
siteSettings.get(toggles[i].name).set('action', 'redirect');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultActionSettings[toggles[0].lang] = 'redirect';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllAlert = document.getElementById('setAllAlert');
|
||||
setAllAlert.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.toggleAlert');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = true;
|
||||
siteSettings.get(toggles[i].name).set('action', 'alert');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultActionSettings[toggles[0].lang] = 'alert';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllDisabled = document.getElementById('setAllDisabled');
|
||||
setAllDisabled.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.toggleDisable');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = true;
|
||||
siteSettings.get(toggles[i].name).set('action', 'disabled');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultActionSettings[toggles[0].lang] = 'disabled';
|
||||
chrome.storage.sync.set({ 'defaultActionSettings': defaultActionSettings });
|
||||
});
|
||||
|
||||
var setAllSearchFilter = document.getElementById('setAllSearchFilter');
|
||||
setAllSearchFilter.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.toggleFilter');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = true;
|
||||
siteSettings.get(toggles[i].name).set('searchFilter', 'true');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultSearchFilterSettings[toggles[0].lang] = 'true';
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSettings': defaultSearchFilterSettings });
|
||||
});
|
||||
|
||||
var setNoneSearchFilter = document.getElementById('setNoneSearchFilter');
|
||||
setNoneSearchFilter.addEventListener('click', function () {
|
||||
var toggles = document.querySelectorAll('#toggles input.toggleFilter');
|
||||
for (var i = 0; i < toggles.length; i++) {
|
||||
toggles[i].checked = false;
|
||||
siteSettings.get(toggles[i].name).set('searchFilter', 'false');
|
||||
}
|
||||
chrome.storage.sync.set({ 'siteSettings': siteSettings });
|
||||
defaultSearchFilterSettings[toggles[0].lang] = 'false';
|
||||
chrome.storage.sync.set({ 'defaultSearchFilterSettings': defaultSearchFilterSettings });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Set power setting
|
||||
function setPower(setting) {
|
||||
chrome.storage.sync.set({ 'power': setting });
|
||||
var powerImage = document.getElementById('powerImage');
|
||||
powerImage.src = 'images/power-' + setting + '.png';
|
||||
var powerText = document.getElementById('powerText');
|
||||
powerText.textContent = 'Extension is ' + setting;
|
||||
if (setting === 'on') {
|
||||
document.getElementById('powerCheckbox').checked = true;
|
||||
} else {
|
||||
document.getElementById('powerCheckbox').checked = false;
|
||||
}
|
||||
|
||||
chrome.runtime.sendMessage({
|
||||
action: 'updateIcon',
|
||||
value: setting
|
||||
});
|
||||
}
|
||||
|
||||
// Set notifications setting
|
||||
function setNotifications(setting) {
|
||||
chrome.storage.sync.set({ 'notifications': setting });
|
||||
if (setting === 'on') {
|
||||
document.getElementById('notificationsCheckbox').checked = true;
|
||||
} else {
|
||||
document.getElementById('notificationsCheckbox').checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set search filter setting
|
||||
function setSearchFilter(setting) {
|
||||
chrome.storage.sync.set({ 'searchFilter': setting });
|
||||
if (setting === 'on') {
|
||||
document.getElementById('searchFilterCheckbox').checked = true;
|
||||
} else {
|
||||
document.getElementById('searchFilterCheckbox').checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set BreezeWiki settings
|
||||
function setBreezeWiki(setting) {
|
||||
chrome.storage.sync.set({ 'breezewiki': setting });
|
||||
var breezewikiHost = document.getElementById('breezewikiHost');
|
||||
if (setting === 'on') {
|
||||
document.getElementById('breezewikiCheckbox').checked = true;
|
||||
} else {
|
||||
document.getElementById('breezewikiCheckbox').checked = false;
|
||||
}
|
||||
if (setting === 'on') {
|
||||
breezewikiHost.style.display = 'inline';
|
||||
chrome.storage.sync.get({ 'breezewikiHost': null }, function (host) {
|
||||
if (!host.breezewikiHost) {
|
||||
fetch('https://bw.getindie.wiki/instances.json')
|
||||
.then((response) => response.json())
|
||||
.then((breezewikiHosts) => {
|
||||
// Check if BreezeWiki's main site is available
|
||||
let breezewikiMain = breezewikiHosts.filter(host => host.instance === 'https://breezewiki.com');
|
||||
if (breezewikiMain.length > 0) {
|
||||
host.breezewikiHost = breezewikiMain[0].instance;
|
||||
} else {
|
||||
// If BreezeWiki.com is not available, set to a random mirror
|
||||
host.breezewikiHost = breezewikiHosts[Math.floor(Math.random() * breezewikiHosts.length)].instance;
|
||||
}
|
||||
chrome.storage.sync.set({ 'breezewikiHost': host.breezewikiHost });
|
||||
chrome.storage.sync.set({ 'breezewikiHostOptions': breezewikiHosts });
|
||||
chrome.storage.sync.set({ 'breezewikiHostFetchTimestamp': Date.now() });
|
||||
document.getElementById('breezewikiHostSelect').value = host.breezewikiHost;
|
||||
});
|
||||
} else {
|
||||
document.getElementById('breezewikiHostSelect').value = host.breezewikiHost;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
breezewikiHost.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Main function that runs on-load
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Adding version to popup:
|
||||
const version = chrome.runtime.getManifest().version;
|
||||
document.getElementById('version').textContent = 'v' + version;
|
||||
|
||||
// Get user's last set language
|
||||
chrome.storage.sync.get({ 'lang': 'EN' }, function (item) {
|
||||
langSelect.value = item.lang;
|
||||
chrome.storage.sync.set({ 'lang': item.lang });
|
||||
loadOptions(item.lang);
|
||||
});
|
||||
// Add event listener for language select
|
||||
var langSelect = document.getElementById("langSelect");
|
||||
langSelect.addEventListener('change', function () {
|
||||
chrome.storage.sync.set({ 'lang': langSelect.value });
|
||||
resetOptions();
|
||||
loadOptions(langSelect.value);
|
||||
});
|
||||
|
||||
// Set setting toggle values:
|
||||
chrome.storage.sync.get({ 'power': 'on' }, function (item) {
|
||||
setPower(item.power);
|
||||
});
|
||||
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
|
||||
setNotifications(item.notifications);
|
||||
});
|
||||
chrome.storage.sync.get({ 'searchFilter': 'on' }, function (item) {
|
||||
setSearchFilter(item.searchFilter);
|
||||
});
|
||||
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
|
||||
setBreezeWiki(item.breezewiki);
|
||||
});
|
||||
|
||||
// Add event listeners for setting toggles
|
||||
document.getElementById('powerCheckbox').addEventListener('change', function () {
|
||||
chrome.storage.sync.get({ 'power': 'on' }, function (item) {
|
||||
if (item.power === 'on') {
|
||||
setPower('off');
|
||||
} else {
|
||||
setPower('on');
|
||||
}
|
||||
});
|
||||
});
|
||||
document.getElementById('notificationsCheckbox').addEventListener('change', function () {
|
||||
chrome.storage.sync.get({ 'notifications': 'on' }, function (item) {
|
||||
if (item.notifications === 'on') {
|
||||
setNotifications('off');
|
||||
} else {
|
||||
setNotifications('on');
|
||||
}
|
||||
});
|
||||
});
|
||||
document.getElementById('searchFilterCheckbox').addEventListener('change', function () {
|
||||
chrome.storage.sync.get({ 'searchFilter': 'on' }, function (item) {
|
||||
if (item.searchFilter === 'on') {
|
||||
setSearchFilter('off');
|
||||
} else {
|
||||
setSearchFilter('on');
|
||||
}
|
||||
});
|
||||
});
|
||||
document.getElementById('breezewikiCheckbox').addEventListener('change', function () {
|
||||
chrome.storage.sync.get({ 'breezewiki': 'off' }, function (item) {
|
||||
if (item.breezewiki === 'on') {
|
||||
setBreezeWiki('off');
|
||||
} else {
|
||||
setBreezeWiki('on');
|
||||
}
|
||||
});
|
||||
});
|
||||
var breezewikiHostSelect = document.getElementById("breezewikiHostSelect");
|
||||
breezewikiHostSelect.addEventListener('change', function () {
|
||||
chrome.storage.sync.set({ 'breezewikiHost': breezewikiHostSelect.value });
|
||||
});
|
||||
|
||||
// Get and display stat counts
|
||||
chrome.storage.sync.get({ 'countAlerts': 0 }, function (item) {
|
||||
var key = Object.keys(item)[0];
|
||||
chrome.storage.sync.set({ 'countAlerts': item[key] });
|
||||
document.getElementById('countAlerts').textContent = item[key];
|
||||
});
|
||||
chrome.storage.sync.get({ 'countRedirects': 0 }, function (item) {
|
||||
var key = Object.keys(item)[0];
|
||||
chrome.storage.sync.set({ 'countRedirects': item[key] });
|
||||
document.getElementById('countRedirects').textContent = item[key];
|
||||
});
|
||||
chrome.storage.sync.get({ 'countSearchFilters': 0 }, function (item) {
|
||||
var key = Object.keys(item)[0];
|
||||
chrome.storage.sync.set({ 'countSearchFilters': item[key] });
|
||||
document.getElementById('countSearchFilters').textContent = item[key];
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue