GrassClipper/resources/js/onLoad.js

90 lines
2.5 KiB
JavaScript
Raw Normal View History

/**
* Every autofill, such as backgrounds and the game folder,
* should be done here to ensure DOM contents are loaded.
*/
2022-05-03 05:44:57 +00:00
document.addEventListener('DOMContentLoaded', async () => {
2022-05-03 05:48:03 +00:00
displayUpdate()
setBackgroundImage()
displayGameFolder()
displayServerFolder()
2022-05-03 05:48:03 +00:00
// Set title version
document.querySelector('#version').innerHTML = NL_APPVERSION
2022-05-03 05:48:03 +00:00
const config = await getCfg()
const ipArr = await getFavIps()
2022-05-03 05:48:03 +00:00
if (config.serverLaunchPanel) {
displayServerLaunchSection()
}
2022-05-03 05:48:03 +00:00
// Set last connect
document.querySelector('#ip').value = config.lastConnect
2022-05-03 05:48:03 +00:00
if (ipArr.includes(config.lastConnect)) {
document.querySelector('#star').src = 'icons/star_filled.svg'
}
2022-05-03 05:48:03 +00:00
// Disable private game launch if proxy IP or proxy server is not found
const playPriv = document.querySelector('#playPrivate')
if (!(await proxyIsInstalled())) {
playPriv.classList.add('disabled')
playPriv.disabled = true
}
// Exit favorites list and settings panel when clicking outside of it
window.addEventListener('click', function(e) {
const favList = document.querySelector('#ipList')
const settingsPanel = document.querySelector('#settingsPanel')
const downloadPanel = document.querySelector('#downloadPanel')
// This will close the favorites list no matter what is clicked
if (favList.style.display !== 'none') {
favList.style.display = 'none'
favList.style.transform = ''
}
2022-05-03 05:48:03 +00:00
// This will close the settings panel no matter what is clicked
let checkElm = e.target
2022-05-03 05:48:03 +00:00
while(checkElm.tagName !== 'BODY') {
if (checkElm.id === 'settingsPanel'
2022-05-02 06:15:04 +00:00
|| checkElm.id === 'settingsBtn') {
2022-05-03 05:48:03 +00:00
return
}
2022-05-03 05:48:03 +00:00
if (checkElm.id === 'downloadPanel' ||
2022-05-02 06:15:04 +00:00
checkElm.id === 'downloadBtn') {
2022-05-03 05:48:03 +00:00
return
}
checkElm = checkElm.parentElement
}
2022-05-03 05:48:03 +00:00
// We travelled through the parents, so if we are at the body, we clicked outside of the settings panel
if (checkElm.tagName === 'BODY') {
// This will close the settings panel only when something outside of it is clicked
if (settingsPanel.style.display !== 'none') {
settingsPanel.style.display = 'none'
}
if (downloadPanel.style.display !== 'none') {
downloadPanel.style.display = 'none'
}
}
2022-05-03 05:48:03 +00:00
})
// Ensure we do the translation at the very end, after everything else has loaded
await doTranslation()
if (!config.gameexe) {
handleGameNotSet()
}
if (!config.serverFolder) {
handleServerNotSet()
}
})