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-04-29 05:50:12 +03:00
|
|
|
}
|
2020-01-21 23:26:49 +03:00
|
|
|
|
2020-04-29 05:50:12 +03:00
|
|
|
const fillConfigValues = (near, nojs, dark) => {
|
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"] : "";
|
|
|
|
near.addEventListener("keyup", function() {
|
|
|
|
configSettings["near"] = near.value;
|
2020-04-06 02:59:50 +03:00
|
|
|
});
|
|
|
|
|
2020-04-29 05:50:12 +03:00
|
|
|
nojs.checked = !!configSettings["nojs"];
|
|
|
|
nojs.addEventListener("change", function() {
|
|
|
|
configSettings["nojs"] = nojs.checked ? 1 : 0;
|
2020-04-08 21:47:21 +03:00
|
|
|
});
|
|
|
|
|
2020-04-29 05:50:12 +03:00
|
|
|
dark.checked = !!configSettings["dark"];
|
|
|
|
dark.addEventListener("change", function() {
|
|
|
|
configSettings["dark"] = dark.checked ? 1 : 0;
|
2020-04-08 21:47:21 +03:00
|
|
|
});
|
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-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");
|
|
|
|
});
|
|
|
|
|
|
|
|
const near = document.getElementById("config-near");
|
|
|
|
const noJS = document.getElementById("config-nojs");
|
|
|
|
const dark = document.getElementById("config-dark");
|
|
|
|
|
|
|
|
fillConfigValues(near, noJS, dark);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
});
|