0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-24 15:08:22 -05:00

feat: use ternary condition statement and add error-handling

This commit is contained in:
neon_arch 2023-06-19 19:38:45 +03:00
parent 2b7e28c963
commit 3be0c65109

View File

@ -1,16 +1,17 @@
// This function is executed when any page on the website finsihes loading and // This function is executed when any page on the website finsihes loading and
// this function retrieves the cookies if it is present on the user's machine. // this function retrieves the cookies if it is present on the user's machine.
// If it is available then the saved cookies is display in the cookies tab // If it is available then the saved cookies is display in the cookies tab
// otherwise an appropriate message is displayed if it is not available. // otherwise an appropriate message is displayed if it is not available.
document.addEventListener( document.addEventListener(
'DOMContentLoaded', 'DOMContentLoaded',
() => { () => {
let cookie = decodeURIComponent(document.cookie) try {
if (cookie !== '') { let cookie = decodeURIComponent(document.cookie)
document.querySelector('.cookies input').value = cookie
} else {
document.querySelector('.cookies input').value = document.querySelector('.cookies input').value =
'No cookies has been saved on your system' cookie !== '' ? cookie : 'No cookies have been saved on your system'
} catch (error) {
console.error('Error decoding cookie:', error)
document.querySelector('.cookies input').value = 'Error decoding cookie'
} }
}, },
false false