このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
whoogle-mod/app/static/js/controller.js

53 行
1.6 KiB
JavaScript
Raw 通常表示 履歴

2020-01-22 05:26:49 +09:00
document.addEventListener("DOMContentLoaded", function() {
// Setup search field
2020-01-22 05:26:49 +09:00
const searchBar = document.getElementById("search-bar");
const searchBtn = document.getElementById("search-submit");
// Automatically focus on search field
searchBar.focus();
searchBar.select();
2020-01-22 05:26:49 +09:00
searchBar.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
searchBtn.click();
}
});
searchBtn.onclick = function() {
window.location.href = '/search?q=' + encodeURI(searchBar.value);
};
// Setup shoogle config
const saveConfig = document.getElementById("config-submit");
const nearConfig = document.getElementById("config-near");
// Request existing config info
var xhr = new XMLHttpRequest();
xhr.open("GET", "/static/config.json");
xhr.onload = function() {
if (xhr.readyState === 4 && xhr.status !== 200) {
alert("Error loading Shoogle config");
return;
}
// Allow for updating/saving config values
let configSettings = JSON.parse(xhr.responseText);
nearConfig.value = configSettings["near"];
nearConfig.addEventListener("keyup", function(event) {
configSettings["near"] = nearConfig.value;
});
saveConfig.onclick = function() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/config");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify(configSettings));
}
};
xhr.send();
2020-01-22 05:26:49 +09:00
});