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>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<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>
|
</div>
|
||||||
<noscript>turn on js doofus</noscript>
|
<noscript>turn on js doofus</noscript>
|
||||||
<span id="update">update available! close all open hisho tabs and reopen hisho to update.</span>
|
<span id="update">update available! close all open hisho tabs and reopen hisho to update.</span>
|
||||||
|
|||||||
70
main.js
70
main.js
@@ -20,6 +20,7 @@ function toggleIME() {
|
|||||||
|
|
||||||
function animateHeader(inout = false) {
|
function animateHeader(inout = false) {
|
||||||
//todo: debounce this
|
//todo: debounce this
|
||||||
|
// const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)"); //do shit
|
||||||
if (inout) {
|
if (inout) {
|
||||||
header.classList.add("header-animation-reverse");
|
header.classList.add("header-animation-reverse");
|
||||||
header.classList.remove("header-animation");
|
header.classList.remove("header-animation");
|
||||||
@@ -216,6 +217,7 @@ function loadDictionary() {
|
|||||||
//prepare search. maybe async this if we're loading a specific word?
|
//prepare search. maybe async this if we're loading a specific word?
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
try {
|
try {
|
||||||
|
if (keys[i] == "") continue;
|
||||||
//create array
|
//create array
|
||||||
searchDictionary[keys[i]] = [];
|
searchDictionary[keys[i]] = [];
|
||||||
|
|
||||||
@@ -241,6 +243,13 @@ function loadDictionary() {
|
|||||||
|
|
||||||
//ok, we're all ready!
|
//ok, we're all ready!
|
||||||
document.querySelector("header input").placeholder = "search";
|
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 {
|
} else {
|
||||||
alert("yeah something went horribly wrong loading the wordlist so uh,,, certified ike moment");
|
alert("yeah something went horribly wrong loading the wordlist so uh,,, certified ike moment");
|
||||||
@@ -250,13 +259,11 @@ function loadDictionary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function search(word, type) {
|
function search(word, type) {
|
||||||
console.log(type);
|
|
||||||
if (type == "all") { word = "" };
|
if (type == "all") { word = "" };
|
||||||
if (type == "random") {
|
if (type == "random") {
|
||||||
let random = Math.floor(Math.random() * Object.keys(json).length);
|
let random = Math.floor(Math.random() * Object.keys(json).length);
|
||||||
return [Object.keys(json)[random]];
|
return [Object.keys(json)[random]];
|
||||||
}
|
}
|
||||||
console.log(word);
|
|
||||||
let words = word.split(" ");
|
let words = word.split(" ");
|
||||||
for (let i = 0; i < words.length; i++) {
|
for (let i = 0; i < words.length; i++) {
|
||||||
words[i] = stripWord(words[i]);
|
words[i] = stripWord(words[i]);
|
||||||
@@ -372,10 +379,14 @@ function doSearch(state = true) {
|
|||||||
} else {
|
} else {
|
||||||
types[json[results[i]][o]["type"]]++;
|
types[json[results[i]][o]["type"]]++;
|
||||||
}
|
}
|
||||||
//number, meaning (*required)
|
//meaning, tl, etc
|
||||||
meaning.innerHTML += "<span class='result-number'>" + (o + 1) + "</span><span class='result-big'>" + json[results[i]][o]["meaning"] + "</span>";
|
if (json[results[i]][o]["meaning"] != undefined) {
|
||||||
//longer translation (below are not required, make sure to check for them)
|
meaning.innerHTML += "<span class='result-number'>" + (o + 1) + "</span><span class='result-big'>" + escapeHTML(json[results[i]][o]["meaning"]) + "</span>";
|
||||||
if (json[results[i]][o]["translation"] != undefined && json[results[i]][o]["translation"].toLowerCase() != json[results[i]][o]["meaning"].toLowerCase()) {
|
} 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>";
|
meaning.innerHTML += "<br><span class='result-translation'>" + json[results[i]][o]["translation"] + "</span>";
|
||||||
}
|
}
|
||||||
//example
|
//example
|
||||||
@@ -427,14 +438,14 @@ function doSearch(state = true) {
|
|||||||
}
|
}
|
||||||
//notes
|
//notes
|
||||||
if (json[results[i]][o]["notes"] != undefined) {
|
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)
|
//(source, etc)
|
||||||
if (json[results[i]][o]["canon-etymology"] != undefined) {
|
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) {
|
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
|
//todo
|
||||||
result.appendChild(meaning); //y, yeah.
|
result.appendChild(meaning); //y, yeah.
|
||||||
@@ -445,20 +456,21 @@ function doSearch(state = true) {
|
|||||||
let header = document.createElement("div");
|
let header = document.createElement("div");
|
||||||
header.classList.add("results-header");
|
header.classList.add("results-header");
|
||||||
//When using search methods, accomodate search text.
|
//When using search methods, accomodate search text.
|
||||||
|
//we dont wanna actually change val, because this breaks searchParams
|
||||||
switch (type) {
|
switch (type) {
|
||||||
//show:all
|
//show:all
|
||||||
case "all":
|
case "all":
|
||||||
val = "Showing all words";
|
header.innerHTML += "<span class='heonian'>showing all words</span><br>";
|
||||||
break;
|
break;
|
||||||
case "random":
|
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;
|
break;
|
||||||
//OMG A WORD
|
//OMG A WORD
|
||||||
default:
|
default:
|
||||||
val = "search results for: " + val;
|
header.innerHTML += "<span class='heonian'>search results for: " + val + "</span><br>";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
header.innerHTML += "<span class='heonian'>" + val + "</span><br>";
|
|
||||||
for (let i in types) {
|
for (let i in types) {
|
||||||
if (i !== "") { header.innerHTML += "<span class='results-header-count'>" + i + "s - " + types[i] + "</span>"; }
|
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() {
|
async function registerSW() {
|
||||||
if ('serviceWorker' in navigator) {
|
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 => {
|
navigator.serviceWorker.register('./sw.js').then(registration => {
|
||||||
registration.onupdatefound = () => {
|
registration.onupdatefound = () => {
|
||||||
const installingWorker = registration.installing;
|
const installingWorker = registration.installing;
|
||||||
@@ -491,21 +508,11 @@ async function registerSW() {
|
|||||||
// but the previous service worker will still serve the older
|
// but the previous service worker will still serve the older
|
||||||
// content until all client tabs are closed.
|
// content until all client tabs are closed.
|
||||||
header.querySelector("#update").style.display = "block";
|
header.querySelector("#update").style.display = "block";
|
||||||
|
|
||||||
// Execute callback
|
|
||||||
if (config && config.onUpdate) {
|
|
||||||
config.onUpdate(registration);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// At this point, everything has been precached.
|
// At this point, everything has been precached.
|
||||||
// It's the perfect time to display a
|
// It's the perfect time to display a
|
||||||
// "Content is cached for offline use." message.
|
// "Content is cached for offline use." message.
|
||||||
console.log('Content is cached for offline use.');
|
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() {
|
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) {
|
navigator.serviceWorker.getRegistrations().then(function(registrations) {
|
||||||
for(let registration of registrations) {
|
for (let registration of registrations)
|
||||||
registration.unregister()
|
registration.unregister();
|
||||||
}}); //dev use only!! or whatever... i just copypasted this from SO
|
}); //dev use only!! or whatever... i just copypasted this from SO
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHTML(str){
|
||||||
|
return new Option(str).innerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = () => {
|
window.onload = () => {
|
||||||
@@ -560,8 +575,7 @@ window.onload = () => {
|
|||||||
doSearch(false);
|
doSearch(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
registerSW();
|
registerSW(); //considering disabling this for now,.... itso nly lead to trouble :////
|
||||||
//also check if ?s is there . for hecks sake (todo) (TODO!!!!!!)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortObject = obj => Object.keys(obj).sort().reduce((res, key) => (res[key] = obj[key], res), {})
|
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