2020-04-29 02:50:12 +00:00
|
|
|
const setupSearchLayout = () => {
|
2020-04-05 23:59:50 +00:00
|
|
|
// Setup search field
|
2020-01-21 20:26:49 +00:00
|
|
|
const searchBar = document.getElementById("search-bar");
|
|
|
|
const searchBtn = document.getElementById("search-submit");
|
|
|
|
|
2020-01-22 01:07:08 +00:00
|
|
|
// Automatically focus on search field
|
|
|
|
searchBar.focus();
|
|
|
|
searchBar.select();
|
|
|
|
|
2020-01-21 20:26:49 +00:00
|
|
|
searchBar.addEventListener("keyup", function(event) {
|
|
|
|
if (event.keyCode === 13) {
|
|
|
|
event.preventDefault();
|
|
|
|
searchBtn.click();
|
2020-05-24 20:03:11 +00:00
|
|
|
} else {
|
|
|
|
handleUserInput(searchBar);
|
2020-01-21 20:26:49 +00:00
|
|
|
}
|
|
|
|
});
|
2020-05-13 06:19:51 +00:00
|
|
|
};
|
|
|
|
|
2020-04-29 15:46:18 +00:00
|
|
|
const setupConfigLayout = () => {
|
2020-05-05 00:00:43 +00:00
|
|
|
// Setup whoogle config
|
2020-04-29 15:46:18 +00: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 06:19:51 +00:00
|
|
|
};
|
2020-04-29 15:46:18 +00:00
|
|
|
|
2020-06-02 18:54:47 +00: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 15:09:31 +00:00
|
|
|
xhrPUT.open("PUT", "config?name=" + config + ".conf");
|
2020-06-02 18:54:47 +00: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 15:09:31 +00:00
|
|
|
configForm.action = 'config?name=' + config + ".conf";
|
2020-06-02 18:54:47 +00:00
|
|
|
configForm.submit();
|
|
|
|
};
|
|
|
|
|
2020-04-29 02:50:12 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
document.getElementById("main").style.display = "block";
|
|
|
|
}, 100);
|
2020-04-05 23:59:50 +00:00
|
|
|
|
2020-04-29 02:50:12 +00:00
|
|
|
setupSearchLayout();
|
|
|
|
setupConfigLayout();
|
2020-09-30 14:26:27 +00:00
|
|
|
|
2021-04-05 14:37:39 +00:00
|
|
|
document.getElementById("config-load").addEventListener("click", loadConfig);
|
|
|
|
document.getElementById("config-save").addEventListener("click", saveConfig);
|
|
|
|
|
2020-09-30 14:26:27 +00: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 20:26:49 +00:00
|
|
|
});
|