2019-10-07 13:59:31 +02:00
|
|
|
'use strict';
|
|
|
|
|
2020-04-25 10:31:27 +02:00
|
|
|
let nitterInstance = document.getElementById('nitter-instance');
|
|
|
|
let invidiousInstance = document.getElementById('invidious-instance');
|
|
|
|
let bibliogramInstance = document.getElementById('bibliogram-instance');
|
|
|
|
let osmInstance = document.getElementById('osm-instance');
|
|
|
|
let disableNitter = document.getElementById('disable-nitter');
|
|
|
|
let disableInvidious = document.getElementById('disable-invidious');
|
|
|
|
let disableBibliogram = document.getElementById('disable-bibliogram');
|
|
|
|
let disableOsm = document.getElementById('disable-osm');
|
|
|
|
let alwaysProxy = document.getElementById('always-proxy');
|
|
|
|
let onlyEmbeddedVideo = document.getElementById('only-embed');
|
|
|
|
let videoQuality = document.getElementById('video-quality');
|
|
|
|
let removeTwitterSW = document.getElementById('remove-twitter-sw');
|
2020-04-25 16:43:43 +02:00
|
|
|
let whitelist;
|
2019-10-07 13:59:31 +02:00
|
|
|
|
2020-02-24 04:19:56 +01:00
|
|
|
window.browser = window.browser || window.chrome;
|
|
|
|
|
2020-04-25 16:43:43 +02:00
|
|
|
function prependWhitelistItem(item, index) {
|
|
|
|
const li = document.createElement('li');
|
|
|
|
li.appendChild(document.createTextNode(item.toString()));
|
|
|
|
const button = document.createElement('button');
|
|
|
|
button.appendChild(document.createTextNode('X'));
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
li.remove();
|
|
|
|
whitelist.splice(index, 1);
|
|
|
|
browser.storage.sync.set({
|
|
|
|
whitelist: whitelist
|
|
|
|
});
|
|
|
|
});
|
|
|
|
li.appendChild(button);
|
|
|
|
document.getElementById('whitelist-items').prepend(li);
|
|
|
|
}
|
|
|
|
|
2020-02-24 04:19:56 +01:00
|
|
|
browser.storage.sync.get(
|
2020-02-01 04:17:51 +01:00
|
|
|
[
|
|
|
|
'nitterInstance',
|
|
|
|
'invidiousInstance',
|
|
|
|
'bibliogramInstance',
|
2020-02-27 02:18:50 +01:00
|
|
|
'osmInstance',
|
2020-02-01 04:17:51 +01:00
|
|
|
'disableNitter',
|
|
|
|
'disableInvidious',
|
2020-02-11 23:35:58 +01:00
|
|
|
'disableBibliogram',
|
2020-03-10 06:03:28 +01:00
|
|
|
'disableOsm',
|
2020-03-21 10:34:32 +01:00
|
|
|
'alwaysProxy',
|
|
|
|
'onlyEmbeddedVideo',
|
2020-03-29 01:34:46 +01:00
|
|
|
'videoQuality',
|
2020-04-25 16:43:43 +02:00
|
|
|
'removeTwitterSW',
|
|
|
|
'whitelist'
|
2020-02-01 04:17:51 +01:00
|
|
|
],
|
2020-01-14 10:48:37 +01:00
|
|
|
result => {
|
2019-10-07 13:59:31 +02:00
|
|
|
nitterInstance.value = result.nitterInstance || '';
|
|
|
|
invidiousInstance.value = result.invidiousInstance || '';
|
2020-02-01 04:17:51 +01:00
|
|
|
bibliogramInstance.value = result.bibliogramInstance || '';
|
2020-02-27 02:18:50 +01:00
|
|
|
osmInstance.value = result.osmInstance || '';
|
2020-02-01 04:17:51 +01:00
|
|
|
disableNitter.checked = !result.disableNitter;
|
|
|
|
disableInvidious.checked = !result.disableInvidious;
|
|
|
|
disableBibliogram.checked = !result.disableBibliogram;
|
2020-02-27 02:18:50 +01:00
|
|
|
disableOsm.checked = !result.disableOsm;
|
2020-03-10 06:03:28 +01:00
|
|
|
alwaysProxy.checked = result.alwaysProxy;
|
2020-03-21 10:34:32 +01:00
|
|
|
onlyEmbeddedVideo.checked = result.onlyEmbeddedVideo;
|
|
|
|
videoQuality.value = result.videoQuality || '';
|
2020-03-29 01:34:46 +01:00
|
|
|
removeTwitterSW.checked = !result.removeTwitterSW;
|
2020-04-25 16:43:43 +02:00
|
|
|
whitelist = result.whitelist || [];
|
|
|
|
whitelist.forEach(prependWhitelistItem);
|
2019-10-07 13:59:31 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-04-25 10:31:27 +02:00
|
|
|
function openTab(tab, event) {
|
|
|
|
let i, tabcontent, tablinks;
|
|
|
|
tabcontent = document.getElementsByClassName('tabcontent');
|
|
|
|
for (i = 0; i < tabcontent.length; i++) {
|
|
|
|
tabcontent[i].style.display = 'none';
|
|
|
|
}
|
|
|
|
tablinks = document.getElementsByClassName('tablinks');
|
|
|
|
for (i = 0; i < tablinks.length; i++) {
|
|
|
|
tablinks[i].className = tablinks[i].className.replace(' active', '');
|
|
|
|
}
|
|
|
|
document.getElementById(tab).style.display = 'block';
|
|
|
|
event.currentTarget.className += ' active';
|
|
|
|
}
|
|
|
|
|
2020-04-25 16:43:43 +02:00
|
|
|
document.getElementById('general-tab').addEventListener(
|
2020-04-25 10:31:27 +02:00
|
|
|
'click', openTab.bind(null, 'general')
|
|
|
|
);
|
2020-04-25 16:43:43 +02:00
|
|
|
document.getElementById('advanced-tab').addEventListener(
|
2020-04-25 10:31:27 +02:00
|
|
|
'click', openTab.bind(null, 'advanced')
|
|
|
|
);
|
2020-04-25 16:43:43 +02:00
|
|
|
document.getElementById('whitelist-tab').addEventListener(
|
2020-04-25 10:31:27 +02:00
|
|
|
'click', openTab.bind(null, 'whitelist')
|
|
|
|
);
|
|
|
|
|
2020-04-25 16:43:43 +02:00
|
|
|
document.getElementById('general-tab').click();
|
|
|
|
|
|
|
|
function addToWhitelist() {
|
|
|
|
const input = document.getElementById('new-whitelist-item');
|
|
|
|
if (input.value) {
|
|
|
|
try {
|
|
|
|
new RegExp(input.value);
|
|
|
|
const index = whitelist.push(input.value);
|
|
|
|
prependWhitelistItem(input.value, index);
|
|
|
|
browser.storage.sync.set({
|
|
|
|
whitelist: whitelist
|
|
|
|
});
|
|
|
|
input.value = '';
|
|
|
|
} catch (error) {
|
|
|
|
input.setCustomValidity('Invalid RegExp');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
input.setCustomValidity('Invalid RegExp');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('add-to-whitelist').addEventListener(
|
|
|
|
'click', addToWhitelist
|
|
|
|
);
|
2020-04-25 10:31:27 +02:00
|
|
|
|
2020-03-21 10:34:32 +01:00
|
|
|
function debounce(func, wait, immediate) {
|
|
|
|
let timeout;
|
|
|
|
return () => {
|
|
|
|
let context = this, args = arguments;
|
|
|
|
let later = () => {
|
|
|
|
timeout = null;
|
|
|
|
if (!immediate) func.apply(context, args);
|
|
|
|
};
|
|
|
|
let callNow = immediate && !timeout;
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = setTimeout(later, wait);
|
|
|
|
if (callNow) func.apply(context, args);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
let nitterInstanceChange = debounce(() => {
|
|
|
|
if (nitterInstance.checkValidity()) {
|
|
|
|
browser.storage.sync.set({
|
|
|
|
nitterInstance: nitterInstance.value ? new URL(nitterInstance.value).origin : ''
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
nitterInstance.addEventListener('input', nitterInstanceChange);
|
|
|
|
|
|
|
|
let invidiousInstanceChange = debounce(() => {
|
|
|
|
if (invidiousInstance.checkValidity()) {
|
|
|
|
browser.storage.sync.set({
|
|
|
|
invidiousInstance: invidiousInstance.value ? new URL(invidiousInstance.value).origin : ''
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
invidiousInstance.addEventListener('input', invidiousInstanceChange);
|
|
|
|
|
|
|
|
let bibliogramInstanceChange = debounce(() => {
|
|
|
|
if (bibliogramInstance.checkValidity()) {
|
|
|
|
browser.storage.sync.set({
|
|
|
|
bibliogramInstance: bibliogramInstance.value ? new URL(bibliogramInstance.value).origin : ''
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
bibliogramInstance.addEventListener('input', bibliogramInstanceChange);
|
|
|
|
|
|
|
|
let osmInstanceChange = debounce(() => {
|
|
|
|
if (osmInstance.checkValidity()) {
|
|
|
|
browser.storage.sync.set({
|
|
|
|
osmInstance: osmInstance.value ? new URL(osmInstance.value).origin : ''
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
osmInstance.addEventListener('input', osmInstanceChange);
|
|
|
|
|
|
|
|
disableNitter.addEventListener('change', event => {
|
|
|
|
browser.storage.sync.set({ disableNitter: !event.target.checked });
|
|
|
|
});
|
|
|
|
|
|
|
|
disableInvidious.addEventListener('change', event => {
|
|
|
|
browser.storage.sync.set({ disableInvidious: !event.target.checked });
|
|
|
|
});
|
|
|
|
|
|
|
|
disableBibliogram.addEventListener('change', event => {
|
|
|
|
browser.storage.sync.set({ disableBibliogram: !event.target.checked });
|
|
|
|
});
|
|
|
|
|
|
|
|
disableOsm.addEventListener('change', event => {
|
|
|
|
browser.storage.sync.set({ disableOsm: !event.target.checked });
|
|
|
|
});
|
|
|
|
|
|
|
|
alwaysProxy.addEventListener('change', event => {
|
|
|
|
browser.storage.sync.set({ alwaysProxy: event.target.checked });
|
|
|
|
});
|
|
|
|
|
|
|
|
onlyEmbeddedVideo.addEventListener('change', event => {
|
|
|
|
browser.storage.sync.set({ onlyEmbeddedVideo: event.target.checked });
|
|
|
|
});
|
|
|
|
|
|
|
|
videoQuality.addEventListener('change', event => {
|
2020-02-24 04:19:56 +01:00
|
|
|
browser.storage.sync.set({
|
2020-03-21 10:34:32 +01:00
|
|
|
videoQuality: event.target.options[videoQuality.selectedIndex].value
|
2019-10-07 13:59:31 +02:00
|
|
|
});
|
2020-03-21 10:34:32 +01:00
|
|
|
});
|
2020-03-29 01:34:46 +01:00
|
|
|
|
|
|
|
removeTwitterSW.addEventListener('change', event => {
|
|
|
|
browser.storage.sync.set({ removeTwitterSW: !event.target.checked });
|
|
|
|
});
|