condividi-link-fediverso-fi.../js/options.js

132 lines
4.7 KiB
JavaScript

function saveOptions(e) {
browser.storage.sync.set({
gnusocialHost: document.querySelector("#gnusocialHost").value,
mastodonHost: document.querySelector("#mastodonHost").value,
pleromaHost: document.querySelector("#pleromaHost").value,
hubzillaHost: document.querySelector("#hubzillaHost").value,
diasporaHost: document.querySelector("#diasporaHost").value,
friendicaHost: document.querySelector("#friendicaHost").value,
lemmyHost: document.querySelector("#lemmyHost").value,
socialhomeHost: document.querySelector("#socialhomeHost").value,
xmppHost: document.querySelector("#xmppHost").value,
nextcloudHost: document.querySelector("#nextcloudHost").value,
nextcloudUsername: document.querySelector("#nextcloudUsername").value,
nextcloudPassword: document.querySelector("#nextcloudPassword").value,
shortcut: document.querySelector("#shortcut").value
});
e.preventDefault();
}
function restoreOptions() {
var gettingGnusocial = browser.storage.sync.get('gnusocialHost');
gettingGnusocial.then((res) => {
document.querySelector("#gnusocialHost").value = res.gnusocialHost || 'https://gnusocial.no';
});
var gettingMastodon = browser.storage.sync.get('mastodonHost');
gettingMastodon.then((res) => {
document.querySelector("#mastodonHost").value = res.mastodonHost || 'https://mastodon.social';
});
var gettingPleroma = browser.storage.sync.get('pleromaHost');
gettingPleroma.then((res) => {
document.querySelector("#pleromaHost").value = res.pleromaHost || 'https://pleroma-social.ml';
});
var gettingHubzilla = browser.storage.sync.get('hubzillaHost');
gettingHubzilla.then((res) => {
document.querySelector("#hubzillaHost").value = res.hubzillaHost || 'https://start.hubzilla.org';
});
var gettingDiaspora = browser.storage.sync.get('diasporaHost');
gettingDiaspora.then((res) => {
document.querySelector("#diasporaHost").value = res.diasporaHost || 'https://diasp.eu';
});
var gettingFriendica = browser.storage.sync.get('friendicaHost');
gettingFriendica.then((res) => {
document.querySelector("#friendicaHost").value = res.friendicaHost || 'https://libranet.de';
});
var gettingLemmy = browser.storage.sync.get('lemmyHost');
gettingLemmy.then((res) => {
document.querySelector("#lemmyHost").value = res.lemmyHost || 'https://dev.lemmy.ml';
});
var gettingSocialhome = browser.storage.sync.get('socialhomeHost');
gettingSocialhome.then((res) => {
document.querySelector("#socialhomeHost").value = res.socialhomeHost || 'https://socialhome.network';
});
var gettingXmpp = browser.storage.sync.get('xmppHost');
gettingXmpp.then((res) => {
document.querySelector("#xmppHost").value = res.xmppHost || 'https://suchat.org';
});
var gettingNextcloudHost = browser.storage.sync.get('nextcloudHost');
gettingNextcloudHost.then((res) => {
document.querySelector("#nextcloudHost").value = res.nextcloudHost || '';
});
var gettingNextcloudUsername = browser.storage.sync.get('nextcloudUsername');
gettingNextcloudUsername.then((res) => {
document.querySelector("#nextcloudUsername").value = res.nextcloudUsername || '';
});
var gettingNextcloudPassword = browser.storage.sync.get('nextcloudPassword');
gettingNextcloudPassword.then((res) => {
document.querySelector("#nextcloudPassword").value = res.nextcloudPassword || '';
});
var gettingShortcut = browser.storage.sync.get('shortcut');
gettingShortcut.then((res) => {
document.querySelector("#shortcut").value = res.shortcut || 'Ctrl+Shift+U';
});
}
/**
* Keyboard shortcut
*/
const commandShorcut = '_execute_browser_action';
/**
* Update the UI: set the value of the shortcut textbox.
*/
async function updateUI() {
let commands = await browser.commands.getAll();
for (command of commands) {
if (command.name === commandShorcut) {
document.querySelector('#shortcut').value = command.shortcut;
}
}
}
/**
* Update the shortcut based on the value in the textbox.
*/
async function updateShortcut() {
await browser.commands.update({
name: commandShorcut,
shortcut: document.querySelector('#shortcut').value
});
}
/**
* Reset the shortcut and update the textbox.
*/
async function resetShortcut() {
await browser.commands.reset(commandShorcut);
updateUI();
}
/**
* Update the UI when the page loads.
*/
document.addEventListener('DOMContentLoaded', restoreOptions, updateUI);
document.querySelector("form").addEventListener("submit", saveOptions);
document.querySelector('#update').addEventListener('click', updateShortcut);
document.querySelector('#reset').addEventListener('click', resetShortcut);