neon_arch commited on
Commit
c5db7cc
β€’
2 Parent(s): eb4ed31 f341bba

Merge pull request #139 from alamin655/JSDocs

Browse files

:broom: chore: Enhance JS Code Documentation with Comprehensive Comments and Docstrings

Cargo.lock CHANGED
@@ -2386,9 +2386,9 @@ dependencies = [
2386
 
2387
  [[package]]
2388
  name = "regex"
2389
- version = "1.9.0"
2390
  source = "registry+https://github.com/rust-lang/crates.io-index"
2391
- checksum = "89089e897c013b3deb627116ae56a6955a72b8bed395c9526af31c9fe528b484"
2392
  dependencies = [
2393
  "aho-corasick",
2394
  "memchr",
@@ -2398,9 +2398,9 @@ dependencies = [
2398
 
2399
  [[package]]
2400
  name = "regex-automata"
2401
- version = "0.3.0"
2402
  source = "registry+https://github.com/rust-lang/crates.io-index"
2403
- checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56"
2404
  dependencies = [
2405
  "aho-corasick",
2406
  "memchr",
@@ -2693,18 +2693,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
2693
 
2694
  [[package]]
2695
  name = "serde"
2696
- version = "1.0.166"
2697
  source = "registry+https://github.com/rust-lang/crates.io-index"
2698
- checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8"
2699
  dependencies = [
2700
  "serde_derive",
2701
  ]
2702
 
2703
  [[package]]
2704
  name = "serde_derive"
2705
- version = "1.0.166"
2706
  source = "registry+https://github.com/rust-lang/crates.io-index"
2707
- checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6"
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.41"
2998
  source = "registry+https://github.com/rust-lang/crates.io-index"
2999
- checksum = "c16a64ba9387ef3fdae4f9c1a7f07a0997fce91985c0336f1ddc1822b3b37802"
3000
  dependencies = [
3001
  "thiserror-impl",
3002
  ]
3003
 
3004
  [[package]]
3005
  name = "thiserror-impl"
3006
- version = "1.0.41"
3007
  source = "registry+https://github.com/rust-lang/crates.io-index"
3008
- checksum = "d14928354b01c4d6a4f0e549069adef399a284e7995c7ccca94e8a07a5346c59"
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.5"
3326
  source = "registry+https://github.com/rust-lang/crates.io-index"
3327
- checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
3328
 
3329
  [[package]]
3330
  name = "unicase"
@@ -3543,7 +3543,7 @@ dependencies = [
3543
 
3544
  [[package]]
3545
  name = "websurfx"
3546
- version = "0.13.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.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
- // This function is executed when any page on the website finishes 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
  }
 
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 parameters.
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 parameters.
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
- // This function handles the toggling of selections of all upstream search engines
2
- // options in the settings page under the tab engines.
 
 
3
  function toggleAllSelection() {
4
  document
5
  .querySelectorAll('.engine')
@@ -10,25 +12,36 @@ function toggleAllSelection() {
10
  )
11
  }
12
 
13
- // This function adds the functionality to sidebar buttons to only show settings
14
- // related to that tab.
 
 
 
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
- // This function adds the functionality to save all the user selected preferences
29
- // to be saved in a cookie on the users machine.
 
 
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
- // This functions gets the saved cookies if it is present on the user's machine If it
61
- // is available then it is parsed and converted to an object which is then used to
62
- // retrieve the preferences that the user had selected previously and is then loaded in the
63
- // website otherwise the function does nothing and the default server side settings are loaded.
 
 
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')) {