Spaces:
Runtime error
Runtime error
Merge pull request #139 from alamin655/JSDocs
Browse files:broom: chore: Enhance JS Code Documentation with Comprehensive Comments and Docstrings
- Cargo.lock +15 -15
- Cargo.toml +1 -1
- public/static/cookies.js +15 -4
- public/static/pagination.js +2 -2
- public/static/settings.js +36 -10
Cargo.lock
CHANGED
@@ -2386,9 +2386,9 @@ dependencies = [
|
|
2386 |
|
2387 |
[[package]]
|
2388 |
name = "regex"
|
2389 |
-
version = "1.9.
|
2390 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2391 |
-
checksum = "
|
2392 |
dependencies = [
|
2393 |
"aho-corasick",
|
2394 |
"memchr",
|
@@ -2398,9 +2398,9 @@ dependencies = [
|
|
2398 |
|
2399 |
[[package]]
|
2400 |
name = "regex-automata"
|
2401 |
-
version = "0.3.
|
2402 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2403 |
-
checksum = "
|
2404 |
dependencies = [
|
2405 |
"aho-corasick",
|
2406 |
"memchr",
|
@@ -2693,18 +2693,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
|
2693 |
|
2694 |
[[package]]
|
2695 |
name = "serde"
|
2696 |
-
version = "1.0.
|
2697 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2698 |
-
checksum = "
|
2699 |
dependencies = [
|
2700 |
"serde_derive",
|
2701 |
]
|
2702 |
|
2703 |
[[package]]
|
2704 |
name = "serde_derive"
|
2705 |
-
version = "1.0.
|
2706 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2707 |
-
checksum = "
|
2708 |
dependencies = [
|
2709 |
"proc-macro2 1.0.63",
|
2710 |
"quote 1.0.29",
|
@@ -2994,18 +2994,18 @@ dependencies = [
|
|
2994 |
|
2995 |
[[package]]
|
2996 |
name = "thiserror"
|
2997 |
-
version = "1.0.
|
2998 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2999 |
-
checksum = "
|
3000 |
dependencies = [
|
3001 |
"thiserror-impl",
|
3002 |
]
|
3003 |
|
3004 |
[[package]]
|
3005 |
name = "thiserror-impl"
|
3006 |
-
version = "1.0.
|
3007 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
3008 |
-
checksum = "
|
3009 |
dependencies = [
|
3010 |
"proc-macro2 1.0.63",
|
3011 |
"quote 1.0.29",
|
@@ -3322,9 +3322,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
|
3322 |
|
3323 |
[[package]]
|
3324 |
name = "ucd-trie"
|
3325 |
-
version = "0.1.
|
3326 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
3327 |
-
checksum = "
|
3328 |
|
3329 |
[[package]]
|
3330 |
name = "unicase"
|
@@ -3543,7 +3543,7 @@ dependencies = [
|
|
3543 |
|
3544 |
[[package]]
|
3545 |
name = "websurfx"
|
3546 |
-
version = "0.13.
|
3547 |
dependencies = [
|
3548 |
"actix-files",
|
3549 |
"actix-web",
|
|
|
2386 |
|
2387 |
[[package]]
|
2388 |
name = "regex"
|
2389 |
+
version = "1.9.1"
|
2390 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2391 |
+
checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575"
|
2392 |
dependencies = [
|
2393 |
"aho-corasick",
|
2394 |
"memchr",
|
|
|
2398 |
|
2399 |
[[package]]
|
2400 |
name = "regex-automata"
|
2401 |
+
version = "0.3.2"
|
2402 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2403 |
+
checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf"
|
2404 |
dependencies = [
|
2405 |
"aho-corasick",
|
2406 |
"memchr",
|
|
|
2693 |
|
2694 |
[[package]]
|
2695 |
name = "serde"
|
2696 |
+
version = "1.0.168"
|
2697 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2698 |
+
checksum = "d614f89548720367ded108b3c843be93f3a341e22d5674ca0dd5cd57f34926af"
|
2699 |
dependencies = [
|
2700 |
"serde_derive",
|
2701 |
]
|
2702 |
|
2703 |
[[package]]
|
2704 |
name = "serde_derive"
|
2705 |
+
version = "1.0.168"
|
2706 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2707 |
+
checksum = "d4fe589678c688e44177da4f27152ee2d190757271dc7f1d5b6b9f68d869d641"
|
2708 |
dependencies = [
|
2709 |
"proc-macro2 1.0.63",
|
2710 |
"quote 1.0.29",
|
|
|
2994 |
|
2995 |
[[package]]
|
2996 |
name = "thiserror"
|
2997 |
+
version = "1.0.43"
|
2998 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2999 |
+
checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42"
|
3000 |
dependencies = [
|
3001 |
"thiserror-impl",
|
3002 |
]
|
3003 |
|
3004 |
[[package]]
|
3005 |
name = "thiserror-impl"
|
3006 |
+
version = "1.0.43"
|
3007 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
3008 |
+
checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f"
|
3009 |
dependencies = [
|
3010 |
"proc-macro2 1.0.63",
|
3011 |
"quote 1.0.29",
|
|
|
3322 |
|
3323 |
[[package]]
|
3324 |
name = "ucd-trie"
|
3325 |
+
version = "0.1.6"
|
3326 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
3327 |
+
checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
|
3328 |
|
3329 |
[[package]]
|
3330 |
name = "unicase"
|
|
|
3543 |
|
3544 |
[[package]]
|
3545 |
name = "websurfx"
|
3546 |
+
version = "0.13.16"
|
3547 |
dependencies = [
|
3548 |
"actix-files",
|
3549 |
"actix-web",
|
Cargo.toml
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
[package]
|
2 |
name = "websurfx"
|
3 |
-
version = "0.13.
|
4 |
edition = "2021"
|
5 |
description = "An open-source alternative to Searx that provides clean, ad-free, and organic results with incredible speed while keeping privacy and security in mind."
|
6 |
repository = "https://github.com/neon-mmd/websurfx"
|
|
|
1 |
[package]
|
2 |
name = "websurfx"
|
3 |
+
version = "0.13.16"
|
4 |
edition = "2021"
|
5 |
description = "An open-source alternative to Searx that provides clean, ad-free, and organic results with incredible speed while keeping privacy and security in mind."
|
6 |
repository = "https://github.com/neon-mmd/websurfx"
|
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 |
}
|
public/static/pagination.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
/**
|
2 |
-
* Navigates to the next page by incrementing the current page number in the URL query
|
3 |
* @returns {void}
|
4 |
*/
|
5 |
function navigate_forward() {
|
@@ -19,7 +19,7 @@ function navigate_forward() {
|
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
-
* Navigates to the previous page by decrementing the current page number in the URL query
|
23 |
* @returns {void}
|
24 |
*/
|
25 |
function navigate_backward() {
|
|
|
1 |
/**
|
2 |
+
* Navigates to the next page by incrementing the current page number in the URL query string.
|
3 |
* @returns {void}
|
4 |
*/
|
5 |
function navigate_forward() {
|
|
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
+
* Navigates to the previous page by decrementing the current page number in the URL query string.
|
23 |
* @returns {void}
|
24 |
*/
|
25 |
function navigate_backward() {
|
public/static/settings.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
3 |
function toggleAllSelection() {
|
4 |
document
|
5 |
.querySelectorAll('.engine')
|
@@ -10,25 +12,36 @@ function toggleAllSelection() {
|
|
10 |
)
|
11 |
}
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
function setActiveTab(current_tab) {
|
|
|
16 |
document
|
17 |
.querySelectorAll('.tab')
|
18 |
.forEach((tab) => tab.classList.remove('active'))
|
19 |
document
|
20 |
.querySelectorAll('.btn')
|
21 |
.forEach((tab) => tab.classList.remove('active'))
|
|
|
|
|
22 |
current_tab.classList.add('active')
|
23 |
document
|
24 |
.querySelector(`.${current_tab.innerText.toLowerCase().replace(' ', '_')}`)
|
25 |
.classList.add('active')
|
26 |
}
|
27 |
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
function setClientSettings() {
|
|
|
31 |
let cookie_dictionary = new Object()
|
|
|
|
|
32 |
document.querySelectorAll('select').forEach((select_tag) => {
|
33 |
if (select_tag.name === 'themes') {
|
34 |
cookie_dictionary['theme'] = select_tag.value
|
@@ -36,6 +49,8 @@ function setClientSettings() {
|
|
36 |
cookie_dictionary['colorscheme'] = select_tag.value
|
37 |
}
|
38 |
})
|
|
|
|
|
39 |
let engines = []
|
40 |
document.querySelectorAll('.engine').forEach((engine_checkbox) => {
|
41 |
if (engine_checkbox.checked === true) {
|
@@ -43,33 +58,44 @@ function setClientSettings() {
|
|
43 |
}
|
44 |
})
|
45 |
cookie_dictionary['engines'] = engines
|
|
|
|
|
46 |
let expiration_date = new Date()
|
47 |
expiration_date.setFullYear(expiration_date.getFullYear() + 1)
|
|
|
|
|
48 |
document.cookie = `appCookie=${JSON.stringify(
|
49 |
cookie_dictionary
|
50 |
)}; expires=${expiration_date.toUTCString()}`
|
51 |
|
|
|
52 |
document.querySelector('.message').innerText =
|
53 |
'β
The settings have been saved sucessfully!!'
|
54 |
|
|
|
55 |
setTimeout(() => {
|
56 |
document.querySelector('.message').innerText = ''
|
57 |
}, 10000)
|
58 |
}
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
64 |
function getClientSettings() {
|
|
|
65 |
let cookie = decodeURIComponent(document.cookie)
|
66 |
|
|
|
67 |
if (cookie !== '') {
|
68 |
let cookie_value = decodeURIComponent(document.cookie)
|
69 |
.split(';')
|
70 |
.map((item) => item.split('='))
|
71 |
.reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {})
|
72 |
|
|
|
73 |
let links = Array.from(document.querySelectorAll('link')).forEach(
|
74 |
(item) => {
|
75 |
if (item.href.includes('static/themes')) {
|
|
|
1 |
+
/**
|
2 |
+
* This function handles the toggling of selections of all upstream search engines
|
3 |
+
* options in the settings page under the tab engines.
|
4 |
+
*/
|
5 |
function toggleAllSelection() {
|
6 |
document
|
7 |
.querySelectorAll('.engine')
|
|
|
12 |
)
|
13 |
}
|
14 |
|
15 |
+
/**
|
16 |
+
* This function adds the functionality to sidebar buttons to only show settings
|
17 |
+
* related to that tab.
|
18 |
+
* @param {HTMLElement} current_tab - The current tab that was clicked.
|
19 |
+
*/
|
20 |
function setActiveTab(current_tab) {
|
21 |
+
// Remove the active class from all tabs and buttons
|
22 |
document
|
23 |
.querySelectorAll('.tab')
|
24 |
.forEach((tab) => tab.classList.remove('active'))
|
25 |
document
|
26 |
.querySelectorAll('.btn')
|
27 |
.forEach((tab) => tab.classList.remove('active'))
|
28 |
+
|
29 |
+
// Add the active class to the current tab and its corresponding settings
|
30 |
current_tab.classList.add('active')
|
31 |
document
|
32 |
.querySelector(`.${current_tab.innerText.toLowerCase().replace(' ', '_')}`)
|
33 |
.classList.add('active')
|
34 |
}
|
35 |
|
36 |
+
/**
|
37 |
+
* This function adds the functionality to save all the user selected preferences
|
38 |
+
* to be saved in a cookie on the users machine.
|
39 |
+
*/
|
40 |
function setClientSettings() {
|
41 |
+
// Create an object to store the user's preferences
|
42 |
let cookie_dictionary = new Object()
|
43 |
+
|
44 |
+
// Loop through all select tags and add their values to the cookie dictionary
|
45 |
document.querySelectorAll('select').forEach((select_tag) => {
|
46 |
if (select_tag.name === 'themes') {
|
47 |
cookie_dictionary['theme'] = select_tag.value
|
|
|
49 |
cookie_dictionary['colorscheme'] = select_tag.value
|
50 |
}
|
51 |
})
|
52 |
+
|
53 |
+
// Loop through all engine checkboxes and add their values to the cookie dictionary
|
54 |
let engines = []
|
55 |
document.querySelectorAll('.engine').forEach((engine_checkbox) => {
|
56 |
if (engine_checkbox.checked === true) {
|
|
|
58 |
}
|
59 |
})
|
60 |
cookie_dictionary['engines'] = engines
|
61 |
+
|
62 |
+
// Set the expiration date for the cookie to 1 year from the current date
|
63 |
let expiration_date = new Date()
|
64 |
expiration_date.setFullYear(expiration_date.getFullYear() + 1)
|
65 |
+
|
66 |
+
// Save the cookie to the user's machine
|
67 |
document.cookie = `appCookie=${JSON.stringify(
|
68 |
cookie_dictionary
|
69 |
)}; expires=${expiration_date.toUTCString()}`
|
70 |
|
71 |
+
// Display a success message to the user
|
72 |
document.querySelector('.message').innerText =
|
73 |
'β
The settings have been saved sucessfully!!'
|
74 |
|
75 |
+
// Clear the success message after 10 seconds
|
76 |
setTimeout(() => {
|
77 |
document.querySelector('.message').innerText = ''
|
78 |
}, 10000)
|
79 |
}
|
80 |
|
81 |
+
/**
|
82 |
+
* This functions gets the saved cookies if it is present on the user's machine If it
|
83 |
+
* is available then it is parsed and converted to an object which is then used to
|
84 |
+
* retrieve the preferences that the user had selected previously and is then loaded in the
|
85 |
+
* website otherwise the function does nothing and the default server side settings are loaded.
|
86 |
+
*/
|
87 |
function getClientSettings() {
|
88 |
+
// Get the appCookie from the user's machine
|
89 |
let cookie = decodeURIComponent(document.cookie)
|
90 |
|
91 |
+
// If the cookie is not empty, parse it and use it to set the user's preferences
|
92 |
if (cookie !== '') {
|
93 |
let cookie_value = decodeURIComponent(document.cookie)
|
94 |
.split(';')
|
95 |
.map((item) => item.split('='))
|
96 |
.reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {})
|
97 |
|
98 |
+
// Loop through all link tags and update their href values to match the user's preferences
|
99 |
let links = Array.from(document.querySelectorAll('link')).forEach(
|
100 |
(item) => {
|
101 |
if (item.href.includes('static/themes')) {
|