From eecd5043f679361c2db69688cc400d7ae0a630ae Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 24 Jan 2022 10:28:11 +0800 Subject: [PATCH] limit query words to list --- src/words.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/words.ts b/src/words.ts index 3defd9d..995f525 100644 --- a/src/words.ts +++ b/src/words.ts @@ -1,14 +1,18 @@ +const defaultMessage = ' Using word of the day instead.' + export function getWordOfTheDay() { if (location.search) { try { - const query = atob(location.search.slice(1)) - if (query.length !== 5) { - alert('incorrect word length from encoded query.') - } else { - return query - } + const query = atob(location.search.slice(1)) + if (query.length !== 5) { + alert(`Incorrect word length from encoded query. ${defaultMessage}`) + } else if (!allWords.includes(query)) { + alert(`Encoded query is not in the word list. ${defaultMessage}`) + } else { + return query + } } catch (e) { - alert('malformed encoded word query.') + alert(`Malformed encoded word query. ${defaultMessage}`) } }