From fb6484b5ff75609a15b0c69f713d16dc3c2594e9 Mon Sep 17 00:00:00 2001 From: Miodec Date: Sun, 17 Jan 2021 00:54:17 +0000 Subject: [PATCH] made sure that a quote is always found if all length is selected, otherwise showing that no quote was found for that length --- src/js/script.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/js/script.js b/src/js/script.js index 4456d1a55..ba89c8f18 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -471,6 +471,9 @@ async function initWords() { success: function (data) { hideBackgroundLoader(); try { + if (data.quotes.length === 0) { + throw new Error("No quotes"); + } quotes = data; quotes.groups.forEach((qg, i) => { let lower = qg[0]; @@ -643,6 +646,14 @@ async function initWords() { if (config.quoteLength === -1) { group = Math.floor(Math.random() * quotes.groups.length); + while (quotes.groups[group].length === 0) { + group = Math.floor(Math.random() * quotes.groups.length); + } + } else { + if (quotes.groups[group].length === 0) { + Notifications.add("No quotes found for selected quote length", 0); + return; + } } let rq =