From 7c9d161719cba280d6df685d1a8549427e6df340 Mon Sep 17 00:00:00 2001 From: Nathan McRae Date: Wed, 8 May 2024 20:16:39 -0700 Subject: [PATCH] Add common words back in as option Still can choose the morse shorthand --- morse-code_files/constants.js | 1444 +++++++++++++++++++++++++++----- morse-code_files/morse-code.js | 19 +- 2 files changed, 1226 insertions(+), 237 deletions(-) diff --git a/morse-code_files/constants.js b/morse-code_files/constants.js index 6a5265b..be34f30 100644 --- a/morse-code_files/constants.js +++ b/morse-code_files/constants.js @@ -51,245 +51,1225 @@ const REVERSE_MORSE_MAP = function() { return reversed; }(); - -// Thanks to https://github.com/dariusk/corpora/blob/master/data/words/common.json (CC0 license) const COMMON_WORDS = { "description": "Common English words.", "commonWords": [ - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - ".", - "?", - "!", - "=", - "+", - "-", - "QRG", - "QRI", - "QRK", - "QRL", - "QRM", - "QRN", - "QRO", - "QRP", - "QRQ", - "QRR", - "QRRR", - "QRS", - "QRT", - "QRU", - "QRV", - "QRX", - "QRZ", - "QSA", - "QSB", - "QSD", - "QSK", - "QSL", - "QSM", - "QSN", - "QSO", - "QSP", - "QST", - "QSX", - "QSY", - "QTA", - "QTC", - "QTH", - "QTR", - "AA", - "AB", - "ABT", - "ADEE", - "ADR", - "AGN", - "AM", - "ANT", - "BCI", - "BCL", - "BCNU", - "BK", - "BN", - "BT", - "BTR", - "Bug", - "C", - "CFM", - "CK", - "CKT", - "CL", - "CLBK", - "CLD", - "CLG", - "CNT", - "CONDX", - "CQ", - "CU", - "CUL", - "CUM", - "CW", - "DA", - "DE", - "DIFF", - "DLD", - "DLVD", - "DN", - "DR", - "DX", - "EL", - "ES", - "FB", - "FER", - "FM", - "GA", - "GB", - "GD", - "GE", - "GESS", - "GG", - "GM", - "GN", - "GND", - "GUD", - "GV", - "HH", - "HI", - "HR", - "HV", - "HW", - "IMI", - "LNG", - "LTR", - "LVG", - "MA", - "MILLS", - "MSG", - "N", - "NCS", - "ND", - "NM", - "NR", - "NW", - "OB", - "OC", - "OM", - "OP", - "OPR", - "OT", - "PBL", - "PKG", - "PSE", - "PT", - "PWR", - "PX", - "R", - "RC", - "RCD", - "RCVR", - "REF", - "RFI", - "RIG", - "RPT", - "RTTY", - "RST", - "RX", - "SASE", - "SED", - "SEZ", - "SGD", - "SIG", - "SINE", - "SKED", - "SRI", - "SS", - "SSB", - "STN", - "SUM", - "SVC", - "T", - "TFC", - "TMW", - "TKS", - "TNX", - "TR", - "TX", - "T/R", - "TRIX", - "TT", - "TTS", - "TU", - "TVI", - "TX", - "TXT", - "U", - "UR", - "URS", - "VFB", - "VFO", - "VY", - "W", - "WA", - "WD", - "WDS", - "WKD", - "WKG", - "WPM", - "WRD", - "WX", - "TXVR", - "XMTR", - "XTL", - "XYL", - "YF", - "YL", - "YR", - "73", - "KG7DAB", - "KF7WNR", - "K7LWA", - "W7UUL", - "KB7LTT", - "WA2AFT", - "KE7BSC", - "AB7MK", - "KF7ZZB", - "N1MNB", - "KF7YKN", - "K7IS", - "KJ7ZOL", - "N1SXY", - "KF7BMP", - "KF4ELO", - "KF7SWZ", - "K7ETA", - "KF5CZU", - "KI7MLV", - "K7TJA", - "N7GRN", - "KG7AHK", - "KG7CMP", - "KG7GWH", - "KI7HQJ", - "K7PWN", - "KI7ZEJ", - "AG7Z", - "KI7QVE", - "W1ZKY", - "KG7PKS", - "KD7NKS", - "KF7TIH" + "a", + "able", + "about", + "absolute", + "accept", + "account", + "achieve", + "across", + "act", + "active", + "actual", + "add", + "address", + "admit", + "advertise", + "affect", + "afford", + "after", + "afternoon", + "again", + "against", + "age", + "agent", + "ago", + "agree", + "air", + "all", + "allow", + "almost", + "along", + "already", + "alright", + "also", + "although", + "always", + "america", + "amount", + "and", + "another", + "answer", + "any", + "apart", + "apparent", + "appear", + "apply", + "appoint", + "approach", + "appropriate", + "area", + "argue", + "arm", + "around", + "arrange", + "art", + "as", + "ask", + "associate", + "assume", + "at", + "attend", + "authority", + "available", + "aware", + "away", + "awful", + "baby", + "back", + "bad", + "bag", + "balance", + "ball", + "bank", + "bar", + "base", + "basis", + "be", + "bear", + "beat", + "beauty", + "because", + "become", + "bed", + "before", + "begin", + "behind", + "believe", + "benefit", + "best", + "bet", + "between", + "big", + "bill", + "birth", + "bit", + "black", + "bloke", + "blood", + "blow", + "blue", + "board", + "boat", + "body", + "book", + "both", + "bother", + "bottle", + "bottom", + "box", + "boy", + "break", + "brief", + "brilliant", + "bring", + "britain", + "brother", + "budget", + "build", + "bus", + "business", + "busy", + "but", + "buy", + "by", + "cake", + "call", + "can", + "car", + "card", + "care", + "carry", + "case", + "cat", + "catch", + "cause", + "cent", + "centre", + "certain", + "chair", + "chairman", + "chance", + "change", + "chap", + "character", + "charge", + "cheap", + "check", + "child", + "choice", + "choose", + "Christmas", + "church", + "city", + "claim", + "class", + "clean", + "clear", + "client", + "clock", + "close", + "closes", + "clothe", + "club", + "coffee", + "cold", + "colleague", + "collect", + "college", + "colour", + "come", + "comment", + "commit", + "committee", + "common", + "community", + "company", + "compare", + "complete", + "compute", + "concern", + "condition", + "confer", + "consider", + "consult", + "contact", + "continue", + "contract", + "control", + "converse", + "cook", + "copy", + "corner", + "correct", + "cost", + "could", + "council", + "count", + "country", + "county", + "couple", + "course", + "court", + "cover", + "create", + "cross", + "cup", + "current", + "cut", + "dad", + "danger", + "date", + "day", + "dead", + "deal", + "dear", + "debate", + "decide", + "decision", + "deep", + "definite", + "degree", + "department", + "depend", + "describe", + "design", + "detail", + "develop", + "die", + "difference", + "difficult", + "dinner", + "direct", + "discuss", + "district", + "divide", + "do", + "doctor", + "document", + "dog", + "door", + "double", + "doubt", + "down", + "draw", + "dress", + "drink", + "drive", + "drop", + "dry", + "due", + "during", + "each", + "early", + "east", + "easy", + "eat", + "economy", + "educate", + "effect", + "egg", + "eight", + "either", + "elect", + "electric", + "eleven", + "else", + "employ", + "encourage", + "end", + "engine", + "english", + "enjoy", + "enough", + "enter", + "environment", + "equal", + "especial", + "europe", + "even", + "evening", + "ever", + "every", + "evidence", + "exact", + "example", + "except", + "excuse", + "exercise", + "exist", + "expect", + "expense", + "experience", + "explain", + "express", + "extra", + "eye", + "face", + "fact", + "fair", + "fall", + "family", + "far", + "farm", + "fast", + "father", + "favour", + "feed", + "feel", + "few", + "field", + "fight", + "figure", + "file", + "fill", + "film", + "final", + "finance", + "find", + "fine", + "finish", + "fire", + "first", + "fish", + "fit", + "five", + "flat", + "floor", + "fly", + "follow", + "food", + "foot", + "for", + "force", + "forget", + "form", + "fortune", + "forward", + "four", + "france", + "free", + "friday", + "friend", + "from", + "front", + "full", + "fun", + "function", + "fund", + "further", + "future", + "game", + "garden", + "gas", + "general", + "germany", + "get", + "girl", + "give", + "glass", + "go", + "god", + "good", + "goodbye", + "govern", + "grand", + "grant", + "great", + "green", + "ground", + "group", + "grow", + "guess", + "guy", + "hair", + "half", + "hall", + "hand", + "hang", + "happen", + "happy", + "hard", + "hate", + "have", + "he", + "head", + "health", + "hear", + "heart", + "heat", + "heavy", + "hell", + "help", + "here", + "high", + "history", + "hit", + "hold", + "holiday", + "home", + "honest", + "hope", + "horse", + "hospital", + "hot", + "hour", + "house", + "how", + "however", + "hullo", + "hundred", + "husband", + "idea", + "identify", + "if", + "imagine", + "important", + "improve", + "in", + "include", + "income", + "increase", + "indeed", + "individual", + "industry", + "inform", + "inside", + "instead", + "insure", + "interest", + "into", + "introduce", + "invest", + "involve", + "issue", + "it", + "item", + "jesus", + "job", + "join", + "judge", + "jump", + "just", + "keep", + "key", + "kid", + "kill", + "kind", + "king", + "kitchen", + "knock", + "know", + "labour", + "lad", + "lady", + "land", + "language", + "large", + "last", + "late", + "laugh", + "law", + "lay", + "lead", + "learn", + "leave", + "left", + "leg", + "less", + "let", + "letter", + "level", + "lie", + "life", + "light", + "like", + "likely", + "limit", + "line", + "link", + "list", + "listen", + "little", + "live", + "load", + "local", + "lock", + "london", + "long", + "look", + "lord", + "lose", + "lot", + "love", + "low", + "luck", + "lunch", + "machine", + "main", + "major", + "make", + "man", + "manage", + "many", + "mark", + "market", + "marry", + "match", + "matter", + "may", + "maybe", + "mean", + "meaning", + "measure", + "meet", + "member", + "mention", + "middle", + "might", + "mile", + "milk", + "million", + "mind", + "minister", + "minus", + "minute", + "miss", + "mister", + "moment", + "monday", + "money", + "month", + "more", + "morning", + "most", + "mother", + "motion", + "move", + "mrs", + "much", + "music", + "must", + "name", + "nation", + "nature", + "near", + "necessary", + "need", + "never", + "new", + "news", + "next", + "nice", + "night", + "nine", + "no", + "non", + "none", + "normal", + "north", + "not", + "note", + "notice", + "now", + "number", + "obvious", + "occasion", + "odd", + "of", + "off", + "offer", + "office", + "often", + "okay", + "old", + "on", + "once", + "one", + "only", + "open", + "operate", + "opportunity", + "oppose", + "or", + "order", + "organize", + "original", + "other", + "otherwise", + "ought", + "out", + "over", + "own", + "pack", + "page", + "paint", + "pair", + "paper", + "paragraph", + "pardon", + "parent", + "park", + "part", + "particular", + "party", + "pass", + "past", + "pay", + "pence", + "pension", + "people", + "per", + "percent", + "perfect", + "perhaps", + "period", + "person", + "photograph", + "pick", + "picture", + "piece", + "place", + "plan", + "play", + "please", + "plus", + "point", + "police", + "policy", + "politic", + "poor", + "position", + "positive", + "possible", + "post", + "pound", + "power", + "practise", + "prepare", + "present", + "press", + "pressure", + "presume", + "pretty", + "previous", + "price", + "print", + "private", + "probable", + "problem", + "proceed", + "process", + "produce", + "product", + "programme", + "project", + "proper", + "propose", + "protect", + "provide", + "public", + "pull", + "purpose", + "push", + "put", + "quality", + "quarter", + "question", + "quick", + "quid", + "quiet", + "quite", + "radio", + "rail", + "raise", + "range", + "rate", + "rather", + "read", + "ready", + "real", + "realise", + "really", + "reason", + "receive", + "recent", + "reckon", + "recognize", + "recommend", + "record", + "red", + "reduce", + "refer", + "regard", + "region", + "relation", + "remember", + "report", + "represent", + "require", + "research", + "resource", + "respect", + "responsible", + "rest", + "result", + "return", + "rid", + "right", + "ring", + "rise", + "road", + "role", + "roll", + "room", + "round", + "rule", + "run", + "safe", + "sale", + "same", + "saturday", + "save", + "say", + "scheme", + "school", + "science", + "score", + "scotland", + "seat", + "second", + "secretary", + "section", + "secure", + "see", + "seem", + "self", + "sell", + "send", + "sense", + "separate", + "serious", + "serve", + "service", + "set", + "settle", + "seven", + "shall", + "share", + "she", + "sheet", + "shoe", + "shoot", + "shop", + "short", + "should", + "show", + "shut", + "sick", + "side", + "sign", + "similar", + "simple", + "since", + "sing", + "single", + "sir", + "sister", + "sit", + "site", + "situate", + "six", + "size", + "sleep", + "slight", + "slow", + "small", + "smoke", + "so", + "social", + "society", + "some", + "son", + "soon", + "sorry", + "sort", + "sound", + "south", + "space", + "speak", + "special", + "specific", + "speed", + "spell", + "spend", + "square", + "staff", + "stage", + "stairs", + "stand", + "standard", + "start", + "state", + "station", + "stay", + "step", + "stick", + "still", + "stop", + "story", + "straight", + "strategy", + "street", + "strike", + "strong", + "structure", + "student", + "study", + "stuff", + "stupid", + "subject", + "succeed", + "such", + "sudden", + "suggest", + "suit", + "summer", + "sun", + "sunday", + "supply", + "support", + "suppose", + "sure", + "surprise", + "switch", + "system", + "table", + "take", + "talk", + "tape", + "tax", + "tea", + "teach", + "team", + "telephone", + "television", + "tell", + "ten", + "tend", + "term", + "terrible", + "test", + "than", + "thank", + "the", + "then", + "there", + "therefore", + "they", + "thing", + "think", + "thirteen", + "thirty", + "this", + "thou", + "though", + "thousand", + "three", + "through", + "throw", + "thursday", + "tie", + "time", + "to", + "today", + "together", + "tomorrow", + "tonight", + "too", + "top", + "total", + "touch", + "toward", + "town", + "trade", + "traffic", + "train", + "transport", + "travel", + "treat", + "tree", + "trouble", + "true", + "trust", + "try", + "tuesday", + "turn", + "twelve", + "twenty", + "two", + "type", + "under", + "understand", + "union", + "unit", + "unite", + "university", + "unless", + "until", + "up", + "upon", + "use", + "usual", + "value", + "various", + "very", + "video", + "view", + "village", + "visit", + "vote", + "wage", + "wait", + "walk", + "wall", + "want", + "war", + "warm", + "wash", + "waste", + "watch", + "water", + "way", + "we", + "wear", + "wednesday", + "wee", + "week", + "weigh", + "welcome", + "well", + "west", + "what", + "when", + "where", + "whether", + "which", + "while", + "white", + "who", + "whole", + "why", + "wide", + "wife", + "will", + "win", + "wind", + "window", + "wish", + "with", + "within", + "without", + "woman", + "wonder", + "wood", + "word", + "work", + "world", + "worry", + "worse", + "worth", + "would", + "write", + "wrong", + "year", + "yes", + "yesterday", + "yet", + "you", + "young" ] }; +// Thanks to https://github.com/dariusk/corpora/blob/master/data/words/common.json (CC0 license) +const MORSE_WORDS = [ + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + ".", + "?", + "!", + "=", + "+", + "-", + "QRG", + "QRI", + "QRK", + "QRL", + "QRM", + "QRN", + "QRO", + "QRP", + "QRQ", + "QRR", + "QRRR", + "QRS", + "QRT", + "QRU", + "QRV", + "QRX", + "QRZ", + "QSA", + "QSB", + "QSD", + "QSK", + "QSL", + "QSM", + "QSN", + "QSO", + "QSP", + "QST", + "QSX", + "QSY", + "QTA", + "QTC", + "QTH", + "QTR", + "AA", + "AB", + "ABT", + "ADEE", + "ADR", + "AGN", + "AM", + "ANT", + "BCI", + "BCL", + "BCNU", + "BK", + "BN", + "BT", + "BTR", + "Bug", + "C", + "CFM", + "CK", + "CKT", + "CL", + "CLBK", + "CLD", + "CLG", + "CNT", + "CONDX", + "CQ", + "CU", + "CUL", + "CUM", + "CW", + "DA", + "DE", + "DIFF", + "DLD", + "DLVD", + "DN", + "DR", + "DX", + "EL", + "ES", + "FB", + "FER", + "FM", + "GA", + "GB", + "GD", + "GE", + "GESS", + "GG", + "GM", + "GN", + "GND", + "GUD", + "GV", + "HH", + "HI", + "HR", + "HV", + "HW", + "IMI", + "LNG", + "LTR", + "LVG", + "MA", + "MILLS", + "MSG", + "N", + "NCS", + "ND", + "NM", + "NR", + "NW", + "OB", + "OC", + "OM", + "OP", + "OPR", + "OT", + "PBL", + "PKG", + "PSE", + "PT", + "PWR", + "PX", + "R", + "RC", + "RCD", + "RCVR", + "REF", + "RFI", + "RIG", + "RPT", + "RTTY", + "RST", + "RX", + "SASE", + "SED", + "SEZ", + "SGD", + "SIG", + "SINE", + "SKED", + "SRI", + "SS", + "SSB", + "STN", + "SUM", + "SVC", + "T", + "TFC", + "TMW", + "TKS", + "TNX", + "TR", + "TX", + "T/R", + "TRIX", + "TT", + "TTS", + "TU", + "TVI", + "TX", + "TXT", + "U", + "UR", + "URS", + "VFB", + "VFO", + "VY", + "W", + "WA", + "WD", + "WDS", + "WKD", + "WKG", + "WPM", + "WRD", + "WX", + "TXVR", + "XMTR", + "XTL", + "XYL", + "YF", + "YL", + "YR", + "73", + "KG7DAB", + "KF7WNR", + "K7LWA", + "W7UUL", + "KB7LTT", + "WA2AFT", + "KE7BSC", + "AB7MK", + "KF7ZZB", + "N1MNB", + "KF7YKN", + "K7IS", + "KJ7ZOL", + "N1SXY", + "KF7BMP", + "KF4ELO", + "KF7SWZ", + "K7ETA", + "KF5CZU", + "KI7MLV", + "K7TJA", + "N7GRN", + "KG7AHK", + "KG7CMP", + "KG7GWH", + "KI7HQJ", + "K7PWN", + "KI7ZEJ", + "AG7Z", + "KI7QVE", + "W1ZKY", + "KG7PKS", + "KD7NKS", + "KF7TIH" +]; + const ALL_WORDS = COMMON_WORDS.commonWords; const EASY_WORDS = COMMON_WORDS.commonWords.filter(word => word.length < 5); diff --git a/morse-code_files/morse-code.js b/morse-code_files/morse-code.js index 102f200..5366543 100644 --- a/morse-code_files/morse-code.js +++ b/morse-code_files/morse-code.js @@ -39,8 +39,6 @@ function stopNotePlaying() { $("#beepLamp").removeClass("lamp-on") } - - function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -137,6 +135,11 @@ function getRandomWord() { return EASY_WORDS[randomIndex]; } +function getRandomMorseWord() { + const randomIndex = Math.floor(Math.random() * MORSE_WORDS.length); + return MORSE_WORDS[randomIndex]; +} + function getRandomEasyWords() { const totalLength = Math.floor(Math.random() * 3) + 2; let finalSentence = '' @@ -149,11 +152,11 @@ function getRandomEasyWords() { return finalSentence; } -function getRandomWords() { +function getRandomMorseWords() { const totalLength = Math.floor(Math.random() * 4) + 2; let finalSentence = '' for (let i = 0; i < totalLength; i++) { - finalSentence += ALL_WORDS[Math.floor(Math.random() * ALL_WORDS.length)]; + finalSentence += MORSE_WORDS[Math.floor(Math.random() * MORSE_WORDS.length)]; if (i < totalLength - 1) { finalSentence += ' '; } @@ -222,6 +225,12 @@ function getTarget() { case 'hard': target = getRandomEasyWords(); break; + case 'morse-easy': + target = getRandomMorseWord(); + break; + case 'morse-hard': + target = getRandomMorseWords(); + break; default: target = getRandomWords(); break; @@ -679,4 +688,4 @@ var initializeAudioOnTouch = function() { } document.removeEventListener('touchend', initializeAudioOnTouch); } -document.addEventListener('touchend', initializeAudioOnTouch); \ No newline at end of file +document.addEventListener('touchend', initializeAudioOnTouch);