uncrash everything on pressing all
This commit is contained in:
parent
132e49b589
commit
30b3cf0d0a
@ -1 +1 @@
|
||||
Subproject commit 1222e87853bbd79540ca1d8a91602b619131644b
|
||||
Subproject commit 08c759451d133ea8009ef89a6aec7b0def82a1f5
|
22
main.js
22
main.js
@ -216,6 +216,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]] = [];
|
||||
|
||||
@ -250,13 +251,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]);
|
||||
@ -375,9 +374,11 @@ function doSearch(state = true) {
|
||||
//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()) {
|
||||
if (json[results[i]][o]["translation"] != undefined) {
|
||||
if (json[results[i]][o]["meaning"] != 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>";
|
||||
}
|
||||
}
|
||||
//example
|
||||
if (json[results[i]][o]["examples"] != undefined) {
|
||||
let temp = ""
|
||||
@ -478,6 +479,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 +497,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user