Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
•
3be0c65
1
Parent(s):
2b7e28c
✨ feat: use ternary condition statement and add error-handling
Browse files- public/static/cookies.js +8 -7
public/static/cookies.js
CHANGED
@@ -1,16 +1,17 @@
|
|
1 |
// This function is executed when any page on the website finsihes loading and
|
2 |
-
// this function retrieves the cookies if it is present on the user's machine.
|
3 |
-
// If it is available then the saved cookies is display in the cookies tab
|
4 |
// otherwise an appropriate message is displayed if it is not available.
|
5 |
document.addEventListener(
|
6 |
'DOMContentLoaded',
|
7 |
() => {
|
8 |
-
|
9 |
-
|
10 |
-
document.querySelector('.cookies input').value = cookie
|
11 |
-
} else {
|
12 |
document.querySelector('.cookies input').value =
|
13 |
-
'No cookies
|
|
|
|
|
|
|
14 |
}
|
15 |
},
|
16 |
false
|
|
|
1 |
// This function is executed when any page on the website finsihes loading and
|
2 |
+
// this function retrieves the cookies if it is present on the user's machine.
|
3 |
+
// If it is available then the saved cookies is display in the cookies tab
|
4 |
// otherwise an appropriate message is displayed if it is not available.
|
5 |
document.addEventListener(
|
6 |
'DOMContentLoaded',
|
7 |
() => {
|
8 |
+
try {
|
9 |
+
let cookie = decodeURIComponent(document.cookie)
|
|
|
|
|
10 |
document.querySelector('.cookies input').value =
|
11 |
+
cookie !== '' ? cookie : 'No cookies have been saved on your system'
|
12 |
+
} catch (error) {
|
13 |
+
console.error('Error decoding cookie:', error)
|
14 |
+
document.querySelector('.cookies input').value = 'Error decoding cookie'
|
15 |
}
|
16 |
},
|
17 |
false
|