2019-10-07 13:59:31 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
let disableNitter = document.querySelector('#disableNitter');
|
|
|
|
let disableInvidious = document.querySelector('#disableInvidious');
|
2019-10-30 06:48:38 +01:00
|
|
|
let nitterInstance = document.querySelector('#nitterInstance');
|
|
|
|
let invidiousInstance = document.querySelector('#invidiousInstance');
|
2019-10-07 13:59:31 +02:00
|
|
|
|
|
|
|
chrome.storage.sync.get(
|
2019-10-30 06:48:38 +01:00
|
|
|
['disableNitter', 'disableInvidious', 'nitterInstance', 'invidiousInstance'],
|
|
|
|
result => {
|
2019-10-07 13:59:31 +02:00
|
|
|
disableNitter.checked = !result.disableNitter;
|
|
|
|
disableInvidious.checked = !result.disableInvidious;
|
2019-10-30 06:48:38 +01:00
|
|
|
nitterInstance.value = result.nitterInstance || '';
|
|
|
|
invidiousInstance.value = result.invidiousInstance || '';
|
2019-10-07 13:59:31 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-10-30 06:48:38 +01:00
|
|
|
function debounce(func, wait, immediate) {
|
|
|
|
let timeout;
|
|
|
|
return function () {
|
|
|
|
let context = this, args = arguments;
|
|
|
|
let later = function () {
|
|
|
|
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(() => {
|
|
|
|
chrome.storage.sync.set({ nitterInstance: nitterInstance.value });
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
nitterInstance.addEventListener('input', nitterInstanceChange);
|
|
|
|
|
|
|
|
let invidiousInstanceChange = debounce(() => {
|
|
|
|
chrome.storage.sync.set({ invidiousInstance: invidiousInstance.value });
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
invidiousInstance.addEventListener('input', invidiousInstanceChange);
|
|
|
|
|
|
|
|
disableNitter.addEventListener('change', event => {
|
2019-10-07 13:59:31 +02:00
|
|
|
chrome.storage.sync.set({ disableNitter: !event.target.checked });
|
|
|
|
});
|
|
|
|
|
2019-10-30 06:48:38 +01:00
|
|
|
disableInvidious.addEventListener('change', event => {
|
2019-10-07 13:59:31 +02:00
|
|
|
chrome.storage.sync.set({ disableInvidious: !event.target.checked });
|
|
|
|
});
|