libredirect/pages/options/options.js

41 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-10-07 13:59:31 +02:00
'use strict';
let nitterInstance = document.querySelector('#nitter-instance');
let invidiousInstance = document.querySelector('#invidious-instance');
let bibliogramInstance = document.querySelector('#bibliogram-instance');
let disableNitter = document.querySelector('#disable-nitter');
let disableInvidious = document.querySelector('#disable-invidious');
let disableBibliogram = document.querySelector('#disable-bibliogram');
2019-10-07 13:59:31 +02:00
2020-02-24 04:19:56 +01:00
window.browser = window.browser || window.chrome;
browser.storage.sync.get(
2020-02-01 04:17:51 +01:00
[
'nitterInstance',
'invidiousInstance',
'bibliogramInstance',
'disableNitter',
'disableInvidious',
'disableBibliogram',
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 || '';
disableNitter.checked = !result.disableNitter;
disableInvidious.checked = !result.disableInvidious;
disableBibliogram.checked = !result.disableBibliogram;
2019-10-07 13:59:31 +02:00
}
);
document.querySelector('#save').addEventListener('click', () => {
2020-02-24 04:19:56 +01:00
browser.storage.sync.set({
nitterInstance: nitterInstance.value && nitterInstance.checkValidity() ? new URL(nitterInstance.value).origin : '',
invidiousInstance: invidiousInstance.value && invidiousInstance.checkValidity() ? new URL(invidiousInstance.value).origin : '',
bibliogramInstance: bibliogramInstance.value && bibliogramInstance.checkValidity() ? new URL(bibliogramInstance.value).origin : '',
2019-10-07 13:59:31 +02:00
disableNitter: !disableNitter.checked,
disableInvidious: !disableInvidious.checked,
2020-02-01 04:17:51 +01:00
disableBibliogram: !disableBibliogram.checked
2019-10-07 13:59:31 +02:00
});
window.close();
});