Compare commits
11 Commits
05623222c8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ef9aed3126 | |||
| b6b3655142 | |||
| 38376225c8 | |||
| 00032f9cc0 | |||
| c35d27198c | |||
| 82e4d36b14 | |||
| a6542fbe60 | |||
| 30b3cf0d0a | |||
| 132e49b589 | |||
| 19b1c73dca | |||
| b8ae68eff8 |
Submodule heonian-resources updated: 1222e87853...9f0c4998ee
@@ -37,7 +37,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<a id="showAllWords">show all words</a> <a id="randomWord">random word</a> <a href="#">resources</a>
|
||||
<a id="showAllWords">show all words</a> <a id="randomWord">random word</a> <a href="https://heonian.dreamnotes.space">wiki</a>
|
||||
</div>
|
||||
<noscript>turn on js doofus</noscript>
|
||||
<span id="update">update available! close all open hisho tabs and reopen hisho to update.</span>
|
||||
|
||||
72
main.js
72
main.js
@@ -20,6 +20,7 @@ function toggleIME() {
|
||||
|
||||
function animateHeader(inout = false) {
|
||||
//todo: debounce this
|
||||
// const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)"); //do shit
|
||||
if (inout) {
|
||||
header.classList.add("header-animation-reverse");
|
||||
header.classList.remove("header-animation");
|
||||
@@ -216,6 +217,7 @@ function loadDictionary() {
|
||||
//prepare search. maybe async this if we're loading a specific word?
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
try {
|
||||
if (keys[i] == "") continue;
|
||||
//create array
|
||||
searchDictionary[keys[i]] = [];
|
||||
|
||||
@@ -241,6 +243,13 @@ function loadDictionary() {
|
||||
|
||||
//ok, we're all ready!
|
||||
document.querySelector("header input").placeholder = "search";
|
||||
const url = new URL(window.location);
|
||||
const val = url.searchParams.get('s');
|
||||
if (val != null) {
|
||||
header.querySelector("input").value = val;
|
||||
doSearch(false);
|
||||
animateHeader(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
alert("yeah something went horribly wrong loading the wordlist so uh,,, certified ike moment");
|
||||
@@ -250,13 +259,11 @@ function loadDictionary() {
|
||||
}
|
||||
|
||||
function search(word, type) {
|
||||
console.log(type);
|
||||
if (type == "all") { word = "" };
|
||||
if (type == "random") {
|
||||
let random = Math.floor(Math.random() * Object.keys(json).length);
|
||||
return [Object.keys(json)[random]];
|
||||
}
|
||||
console.log(word);
|
||||
let words = word.split(" ");
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
words[i] = stripWord(words[i]);
|
||||
@@ -372,11 +379,15 @@ function doSearch(state = true) {
|
||||
} else {
|
||||
types[json[results[i]][o]["type"]]++;
|
||||
}
|
||||
//number, meaning (*required)
|
||||
meaning.innerHTML += "<span class='result-number'>" + (o + 1) + "</span><span class='result-big'>" + json[results[i]][o]["meaning"] + "</span>";
|
||||
//longer translation (below are not required, make sure to check for them)
|
||||
if (json[results[i]][o]["translation"] != undefined && json[results[i]][o]["translation"].toLowerCase() != json[results[i]][o]["meaning"].toLowerCase()) {
|
||||
meaning.innerHTML += "<br><span class='result-translation'>" + json[results[i]][o]["translation"] + "</span>";
|
||||
//meaning, tl, etc
|
||||
if (json[results[i]][o]["meaning"] != undefined) {
|
||||
meaning.innerHTML += "<span class='result-number'>" + (o + 1) + "</span><span class='result-big'>" + escapeHTML(json[results[i]][o]["meaning"]) + "</span>";
|
||||
} else if (json[results[i]][o]["translation"] != undefined) {
|
||||
meaning.innerHTML += "<span class='result-number'>" + (o + 1) + "</span><span class='result-big'>" + escapeHTML(json[results[i]][o]["translation"]) + "</span>";
|
||||
}
|
||||
if (json[results[i]][o]["translation"] != undefined && json[results[i]][o]["meaning"] != undefined) {
|
||||
if (json[results[i]][o]["translation"].toLowerCase() != json[results[i]][o]["meaning"].toLowerCase())
|
||||
meaning.innerHTML += "<br><span class='result-translation'>" + json[results[i]][o]["translation"] + "</span>";
|
||||
}
|
||||
//example
|
||||
if (json[results[i]][o]["examples"] != undefined) {
|
||||
@@ -427,14 +438,14 @@ function doSearch(state = true) {
|
||||
}
|
||||
//notes
|
||||
if (json[results[i]][o]["notes"] != undefined) {
|
||||
meaning.innerHTML += "<p class='result-notes'>" + json[results[i]][o]["notes"] + "</p>";
|
||||
meaning.innerHTML += "<p class='result-notes'>" + escapeHTML(json[results[i]][o]["notes"]) + "</p>";
|
||||
}
|
||||
//(source, etc)
|
||||
if (json[results[i]][o]["canon-etymology"] != undefined) {
|
||||
meaning.innerHTML += "<details class='result-meta'><summary>Canon Etymology</summary><p>" + json[results[i]][o]["canon-etymology"] + "</p></details>";
|
||||
meaning.innerHTML += "<details class='result-meta'><summary>Canon Etymology</summary><p>" + escapeHTML(json[results[i]][o]["canon-etymology"]) + "</p></details>";
|
||||
}
|
||||
if (json[results[i]][o]["meta-etymology"] != undefined) {
|
||||
meaning.innerHTML += "<details class='result-meta'><summary>Meta Etymology</summary><p>" + json[results[i]][o]["meta-etymology"] + "</p></details>";
|
||||
meaning.innerHTML += "<details class='result-meta'><summary>Meta Etymology</summary><p>" + escapeHTML(json[results[i]][o]["meta-etymology"]) + "</p></details>";
|
||||
}
|
||||
//todo
|
||||
result.appendChild(meaning); //y, yeah.
|
||||
@@ -445,20 +456,21 @@ function doSearch(state = true) {
|
||||
let header = document.createElement("div");
|
||||
header.classList.add("results-header");
|
||||
//When using search methods, accomodate search text.
|
||||
//we dont wanna actually change val, because this breaks searchParams
|
||||
switch (type) {
|
||||
//show:all
|
||||
case "all":
|
||||
val = "Showing all words";
|
||||
header.innerHTML += "<span class='heonian'>showing all words</span><br>";
|
||||
break;
|
||||
case "random":
|
||||
val = "Showing random word: " + results[0];
|
||||
//think about whether we wanna set searchparams to this, though..?
|
||||
header.innerHTML += "<span class='heonian'>showing random word: " + results[0] + "</span><br>";
|
||||
break;
|
||||
//OMG A WORD
|
||||
default:
|
||||
val = "search results for: " + val;
|
||||
header.innerHTML += "<span class='heonian'>search results for: " + val + "</span><br>";
|
||||
break;
|
||||
}
|
||||
header.innerHTML += "<span class='heonian'>" + val + "</span><br>";
|
||||
for (let i in types) {
|
||||
if (i !== "") { header.innerHTML += "<span class='results-header-count'>" + i + "s - " + types[i] + "</span>"; }
|
||||
}
|
||||
@@ -478,6 +490,11 @@ function goHome(state = true) {
|
||||
|
||||
async function registerSW() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
|
||||
console.log("localhost - not registering sw"); //because spamming removeSW() every time i make a change is annoying;
|
||||
removeSW(); //just in case =w=
|
||||
return;
|
||||
}
|
||||
navigator.serviceWorker.register('./sw.js').then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
@@ -491,21 +508,11 @@ async function registerSW() {
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
header.querySelector("#update").style.display = "block";
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -517,10 +524,18 @@ async function registerSW() {
|
||||
}
|
||||
|
||||
function removeSW() {
|
||||
caches.keys().then(function(names) {
|
||||
for (let name of names)
|
||||
caches.delete(name);
|
||||
}); //this doesnt actually seem to work :/ but . i'll leave it in for later fixing
|
||||
navigator.serviceWorker.getRegistrations().then(function(registrations) {
|
||||
for(let registration of registrations) {
|
||||
registration.unregister()
|
||||
}}); //dev use only!! or whatever... i just copypasted this from SO
|
||||
for (let registration of registrations)
|
||||
registration.unregister();
|
||||
}); //dev use only!! or whatever... i just copypasted this from SO
|
||||
}
|
||||
|
||||
function escapeHTML(str){
|
||||
return new Option(str).innerHTML;
|
||||
}
|
||||
|
||||
window.onload = () => {
|
||||
@@ -560,8 +575,7 @@ window.onload = () => {
|
||||
doSearch(false);
|
||||
}
|
||||
});
|
||||
registerSW();
|
||||
//also check if ?s is there . for hecks sake (todo) (TODO!!!!!!)
|
||||
registerSW(); //considering disabling this for now,.... itso nly lead to trouble :////
|
||||
}
|
||||
|
||||
const sortObject = obj => Object.keys(obj).sort().reduce((res, key) => (res[key] = obj[key], res), {})
|
||||
7
pre-commit
Executable file
7
pre-commit
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
VAR="const currentVersion = '$RANDOM';"
|
||||
sed "1s/.*/$VAR/" sw.js > sw.js.new
|
||||
mv sw.js.new sw.js
|
||||
git add sw.js
|
||||
Reference in New Issue
Block a user