Skip to content

Commit

Permalink
debounce more; fuck formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
mi2ebi committed Dec 19, 2024
1 parent 8ef01f8 commit 760d865
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 107 deletions.
28 changes: 12 additions & 16 deletions events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var worker = { postMessage() { } };
var worker = {postMessage() {}};
var page, res = [];
window.addEventListener("scroll", function (e) {
window.addEventListener("scroll", function(e) {
if (window.innerHeight + window.scrollY >= document.body.scrollHeight - 100) {
page++;
load(res, page);
Expand All @@ -20,40 +20,36 @@ function clearRes() {
function navigate(q, push_state = true, is_search = false) {
clearRes();
if (!is_search) $`search`.value = q;

let newLink = window.location.href.split("?")[0] + (q ? "?q=" + encodeURIComponent(q) : '')
if (push_state) {
window.history.pushState('', '', newLink)
} else {
window.history.replaceState('', '', newLink)
}

if (q == '') {
page = 0;
return
return;
}

$`bottom`.innerHTML = "chum lao jí pó jóaıse"
worker.postMessage({ q })
worker.postMessage({q})
}

let timer;
$`search`.addEventListener("input", function () {
$`search`.addEventListener("input", function() {
clearTimeout(timer);
clearRes();
$`bottom`.innerHTML = "chum lao jí pó jóaıse";
timer = setTimeout(() => {
navigate(this.value.trim(), false, true);
}, 100)
}, 200);
});
$`clear`.addEventListener("click", function () {
$`clear`.addEventListener("click", function() {
$`search`.focus();
navigate("", false);
});
$`english`.addEventListener("click", function () {
let newQuery =
$`search`.value.split(" ")
.filter(t => !/^([!-]|not:)*(\$|scope:)/.test(t))
.concat(["$en"]).join(" ").trim();
$`english`.addEventListener("click", function() {
let newQuery = $`search`.value.split(" ")
.filter(t => !/^([!-]|not:)*(\$|scope:)/.test(t))
.concat(["$en"]).join(" ").trim();
$`search`.focus();
navigate(newQuery, false);
});
29 changes: 13 additions & 16 deletions helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const $ = x => document.getElementById(x);

function mkel(tag, props, children) {
const element = document.createElement(tag);
Object.assign(element, props);
Expand All @@ -10,45 +9,45 @@ function mkel(tag, props, children) {
}
return element;
}

function htmlify(json) {
return mkel("div", { "className": "entry" }, [
return mkel("div", {"className": "entry"}, [
mkel("dt", {}, [
json.warn ? mkel("span", {}, "⚠\ufe0f ") : null,
mkel("a", {
"className": "toa",
onclick() { navigate(json.head) }
onclick() {navigate(json.head)}
}, [json.head]),
" • ",
mkel("a", {
"className": "scope",
onclick() { navigate("scope:" + json.scope) }
onclick() {navigate("scope:" + json.scope)}
}, [json.scope]),
" ",
mkel("a", { onclick() { navigate("@" + json.user) } }, [json.user]),
mkel("a", {onclick() {navigate("@" + json.user)}}, [json.user]),
" ",
mkel("span", { "className": "score" }, [
mkel("span", {"className": "score"}, [
("" + json.score).replace(/^0$/, "±").replace(/^(\d)/, "+$1")
]),
" • ",
mkel("a", { onclick() { navigate("#" + json.id) } }, [json.date.slice(0, 10)]),
mkel("a", {onclick() {navigate("#" + json.id)}}, [json.date.slice(0, 10)]),
" ",
mkel("a", { "href": "https://toadua.uakci.space/#" + encodeURIComponent("#" + json.id) }, ["↗"]),
mkel("a", {"href": "https://toadua.uakci.space/#" + encodeURIComponent("#" + json.id)}, ["↗"]),
]),
mkel("dd", {}, replaceLinks(json.body)),
mkel("div", { "className": "notes indent" }, json.notes.flatMap(note => [
mkel("span", { "className": "score" }, [
mkel("a", { onclick() { navigate("@" + note.user) } }, [note.user]),
mkel("div", {"className": "notes indent"}, json.notes.flatMap(note => [
mkel("span", {"className": "score"}, [
mkel("a", {onclick() {navigate("@" + note.user)}}, [note.user]),
": "
]),
mkel("span", {}, replaceLinks(note.content)),
" ",
mkel("span", { "className": "scope" }, [/^\d/.test(note.date) ? note.date.slice(0, 10) : new Date(note.date).toISOString().slice(0, 10)]),
mkel("span", {"className": "scope"}, [/^\d/.test(note.date)
? note.date.slice(0, 10)
: new Date(note.date).toISOString().slice(0, 10)]),
mkel("br", {}, [])
]))
]);
}

function replaceLinks(str) {
// ugh why isn't /u a default regex flag
let parts = str
Expand All @@ -57,7 +56,6 @@ function replaceLinks(str) {
.replace(/(?<!🌐[^ ]*)(#[a-z0-9_-]{9,})(?=[^a-z0-9_-]|$)/giu, "🆔$1🆔")
.replace(/<((?![/ ])[^>]+(?<! ))>(?!.+<\/\1>)/giu, "📎$1📎")
.match(/([📦🆔🌐📎]).*?\1|[^📦🆔🌐📎]+/ug);

return parts.map(part => {
part = [...part];
let head = part[0], body = part.slice(1, -1).join("")
Expand All @@ -69,7 +67,6 @@ function replaceLinks(str) {
return mkel("a", { onclick() { navigate(search) } }, [body]);
})
}

function load(res, page) {
if (!res) return;
const start = page * 100;
Expand Down
52 changes: 23 additions & 29 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
<body>
<h1>mí soakue / 󱛘󱚰󱛊󱚹󱛛󱛓󱚺󱛃󱛍󱚺󱛄󱚲󱛍󱚴󱛓󱛙</h1>
<p><a href="https://github.com/berrymot/soakue">github</a></p>
<input type="text" id="search" name="search" autocomplete="off" spellcheck="false" size="1"
placeholder="chum lao jí pó tóakue" disabled />
<input
type="text" id="search" name="search"
autocomplete="off" spellcheck="false" size="1"
placeholder="chum lao jí pó tóakue" disabled
/>
<span id="btns">
<button type="reset" id="clear">sıajòaı</button>
<button type="button" id="english">toìqlızuno</button>
Expand All @@ -24,41 +27,32 @@ <h1>mí soakue / 󱛘󱚰󱛊󱚹󱛛󱛓󱚺󱛃󱛍󱚺󱛄󱚲󱛍󱚴󱛓
<div id="bottom"></div>
<div id="howto">
<h2>about</h2>
<p>this updates every day. it used to update every 6 hours, but github actions scheduling is not very precise.
</p>
<p>the fonts here are mostly in Noto, except the font for Tangut (which is by BabelStone) and the Deranı one
(Iosevka modified by Laqme+Kıa).</p>
<p>this updates every day. it used to update every 6 hours, but github actions scheduling is not very precise.</p>
<p>the fonts here are mostly in Noto, except the font for Tangut (which is by BabelStone) and the Deranı one (Iosevka modified by Laqme+Kıa).</p>
<p>kuaq kıe jí mí Sofıa lä soa muoja já ka :3</p>
<h2>operators</h2>
<p><code>= head</code> searches just the words themselves. there are a couple fancy things you can do with this:
</p>
<div class="indent">
<p>
<code>*</code> matches anything (or nothing, i.e. it's <code>/.*/</code>)<br />
<code>?</code> matches any single letter, <code>/[aeıoumpbfntdczsrljꝡqkg'h]|[ncs]h/i</code><br />
<code>CVFQ</code> match their <a href="https://toaq.net/refgram/phonology">refgram</a> definitions (note
that <code>VV</code>&nbsp;⊋&nbsp;<code>F</code>)<br />
<code>R</code> matches a raku</code><br />
<code>_</code> matches a space<br />
<code>()[]|</code> work like in <a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#writing_a_regular_expression_pattern">regex</a>
</p>
</div>
<div class="indent">
<p>
<code>i</code><code>ı</code>, <code>vw</code><code></code>, <code>x</code><code>'</code><br />
<code>.</code><code>◌̣</code><br />
<code>1234</code><code>◌̀◌́◌̈◌̂</code>
</p>
</div>
<p><code>= head</code> searches just the words themselves. there are a couple fancy things you can do with this:</p>
<div class="indent"><p>
<code>*</code> matches anything (or nothing, i.e. it's <code>/.*/</code>)<br />
<code>?</code> matches any single letter, <code>/[aeıoumpbfntdczsrljꝡqkg'h]|[ncs]h/i</code><br />
<code>CVFQ</code> match their <a href="https://toaq.net/refgram/phonology">refgram</a> definitions (note
that <code>VV</code>&nbsp;⊋&nbsp;<code>F</code>)<br />
<code>R</code> matches a raku</code><br />
<code>_</code> matches a space<br />
<code>()[]|</code> work like in <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#writing_a_regular_expression_pattern">regex</a>
</p></div>
<div class="indent"><p>
<code>i</code><code>ı</code>, <code>vw</code><code></code>, <code>x</code><code>'</code><br />
<code>.</code><code>◌̣</code><br />
<code>1234</code><code>◌̀◌́◌̈◌̂</code>
</p></div>
<p><code>~</code> is similar but will also match word-internally: <code>~◌</code> = <code>=*◌*</code></p>
<p><code>@ user</code> searches word authors</p>
<p><code># id</code> finds the word with id <i>x</i></p>
<p><code>/ arity</code> finds definitions with <i>x</i> slots</p>
<p><code>$ scope</code> shows words defined under a particular language code</p>
<p><code>! - not</code> negate a query, e.g. <code>-@official</code></p>
<p><code>^ score</code> finds definitions with at least +<i>x</i> votes. you can do <code>!^</code> for less
than <i>x</i>, and <code>^=</code> for exactly <i>x</i>.</p>
<p><code>^ score</code> finds definitions with at least +<i>x</i> votes. you can do <code>!^</code> for less than <i>x</i>, and <code>^=</code> for exactly <i>x</i>.</p>
<h2>things you can't do here</h2>
<p>anything that requires logging in</p>
</div>
Expand Down
Loading

0 comments on commit 760d865

Please sign in to comment.