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-24 23:03:11 +03:00
|
|
|
} else {
|
|
|
|
handleUserInput(searchBar);
|
2020-01-21 23:26:49 +03:00
|
|
|
}
|
|
|
|
});
|
2020-05-13 09:19:51 +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
|
|
|
};
|
2020-04-29 18:46:18 +03:00
|
|
|
|
2020-06-02 21:54:47 +03:00
|
|
|
const loadConfig = event => {
|
|
|
|
event.preventDefault();
|
|
|
|
let config = prompt("Enter name of config:");
|
|
|
|
if (!config) {
|
|
|
|
alert("Must specify a name for the config to load");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let xhrPUT = new XMLHttpRequest();
|
2020-10-29 18:09:31 +03:00
|
|
|
xhrPUT.open("PUT", "config?name=" + config + ".conf");
|
2020-06-02 21:54:47 +03:00
|
|
|
xhrPUT.onload = function() {
|
|
|
|
if (xhrPUT.readyState === 4 && xhrPUT.status !== 200) {
|
|
|
|
alert("Error loading Whoogle config");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
location.reload(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPUT.send();
|
|
|
|
};
|
|
|
|
|
|
|
|
const saveConfig = event => {
|
|
|
|
event.preventDefault();
|
|
|
|
let config = prompt("Enter name for this config:");
|
|
|
|
if (!config) {
|
|
|
|
alert("Must specify a name for the config to save");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let configForm = document.getElementById("config-form");
|
2020-10-29 18:09:31 +03:00
|
|
|
configForm.action = 'config?name=' + config + ".conf";
|
2020-06-02 21:54:47 +03:00
|
|
|
configForm.submit();
|
|
|
|
};
|
|
|
|
|
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-09-30 17:26:27 +03:00
|
|
|
|
|
|
|
// Focusing on the search input field requires a delay for elements to finish
|
|
|
|
// loading (seemingly only on FF)
|
|
|
|
setTimeout(function() { document.getElementById("search-bar").focus(); }, 250);
|
2020-01-21 23:26:49 +03:00
|
|
|
});
|