Fix long standing bug with settings and lint.

This commit is contained in:
wearrrrr 2024-02-20 13:58:27 -06:00
parent 1cab054da7
commit 5246e6e83b
5 changed files with 130 additions and 137 deletions

View file

@ -42,7 +42,7 @@ const rammerheadScopes = [
const rammerheadSession = /^\/[a-z0-9]{32}/; const rammerheadSession = /^\/[a-z0-9]{32}/;
function shouldRouteRh(req) { function shouldRouteRh(req) {
const url = new URL(req.url, 'http://0.0.0.0'); const url = new URL(req.url, "http://0.0.0.0");
return rammerheadScopes.includes(url.pathname) || rammerheadSession.test(url.pathname); return rammerheadScopes.includes(url.pathname) || rammerheadSession.test(url.pathname);
} }
@ -91,20 +91,19 @@ app.get("/search", async (req, res) => {
try { try {
const { query } = req.query; const { query } = req.query;
const response = await fetch( const response = await fetch(`http://api.duckduckgo.com/ac?q=${query}&format=json`).then(
`http://api.duckduckgo.com/ac?q=${query}&format=json` (apiRes) => apiRes.json()
).then((apiRes) => apiRes.json()); );
res.send(response); res.send(response);
} catch (err) { } catch (err) {
res.redirect(302, "/404.html"); res.redirect(302, "/404.html");
} }
}); });
app.get('*', function(req, res){ app.get("*", function (req, res) {
res.redirect(302, '/404.html'); res.redirect(302, "/404.html");
}); });
console.log(chalk.gray("Starting Alu...")); console.log(chalk.gray("Starting Alu..."));
console.log(chalk.green("Alu started successfully!")); console.log(chalk.green("Alu started successfully!"));
server.on("listening", () => { server.on("listening", () => {

View file

@ -65,4 +65,3 @@ const t = useTranslations(lang);
} }
</style> </style>
</div> </div>
</div>

View file

@ -47,13 +47,13 @@ const t = useTranslations(lang);
<div id="current-content"></div> <div id="current-content"></div>
</div> </div>
<script is:inline> <script is:inline>
function settingsLoad() {
document.addEventListener("astro:after-swap", () => { document.addEventListener("astro:after-swap", () => {
window.currentlySelectedTab = ""; window.currentlySelectedTab = "";
document.removeEventListener("setting-tabChange", determineListener); document.removeEventListener("setting-tabChange", determineListener);
}); });
window.currentlySelectedTab; window.currentlySelectedTab;
window.loadedContentStorage = {}; window.loadedContentStorage = {};
Array.from(document.getElementsByClassName("setting-tab")).forEach((tab) => { Array.from(document.getElementsByClassName("setting-tab")).forEach((tab) => {
let contentToLoad = document.getElementById("content-" + tab.id); let contentToLoad = document.getElementById("content-" + tab.id);
if (contentToLoad) { if (contentToLoad) {
@ -159,17 +159,6 @@ const t = useTranslations(lang);
} }
}); });
}); });
// Array.from(item.children).forEach((item) => {
// item.addEventListener('click', () => {
// localStorage.setItem(localStorageItem, item.dataset.setting)
// applySavedLocalStorage(localStorageItem, dropdownID)
// closeDropdown(item.parentElement.id);
// if (typeof optionalCallback == "function") {
// optionalCallback();
// }
// })
// })
} }
function applyInputListeners(item, localStorageItem) { function applyInputListeners(item, localStorageItem) {
@ -353,6 +342,11 @@ const t = useTranslations(lang);
break; break;
} }
} }
}
document.addEventListener('astro:after-swap', () => {
settingsLoad()
})
settingsLoad()
</script> </script>
<style is:global> <style is:global>
.content-hidden { .content-hidden {

View file

@ -16,7 +16,13 @@ export function getStaticPaths() {
<h1 class="title-text">{t("menu.welcome")}</h1> <h1 class="title-text">{t("menu.welcome")}</h1>
<div class="form-wrapper"> <div class="form-wrapper">
<form class="url-input-form" id="url-input-form"> <form class="url-input-form" id="url-input-form">
<input class="url-input" id="url-input" type="text" placeholder={t("menu.search")} autocomplete="off" /> <input
class="url-input"
id="url-input"
type="text"
placeholder={t("menu.search")}
autocomplete="off"
/>
<div id="search-suggestions"></div> <div id="search-suggestions"></div>
<div id="loading-content">Loading...</div> <div id="loading-content">Loading...</div>
<div id="top-bar"></div> <div id="top-bar"></div>
@ -38,11 +44,8 @@ export function getStaticPaths() {
<p> <p>
Spreading the word of Alu is a great start, but if you really enjoy Alu, and want private Spreading the word of Alu is a great start, but if you really enjoy Alu, and want private
links, consider supporting me through Patreon! You can support me links, consider supporting me through Patreon! You can support me
<Link <Link href="https://www.patreon.com/wearr/membership" newTab linkTextContent="Here!" />,
href="https://www.patreon.com/wearr/membership" thank you for helping to make Alu great!
newTab
linkTextContent="Here!"
/>, thank you for helping to make Alu great!
</p> </p>
</div> </div>
</div> </div>
@ -52,8 +55,8 @@ export function getStaticPaths() {
<script> <script>
type Suggestion = { type Suggestion = {
phrase: string; phrase: string;
} };
const debounce = (func: Function, delay: number): (...args: any[]) => void => { const debounce = (func: Function, delay: number): ((...args: any[]) => void) => {
let debounceTimer: NodeJS.Timeout; let debounceTimer: NodeJS.Timeout;
return function (this: Function, ...args: any[]) { return function (this: Function, ...args: any[]) {
const context: any = this; const context: any = this;
@ -78,7 +81,7 @@ export function getStaticPaths() {
suggestionElement.style.marginTop = "5px"; suggestionElement.style.marginTop = "5px";
suggestionElement.innerText = suggestion.phrase; suggestionElement.innerText = suggestion.phrase;
suggestionElement.addEventListener("click", () => { suggestionElement.addEventListener("click", () => {
console.log("here") console.log("here");
urlInput.value = suggestion.phrase; urlInput.value = suggestion.phrase;
// I can't be bothered to extend the window object, so I'm just going to use any // I can't be bothered to extend the window object, so I'm just going to use any
(window as any).loadFormContent(); (window as any).loadFormContent();
@ -95,10 +98,10 @@ export function getStaticPaths() {
} }
function addEventListeners() { function addEventListeners() {
let urlInput = document.getElementById("url-input") as HTMLInputElement; let urlInput = document.getElementById("url-input") as HTMLInputElement;
let searchSuggestions = document.getElementById('search-suggestions') as HTMLDivElement; let searchSuggestions = document.getElementById("search-suggestions") as HTMLDivElement;
// Silently return if the required elements aren't found, this prevents the console from getting cluttered with errors. // Silently return if the required elements aren't found, this prevents the console from getting cluttered with errors.
if (!urlInput || !searchSuggestions) return; if (!urlInput || !searchSuggestions) return;
urlInput.addEventListener('focus', () => { urlInput.addEventListener("focus", () => {
if (!searchSuggestions) { if (!searchSuggestions) {
throw new Error("searchSuggestions is null"); throw new Error("searchSuggestions is null");
} }
@ -107,23 +110,21 @@ export function getStaticPaths() {
searchSuggestions.style.pointerEvents = "all"; searchSuggestions.style.pointerEvents = "all";
urlInput.classList.add("search-results"); urlInput.classList.add("search-results");
} }
}) });
urlInput.addEventListener('blur', () => { urlInput.addEventListener("blur", () => {
searchSuggestions.style.opacity = "0"; searchSuggestions.style.opacity = "0";
setTimeout(() => { setTimeout(() => {
searchSuggestions.style.pointerEvents = "none"; searchSuggestions.style.pointerEvents = "none";
}, 200); }, 200);
urlInput.classList.remove("search-results") urlInput.classList.remove("search-results");
}) });
urlInput.addEventListener("keyup", () => { urlInput.addEventListener("keyup", () => {
debounce(sendAPIRequest, 300).apply(null, [urlInput, searchSuggestions]); debounce(sendAPIRequest, 300).apply(null, [urlInput, searchSuggestions]);
}); });
} }
document.addEventListener('astro:after-swap', addEventListeners); document.addEventListener("astro:after-swap", addEventListeners);
addEventListeners(); addEventListeners();
</script> </script>
<style> <style>

View file

@ -2,6 +2,6 @@
"extends": "astro/tsconfigs/strict", "extends": "astro/tsconfigs/strict",
"exclude": ["node_modules/**", "dist/**"], "exclude": ["node_modules/**", "dist/**"],
"compilerOptions": { "compilerOptions": {
"verbatimModuleSyntax": false, "verbatimModuleSyntax": false
} }
} }