alamin655
commited on
Commit
•
6bc06a3
1
Parent(s):
09d9573
Add comments and docstrings to the code
Browse files- public/static/cookies.js +15 -4
public/static/cookies.js
CHANGED
@@ -1,15 +1,26 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
}
|
|
|
1 |
+
/**
|
2 |
+
* This function is executed when any page on the website finishes loading and
|
3 |
+
* this function retrieves the cookies if it is present on the user's machine.
|
4 |
+
* If it is available then the saved cookies is display in the cookies tab
|
5 |
+
* otherwise an appropriate message is displayed if it is not available.
|
6 |
+
*
|
7 |
+
* @function
|
8 |
+
* @listens DOMContentLoaded
|
9 |
+
* @returns {void}
|
10 |
+
*/
|
11 |
document.addEventListener(
|
12 |
'DOMContentLoaded',
|
13 |
() => {
|
14 |
try {
|
15 |
+
// Decode the cookie value
|
16 |
let cookie = decodeURIComponent(document.cookie)
|
17 |
+
// Set the value of the input field to the decoded cookie value if it is not empty
|
18 |
+
// Otherwise, display a message indicating that no cookies have been saved on the user's system
|
19 |
document.querySelector('.cookies input').value =
|
20 |
cookie !== '' ? cookie : 'No cookies have been saved on your system'
|
21 |
} catch (error) {
|
22 |
+
// If there is an error decoding the cookie, log the error to the console
|
23 |
+
// and display an error message in the input field
|
24 |
console.error('Error decoding cookie:', error)
|
25 |
document.querySelector('.cookies input').value = 'Error decoding cookie'
|
26 |
}
|