mirror of
https://github.com/benbusby/whoogle-search.git
synced 2025-10-25 15:53:27 -04:00
Squashed commit of the following:
commit 37e22d2945b077a94d9997d064f4355ff8819bae
Author: Ben Busby <benbusby@protonmail.com>
Date: Mon Apr 5 10:27:05 2021 -0400
Pass user config to logo template
commit 2406fee05c3e221112fbe802fbf2ecca1df99127
Author: Ben Busby <benbusby@protonmail.com>
Date: Mon Apr 5 10:24:54 2021 -0400
Fix incorrect contrast text in dark theme
commit 91dd677e22c2e99819123154e03e9f519f95a9bd
Author: Ben Busby <benbusby@protonmail.com>
Date: Fri Apr 2 17:21:38 2021 -0400
Remove inline onclicks, fix svg sizing
commit 91bbf9c0fae36febd6a6a0d8e6a560babe8622d5
Merge: 72637df b1227bd
Author: Ben Busby <benbusby@protonmail.com>
Date: Fri Apr 2 15:35:37 2021 -0400
Merge remote-tracking branch 'origin/develop' into custom-css-tweaks
commit 72637df213f4b9e83e4b58fe76973de02f63ec8e
Author: Ben Busby <benbusby@protonmail.com>
Date: Fri Apr 2 11:38:38 2021 -0400
Use svg logo w/ custom styling on results pages
commit 666a7ceac4a6e4d3fe1975dcee91e6094b66149e
Author: Ben Busby <benbusby@protonmail.com>
Date: Fri Apr 2 11:10:37 2021 -0400
Split whoogle-accent into whoogle-element-bg and whoogle-logo
See discussion on #247
86 lines
2.5 KiB
JavaScript
86 lines
2.5 KiB
JavaScript
const setupSearchLayout = () => {
|
|
// Setup search field
|
|
const searchBar = document.getElementById("search-bar");
|
|
const searchBtn = document.getElementById("search-submit");
|
|
|
|
// Automatically focus on search field
|
|
searchBar.focus();
|
|
searchBar.select();
|
|
|
|
searchBar.addEventListener("keyup", function(event) {
|
|
if (event.keyCode === 13) {
|
|
event.preventDefault();
|
|
searchBtn.click();
|
|
} else {
|
|
handleUserInput(searchBar);
|
|
}
|
|
});
|
|
};
|
|
|
|
const setupConfigLayout = () => {
|
|
// Setup whoogle config
|
|
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 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();
|
|
xhrPUT.open("PUT", "config?name=" + config + ".conf");
|
|
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");
|
|
configForm.action = 'config?name=' + config + ".conf";
|
|
configForm.submit();
|
|
};
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
setTimeout(function() {
|
|
document.getElementById("main").style.display = "block";
|
|
}, 100);
|
|
|
|
setupSearchLayout();
|
|
setupConfigLayout();
|
|
|
|
document.getElementById("config-load").addEventListener("click", loadConfig);
|
|
document.getElementById("config-save").addEventListener("click", saveConfig);
|
|
|
|
// 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);
|
|
});
|