GrassClipper/resources/js/options.js

115 lines
2.9 KiB
JavaScript
Raw Normal View History

/**
* Toggle the killswitch script
*/
async function toggleKillSwitch() {
const killSwitch = document.querySelector('#killswitchOption')
const config = await getCfg()
config.enableKillswitch = killSwitch.checked
Neutralino.storage.setData('config', JSON.stringify(config))
}
/**
* Toggles the server launching panel
*/
async function toggleServerLaunchSection() {
const config = await getCfg()
displayServerLaunchSection()
// Save setting
config.serverLaunchPanel = !config.serverLaunchPanel
Neutralino.storage.setData('config', JSON.stringify(config))
}
/**
* Get all languages for the language selector
*/
async function getLanguages() {
const languageFiles = (await filesystem.readDirectory(`${NL_CWD}/languages`)).filter(file => file.entry.endsWith('.json'))
const config = await getCfg()
// Clear language options
const languageSelect = document.querySelector('#languageSelect')
languageSelect.innerHTML = ''
// Load all languages as options
for (const file of languageFiles) {
const fullLanguageName = JSON.parse(await filesystem.readFile(`${NL_CWD}/languages/${file.entry}`)).fullLangName
const lang = file.entry.split('.json')[0]
const option = document.createElement('option')
option.value = lang
option.innerHTML = fullLanguageName
// Set language selected to config language
if (lang === config.language) {
option.selected = true
}
document.querySelector('#languageSelect').appendChild(option)
}
}
/**
* Save lang, refresh to apply
*
* @param {DOMElement} elm
*/
async function handleLanguageChange(elm) {
const list = elm
const config = await getCfg()
// Set language in config
config.language = list.value
Neutralino.storage.setData('config', JSON.stringify(config))
// Force refresh of application, no need for restart!
window.location.reload()
}
2022-04-24 23:17:23 +00:00
/**
* Toggle the use of HTTPS
*/
2022-04-24 23:22:23 +00:00
async function toggleHttps() {
2022-04-24 23:17:23 +00:00
const httpsCheckbox = document.querySelector('#httpsOption')
const config = await getCfg()
config.useHttps = httpsCheckbox.checked
Neutralino.storage.setData('config', JSON.stringify(config))
}
/**
* Add the current value of the IP input to the favorites list
* OR
* Remove the current value of the IP input from the favorites list
*/
async function setFavorite() {
const ip = document.querySelector('#ip').value
2022-05-01 23:52:48 +00:00
const port = document.querySelector('#port').value || '443'
const ipArr = await getFavIps()
2022-04-24 23:06:25 +00:00
const addr = `${ip}:${port}`
// Set star icon
const star = document.querySelector('#star')
if (star.src.includes('filled') && ip) {
star.src = 'icons/star_empty.svg'
// remove from list
2022-04-24 23:06:25 +00:00
ipArr.splice(ipArr.indexOf(addr), 1)
} else {
star.src = 'icons/star_filled.svg'
// add to list
2022-04-24 23:06:25 +00:00
if (ip && !ipArr.includes(addr)) {
ipArr.push(addr)
}
}
Neutralino.storage.setData('favorites', JSON.stringify(ipArr))
}