2020-04-29 05:50:12 +03:00
|
|
|
const setupSearchLayout = () => {
|
2020-04-06 02:59:50 +03:00
|
|
|
// Setup search field
|
2020-01-21 23:26:49 +03:00
|
|
|
const searchBar = document.getElementById("search-bar");
|
|
|
|
const searchBtn = document.getElementById("search-submit");
|
|
|
|
|
2020-01-22 04:07:08 +03:00
|
|
|
// Automatically focus on search field
|
|
|
|
searchBar.focus();
|
|
|
|
searchBar.select();
|
|
|
|
|
2020-01-21 23:26:49 +03:00
|
|
|
searchBar.addEventListener("keyup", function(event) {
|
|
|
|
if (event.keyCode === 13) {
|
|
|
|
event.preventDefault();
|
|
|
|
searchBtn.click();
|
|
|
|
}
|
|
|
|
});
|
2020-05-13 09:19:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const fillConfigValues = () => {
|
|
|
|
// Establish all config value elements
|
|
|
|
const near = document.getElementById("config-near");
|
|
|
|
const noJS = document.getElementById("config-nojs");
|
|
|
|
const dark = document.getElementById("config-dark");
|
2020-05-23 23:27:23 +03:00
|
|
|
const safe = document.getElementById("config-safe");
|
2020-05-13 09:19:51 +03:00
|
|
|
const url = document.getElementById("config-url");
|
2020-05-16 01:10:31 +03:00
|
|
|
const newTab = document.getElementById("config-new-tab");
|
2020-05-13 09:19:51 +03:00
|
|
|
const getOnly = document.getElementById("config-get-only");
|
2020-01-21 23:26:49 +03:00
|
|
|
|
2020-04-06 02:59:50 +03:00
|
|
|
// Request existing config info
|
2020-04-08 21:47:21 +03:00
|
|
|
let xhrGET = new XMLHttpRequest();
|
2020-04-17 03:12:30 +03:00
|
|
|
xhrGET.open("GET", "/config");
|
2020-04-08 21:47:21 +03:00
|
|
|
xhrGET.onload = function() {
|
|
|
|
if (xhrGET.readyState === 4 && xhrGET.status !== 200) {
|
2020-05-05 03:00:43 +03:00
|
|
|
alert("Error loading Whoogle config");
|
2020-04-06 02:59:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow for updating/saving config values
|
2020-04-08 21:47:21 +03:00
|
|
|
let configSettings = JSON.parse(xhrGET.responseText);
|
2020-04-06 02:59:50 +03:00
|
|
|
|
2020-04-29 05:50:12 +03:00
|
|
|
near.value = configSettings["near"] ? configSettings["near"] : "";
|
2020-05-13 09:19:51 +03:00
|
|
|
noJS.checked = !!configSettings["nojs"];
|
2020-04-29 05:50:12 +03:00
|
|
|
dark.checked = !!configSettings["dark"];
|
2020-05-23 23:27:23 +03:00
|
|
|
safe.checked = !!configSettings["safe"];
|
2020-05-13 09:19:51 +03:00
|
|
|
getOnly.checked = !!configSettings["get_only"];
|
2020-05-16 01:10:31 +03:00
|
|
|
newTab.checked = !!configSettings["new_tab"];
|
2020-05-10 22:27:02 +03:00
|
|
|
|
|
|
|
// Addresses the issue of incorrect URL being used behind reverse proxy
|
|
|
|
url.value = configSettings["url"] ? configSettings["url"] : "";
|
2020-04-06 02:59:50 +03:00
|
|
|
};
|
2020-04-29 05:50:12 +03:00
|
|
|
|
2020-04-08 21:47:21 +03:00
|
|
|
xhrGET.send();
|
2020-05-13 09:19:51 +03:00
|
|
|
};
|
2020-04-29 05:50:12 +03:00
|
|
|
|
2020-04-29 18:46:18 +03:00
|
|
|
const setupConfigLayout = () => {
|
2020-05-05 03:00:43 +03:00
|
|
|
// Setup whoogle config
|
2020-04-29 18:46:18 +03:00
|
|
|
const collapsible = document.getElementById("config-collapsible");
|
|
|
|
collapsible.addEventListener("click", function() {
|
|
|
|
this.classList.toggle("active");
|
|
|
|
let content = this.nextElementSibling;
|
|
|
|
if (content.style.maxHeight) {
|
|
|
|
content.style.maxHeight = null;
|
|
|
|
} else {
|
|
|
|
content.style.maxHeight = content.scrollHeight + "px";
|
|
|
|
}
|
|
|
|
|
|
|
|
content.classList.toggle("open");
|
|
|
|
});
|
|
|
|
|
2020-05-13 09:19:51 +03:00
|
|
|
fillConfigValues();
|
|
|
|
};
|
2020-04-29 18:46:18 +03:00
|
|
|
|
2020-04-29 05:50:12 +03:00
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
document.getElementById("main").style.display = "block";
|
|
|
|
}, 100);
|
2020-04-06 02:59:50 +03:00
|
|
|
|
2020-04-29 05:50:12 +03:00
|
|
|
setupSearchLayout();
|
|
|
|
setupConfigLayout();
|
2020-01-21 23:26:49 +03:00
|
|
|
});
|