2023-07-07 20:09:43 +05:30
|
|
|
/**
|
2023-09-22 19:39:50 +03:00
|
|
|
* This function handles the toggling of selections of all upstream search engines
|
2023-07-07 20:09:43 +05:30
|
|
|
* options in the settings page under the tab engines.
|
|
|
|
*/
|
2023-06-18 19:50:32 +03:00
|
|
|
function toggleAllSelection() {
|
|
|
|
document
|
|
|
|
.querySelectorAll('.engine')
|
|
|
|
.forEach(
|
|
|
|
(engine_checkbox) =>
|
2024-08-15 14:19:06 +02:00
|
|
|
(engine_checkbox.checked =
|
|
|
|
document.querySelector('.select_all').checked),
|
2023-06-18 19:50:32 +03:00
|
|
|
)
|
2023-05-31 18:35:02 +05:30
|
|
|
}
|
|
|
|
|
2023-07-07 20:09:43 +05:30
|
|
|
/**
|
2023-09-22 19:39:50 +03:00
|
|
|
* This function adds the functionality to sidebar buttons to only show settings
|
2023-07-07 20:09:43 +05:30
|
|
|
* related to that tab.
|
|
|
|
* @param {HTMLElement} current_tab - The current tab that was clicked.
|
|
|
|
*/
|
2023-06-18 19:50:32 +03:00
|
|
|
function setActiveTab(current_tab) {
|
2023-07-07 20:09:43 +05:30
|
|
|
// Remove the active class from all tabs and buttons
|
2023-06-18 19:50:32 +03:00
|
|
|
document
|
|
|
|
.querySelectorAll('.tab')
|
|
|
|
.forEach((tab) => tab.classList.remove('active'))
|
|
|
|
document
|
|
|
|
.querySelectorAll('.btn')
|
|
|
|
.forEach((tab) => tab.classList.remove('active'))
|
2023-07-07 20:09:43 +05:30
|
|
|
|
|
|
|
// Add the active class to the current tab and its corresponding settings
|
2023-06-18 19:50:32 +03:00
|
|
|
current_tab.classList.add('active')
|
|
|
|
document
|
|
|
|
.querySelector(`.${current_tab.innerText.toLowerCase().replace(' ', '_')}`)
|
|
|
|
.classList.add('active')
|
|
|
|
}
|
2023-05-31 18:35:02 +05:30
|
|
|
|
2023-07-07 20:09:43 +05:30
|
|
|
/**
|
|
|
|
* This function adds the functionality to save all the user selected preferences
|
|
|
|
* to be saved in a cookie on the users machine.
|
|
|
|
*/
|
2023-06-18 19:50:32 +03:00
|
|
|
function setClientSettings() {
|
2023-07-07 20:09:43 +05:30
|
|
|
// Create an object to store the user's preferences
|
2023-06-18 19:50:32 +03:00
|
|
|
let cookie_dictionary = new Object()
|
2023-07-07 20:09:43 +05:30
|
|
|
|
2023-06-18 19:50:32 +03:00
|
|
|
document.querySelectorAll('.engine').forEach((engine_checkbox) => {
|
2024-08-15 14:19:06 +02:00
|
|
|
cookie_dictionary[engine_checkbox.parentNode.parentNode.innerText.trim()] = engine_checkbox.checked
|
2023-06-18 19:50:32 +03:00
|
|
|
})
|
2023-09-22 19:39:50 +03:00
|
|
|
|
2023-07-07 20:09:43 +05:30
|
|
|
// Set the expiration date for the cookie to 1 year from the current date
|
2023-06-18 19:50:32 +03:00
|
|
|
let expiration_date = new Date()
|
|
|
|
expiration_date.setFullYear(expiration_date.getFullYear() + 1)
|
2023-07-07 20:09:43 +05:30
|
|
|
|
|
|
|
// Save the cookie to the user's machine
|
2023-06-18 19:50:32 +03:00
|
|
|
document.cookie = `appCookie=${JSON.stringify(
|
2023-09-22 19:39:50 +03:00
|
|
|
cookie_dictionary,
|
2023-06-18 19:50:32 +03:00
|
|
|
)}; expires=${expiration_date.toUTCString()}`
|
2023-05-31 18:35:02 +05:30
|
|
|
|
2023-07-07 20:09:43 +05:30
|
|
|
// Display a success message to the user
|
2023-06-18 19:50:32 +03:00
|
|
|
document.querySelector('.message').innerText =
|
|
|
|
'✅ The settings have been saved sucessfully!!'
|
2023-06-03 12:56:42 +05:30
|
|
|
|
2023-07-07 20:09:43 +05:30
|
|
|
// Clear the success message after 10 seconds
|
2023-06-18 19:50:32 +03:00
|
|
|
setTimeout(() => {
|
|
|
|
document.querySelector('.message').innerText = ''
|
|
|
|
}, 10000)
|
2023-05-31 18:35:02 +05:30
|
|
|
}
|
|
|
|
|