├── .prettierignore ├── .gitignore ├── src ├── favicon.ico ├── apple-touch-icon.png ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── streamlined_screenshot.png ├── wordEnums.js ├── site.webmanifest ├── utils.js ├── wordData.js ├── style.css ├── index.html ├── settingManagement.js └── main.js ├── .parcelrc ├── README.md ├── package.json ├── .vscode └── launch.json └── LICENSE /.prettierignore: -------------------------------------------------------------------------------- 1 | wordData.js -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | /hot-reload-temp 4 | /.parcel-cache -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baileysnyder/japanese-conjugation/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /.parcelrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@parcel/config-default", 3 | "optimizers": { 4 | "*.html": [] 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baileysnyder/japanese-conjugation/HEAD/src/apple-touch-icon.png -------------------------------------------------------------------------------- /src/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baileysnyder/japanese-conjugation/HEAD/src/android-chrome-192x192.png -------------------------------------------------------------------------------- /src/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baileysnyder/japanese-conjugation/HEAD/src/android-chrome-512x512.png -------------------------------------------------------------------------------- /src/streamlined_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baileysnyder/japanese-conjugation/HEAD/src/streamlined_screenshot.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Japanese Conjugation Practice 2 | A web app for practicing Japanese verb and adjective conjugations with basic spaced repition. URL: http://baileysnyder.com/jconj/ 3 | 4 | ## Build Setup 5 | ```bash 6 | # install dependencies 7 | $ npm install 8 | 9 | # serve with hot reload at localhost:1234 10 | $ npm run dev 11 | 12 | # build for production 13 | # minifies and outputs into /dist 14 | $ npm run build 15 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "wanakana": "^5.0.2" 4 | }, 5 | "devDependencies": { 6 | "@parcel/packager-raw-url": "^2.12.0", 7 | "@parcel/transformer-webmanifest": "^2.12.0", 8 | "parcel": "^2.12.0" 9 | }, 10 | "source": "src/index.html", 11 | "scripts": { 12 | "dev": "parcel --dist-dir ./hot-reload-temp", 13 | "build": "parcel build --dist-dir ./dist --no-source-maps --public-url ./" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/wordEnums.js: -------------------------------------------------------------------------------- 1 | export const PARTS_OF_SPEECH = Object.freeze({ 2 | verb: "verb", 3 | adjective: "adjective", 4 | }); 5 | 6 | export const CONJUGATION_TYPES = Object.freeze({ 7 | present: "Present", 8 | past: "Past", 9 | te: "て-form", 10 | adverb: "Adverb", 11 | volitional: "Volitional", 12 | passive: "Passive", 13 | causative: "Causative", 14 | potential: "Potential", 15 | imperative: "Imperative", 16 | causativePassive: "Causative-Passive", 17 | }); 18 | -------------------------------------------------------------------------------- /src/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Japanese Conjugation Practice", 3 | "icons": [ 4 | { 5 | "src": "./android-chrome-192x192.png", 6 | "sizes": "192x192", 7 | "type": "image/png" 8 | }, 9 | { 10 | "src": "./android-chrome-512x512.png", 11 | "sizes": "512x512", 12 | "type": "image/png" 13 | } 14 | ], 15 | "start_url": "https://baileysnyder.com/jconj/", 16 | "theme_color": "#22221f", 17 | "background_color": "#22221f", 18 | "display": "standalone" 19 | } 20 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | export function toggleDisplayNone(element, isDisplayNone) { 2 | toggleClassName(element, "display-none", isDisplayNone); 3 | } 4 | 5 | export function toggleBackgroundNone(element, isBackgroundNone) { 6 | toggleClassName(element, "background-none", isBackgroundNone); 7 | } 8 | 9 | function toggleClassName(element, className, enabled) { 10 | if (enabled) { 11 | element.classList.add(className); 12 | } else { 13 | element.classList.remove(className); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch Chrome against localhost", 9 | "type": "chrome", 10 | "request": "launch", 11 | "url": "http://localhost:1234", 12 | "webRoot": "${workspaceFolder}", 13 | "sourceMapPathOverrides": { 14 | "/__parcel_source_root/*": "${webRoot}/*" 15 | }, 16 | }, 17 | { 18 | "name": "Launch Microsoft Edge against localhost", 19 | "type": "msedge", 20 | "request": "launch", 21 | "url": "http://localhost:1234", 22 | "webRoot": "${workspaceFolder}", 23 | "sourceMapPathOverrides": { 24 | "/__parcel_source_root/*": "${webRoot}/*" 25 | }, 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /src/wordData.js: -------------------------------------------------------------------------------- 1 | export const wordData = { 2 | "verbs": [ 3 | {"kanji":"い<\/rt><\/ruby>く","type":"irv","eng":"go", "group": "iku"}, 4 | {"kanji":"する","type":"irv","eng":"do, make", "group": "suru"}, 5 | {"kanji":"く<\/rt><\/ruby>る","type":"irv","eng":"come"}, 6 | {"kanji":"ある","type":"irv","eng":"have, exists, is (inanimate)"}, 7 | {"kanji":"と<\/rt><\/ruby>う","type":"irv","eng":"ask, accuse"}, 8 | {"kanji":"いる","type":"ru","eng":"exists, is (living things)"}, 9 | {"kanji":"はじ<\/rt><\/ruby>める","type":"ru","eng":"begin"}, 10 | {"kanji":"か<\/rt><\/ruby>りる","type":"ru","eng":"borrow, rent"}, 11 | {"kanji":"つづ<\/rt><\/ruby>ける","type":"ru","eng":"continue, proceed"}, 12 | {"kanji":"き<\/rt><\/ruby>める","type":"ru","eng":"decide, choose"}, 13 | {"kanji":"た<\/rt><\/ruby>べる","type":"ru","eng":"eat"}, 14 | {"kanji":"わす<\/rt><\/ruby>れる","type":"ru","eng":"forget"}, 15 | {"kanji":"お<\/rt><\/ruby>りる","type":"ru","eng":"get off, go down"}, 16 | {"kanji":"つか<\/rt><\/ruby>れる","type":"ru","eng":"get tired"}, 17 | {"kanji":"お<\/rt><\/ruby>きる","type":"ru","eng":"get up, wake up"}, 18 | {"kanji":"あげる","type":"ru","eng":"give"}, 19 | {"kanji":"で<\/rt><\/ruby>る","type":"ru","eng":"leave, exit, appear"}, 20 | {"kanji":"たす<\/rt><\/ruby>ける","type":"ru","eng":"help"}, 21 | {"kanji":"み<\/rt><\/ruby>る","type":"ru","eng":"see, look"}, 22 | {"kanji":"あ<\/rt><\/ruby>ける","type":"ru","eng":"open"}, 23 | {"kanji":"おぼ<\/rt><\/ruby>える","type":"ru","eng":"remember, learn"}, 24 | {"kanji":"ね<\/rt><\/ruby>る","type":"ru","eng":"sleep, go to bed"}, 25 | {"kanji":"し<\/rt><\/ruby>める","type":"ru","eng":"close"}, 26 | {"kanji":"き<\/rt><\/ruby>る","type":"ru","eng":"put on, wear (shirt, jacket, etc)"}, 27 | {"kanji":"なる","type":"u","eng":"become"}, 28 | {"kanji":"の<\/rt><\/ruby>る","type":"u","eng":"board, ride"}, 29 | {"kanji":"き<\/rt><\/ruby>る","type":"u","eng":"cut"}, 30 | {"kanji":"やる","type":"u","eng":"do, give"}, 31 | {"kanji":"お<\/rt><\/ruby>わる","type":"u","eng":"end"}, 32 | {"kanji":"あ<\/rt><\/ruby>がる","type":"u","eng":"go up, rise","altOkurigana":["上る"]}, 33 | {"kanji":"し<\/rt><\/ruby>る","type":"u","eng":"know"}, 34 | {"kanji":"つく<\/rt><\/ruby>る","type":"u","eng":"make, build"}, 35 | {"kanji":"かえ<\/rt><\/ruby>る","type":"u","eng":"return, go home"}, 36 | {"kanji":"と<\/rt><\/ruby>る","type":"u","eng":"take, steal"}, 37 | {"kanji":"か<\/rt><\/ruby>う","type":"u","eng":"buy"}, 38 | {"kanji":"わら<\/rt><\/ruby>う","type":"u","eng":"laugh, smile"}, 39 | {"kanji":"あ<\/rt><\/ruby>う","type":"u","eng":"meet"}, 40 | {"kanji":"い<\/rt><\/ruby>う","type":"u","eng":"say, utter"}, 41 | {"kanji":"おも<\/rt><\/ruby>う","type":"u","eng":"think, believe"}, 42 | {"kanji":"使つか<\/rt><\/ruby>う","type":"u","eng":"use"}, 43 | {"kanji":"も<\/rt><\/ruby>つ","type":"u","eng":"hold, have"}, 44 | {"kanji":"ま<\/rt><\/ruby>つ","type":"u","eng":"wait"}, 45 | {"kanji":"た<\/rt><\/ruby>つ","type":"u","eng":"stand up"}, 46 | {"kanji":"き<\/rt><\/ruby>く","type":"u","eng":"hear, listen"}, 47 | {"kanji":"ひ<\/rt><\/ruby>く","type":"u","eng":"pull, tug"}, 48 | {"kanji":"は<\/rt><\/ruby>く","type":"u","eng":"put on, wear (pants, skirt, shoes, etc)"}, 49 | {"kanji":"ある<\/rt><\/ruby>く","type":"u","eng":"walk"}, 50 | {"kanji":"か<\/rt><\/ruby>く","type":"u","eng":"write"}, 51 | {"kanji":"はたら<\/rt><\/ruby>く","type":"u","eng":"work"}, 52 | {"kanji":"し<\/rt><\/ruby>ぬ","type":"u","eng":"die, pass away"}, 53 | {"kanji":"の<\/rt><\/ruby>む","type":"u","eng":"drink"}, 54 | {"kanji":"たの<\/rt><\/ruby>しむ","type":"u","eng":"enjoy, have fun"}, 55 | {"kanji":"すす<\/rt><\/ruby>む","type":"u","eng":"advance, go forward"}, 56 | {"kanji":"す<\/rt><\/ruby>む","type":"u","eng":"live, inhabit"}, 57 | {"kanji":"よ<\/rt><\/ruby>む","type":"u","eng":"read"}, 58 | {"kanji":"やす<\/rt><\/ruby>む","type":"u","eng":"rest, be absent"}, 59 | {"kanji":"あそ<\/rt><\/ruby>ぶ","type":"u","eng":"play, have a good time"}, 60 | {"kanji":"まな<\/rt><\/ruby>ぶ","type":"u","eng":"study, learn"}, 61 | {"kanji":"えら<\/rt><\/ruby>ぶ","type":"u","eng":"choose, select"}, 62 | {"kanji":"かえ<\/rt><\/ruby>す","type":"u","eng":"return (something), put back"}, 63 | {"kanji":"お<\/rt><\/ruby>す","type":"u","eng":"push, press"}, 64 | {"kanji":"なお<\/rt><\/ruby>す","type":"u","eng":"cure, repair"}, 65 | {"kanji":"はな<\/rt><\/ruby>す","type":"u","eng":"talk, speak"}, 66 | {"kanji":"さが<\/rt><\/ruby>す","type":"u","eng":"search, look for"}, 67 | {"kanji":"か<\/rt><\/ruby>す","type":"u","eng":"lend, loan"}, 68 | {"kanji":"およ<\/rt><\/ruby>ぐ","type":"u","eng":"swim"}, 69 | {"kanji":"ぬ<\/rt><\/ruby>ぐ","type":"u","eng":"take off clothes, undress"}, 70 | {"kanji":"いそ<\/rt><\/ruby>ぐ","type":"u","eng":"hurry"}, 71 | {"kanji":"かせ<\/rt><\/ruby>ぐ","type":"u","eng":"earn income, make money"}, 72 | {"kanji":"くつろ<\/rt><\/ruby>ぐ","type":"u","eng":"relax, feel at home"}, 73 | {"kanji":"つな<\/rt><\/ruby>ぐ","type":"u","eng":"connect, link together"}, 74 | {"kanji":"わ<\/rt><\/ruby>かる","type":"u","eng":"understand"}, 75 | {"kanji":"べん<\/rt><\/ruby>きょう<\/rt><\/ruby>する","type":"irv","eng":"study", "group": "suru"}, 76 | {"kanji":"う<\/rt><\/ruby>けも<\/rt><\/ruby>つ","type":"u","eng":"take charge of"}, 77 | {"kanji":"も<\/rt><\/ruby>ってい<\/rt><\/ruby>く","type":"irv","eng":"take, carry away", "group": "iku"}, 78 | {"kanji":"た<\/rt><\/ruby>べある<\/rt><\/ruby>く","type":"u","eng":"try food at various restaurants"} 79 | ], 80 | "adjectives": [ 81 | {"kanji":"いい","type":"ira","eng":"good"}, 82 | {"kanji":"かっこいい","type":"ira","eng":"cool, handsome"}, 83 | {"kanji":"あか<\/rt><\/ruby>い","type":"i","eng":"red"}, 84 | {"kanji":"あたら<\/rt><\/ruby>しい","type":"i","eng":"new"}, 85 | {"kanji":"あつ<\/rt><\/ruby>い","type":"i","eng":"hot (weather)"}, 86 | {"kanji":"あぶ<\/rt><\/ruby>ない","type":"i","eng":"dangerous"}, 87 | {"kanji":"お<\/rt><\/ruby>い<\/rt><\/ruby>しい","type":"i","eng":"delicious"}, 88 | {"kanji":"おお<\/rt><\/ruby>きい","type":"i","eng":"big"}, 89 | {"kanji":"おそ<\/rt><\/ruby>い","type":"i","eng":"late, slow"}, 90 | {"kanji":"おも<\/rt><\/ruby>しろ<\/rt><\/ruby>い","type":"i","eng":"interesting, funny"}, 91 | {"kanji":"か<\/rt><\/ruby>わい<\/rt><\/ruby>い","type":"i","eng":"cute, pretty"}, 92 | {"kanji":"さむ<\/rt><\/ruby>い","type":"i","eng":"cold (weather)"}, 93 | {"kanji":"たか<\/rt><\/ruby>い","type":"i","eng":"high, expensive"}, 94 | {"kanji":"たの<\/rt><\/ruby>しい","type":"i","eng":"fun, pleasant"}, 95 | {"kanji":"ちい<\/rt><\/ruby>さい","type":"i","eng":"small"}, 96 | {"kanji":"つま<\/rt><\/ruby>らない","type":"i","eng":"uninteresting, boring","altOkurigana":["詰まらない"]}, 97 | {"kanji":"はや<\/rt><\/ruby>い","type":"i","eng":"fast, quick"}, 98 | {"kanji":"ふる<\/rt><\/ruby>い","type":"i","eng":"old (thing)"}, 99 | {"kanji":"ほ<\/rt><\/ruby>しい","type":"i","eng":"wanted, desired"}, 100 | {"kanji":"むずか<\/rt><\/ruby>しい","type":"i","eng":"difficult"}, 101 | {"kanji":"やす<\/rt><\/ruby>い","type":"i","eng":"cheap"}, 102 | {"kanji":"す<\/rt><\/ruby>き","type":"na","eng":"like"}, 103 | {"kanji":"ゆう<\/rt><\/ruby>めい<\/rt><\/ruby>","type":"na","eng":"famous"}, 104 | {"kanji":"きれい","type":"na","eng":"beautiful, tidy"}, 105 | {"kanji":"きら<\/rt><\/ruby>い","type":"na","eng":"dislike"}, 106 | {"kanji":"しず<\/rt><\/ruby>か","type":"na","eng":"quiet"}, 107 | {"kanji":"げん<\/rt><\/ruby>き<\/rt><\/ruby>","type":"na","eng":"healthy"}, 108 | {"kanji":"いろ<\/rt><\/ruby>いろ<\/rt><\/ruby>","type":"na","eng":"various"}, 109 | {"kanji":"しん<\/rt><\/ruby>ぱい<\/rt><\/ruby>","type":"na","eng":"worry, care"}, 110 | {"kanji":"いや<\/rt><\/ruby>","type":"na","eng":"unpleasant, detestable"}, 111 | {"kanji":"じゅう<\/rt><\/ruby>ぶん<\/rt><\/ruby>","type":"na","eng":"sufficient"}, 112 | {"kanji":"りっ<\/rt><\/ruby>ぱ<\/rt><\/ruby>","type":"na","eng":"excellent, splendid"}, 113 | {"kanji":"おな<\/rt><\/ruby>じ","type":"na","eng":"same, alike"}, 114 | {"kanji":"だい<\/rt><\/ruby>じょう<\/rt><\/ruby>ぶ<\/rt><\/ruby>","type":"na","eng":"okay, safe"}, 115 | {"kanji":"ま<\/rt><\/ruby>っす<\/rt><\/ruby>ぐ","type":"na","eng":"straight, direct","altOkurigana":["真直ぐ","真すぐ","真っすぐ"]}, 116 | {"kanji":"へ<\/rt><\/ruby>た<\/rt><\/ruby>","type":"na","eng":"unskilled"}, 117 | {"kanji":"かん<\/rt><\/ruby>たん<\/rt><\/ruby>","type":"na","eng":"simple, easy"}, 118 | {"kanji":"らく<\/rt><\/ruby>","type":"na","eng":"comfortable, easy"}, 119 | {"kanji":"ざん<\/rt><\/ruby>ねん<\/rt><\/ruby>","type":"na","eng":"unfortunate, disappointing"}, 120 | {"kanji":"ひつ<\/rt><\/ruby>よう<\/rt><\/ruby>","type":"na","eng":"necessary"} 121 | ] 122 | } -------------------------------------------------------------------------------- /src/style.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-family: "Open Sans", "Arial", sans-serif; 3 | font-size: 17px; 4 | } 5 | 6 | body { 7 | background: rgb(34, 34, 31); 8 | --whiteTextColor: rgb(232, 232, 232); 9 | margin: 0; 10 | } 11 | 12 | h1 { 13 | text-align: center; 14 | color: var(--whiteTextColor); 15 | font-size: 1.1rem; 16 | margin-bottom: 0; 17 | margin-top: 0.6rem; 18 | /* Hide the title on mobile displays */ 19 | display: none; 20 | } 21 | 22 | p { 23 | text-align: center; 24 | color: var(--whiteTextColor); 25 | } 26 | 27 | a { 28 | color: #ffc439; 29 | } 30 | 31 | input { 32 | accent-color: #6e6e6e; 33 | } 34 | 35 | input[type="checkbox"], 36 | input[type="radio"], 37 | input[type="checkbox"] + label, 38 | input[type="radio"] + label { 39 | cursor: pointer; 40 | } 41 | 42 | .streak p { 43 | margin: 0; 44 | margin-bottom: 0; 45 | font-size: 0.65rem; 46 | } 47 | 48 | #current-streak { 49 | left: 0.23rem; 50 | float: left; 51 | } 52 | 53 | #current-streak-text, 54 | #max-streak-text { 55 | margin: 0; 56 | font-size: 1rem; 57 | } 58 | 59 | .grow-animation { 60 | animation: grow-animation 0.5s; 61 | } 62 | 63 | @keyframes grow-animation { 64 | from { 65 | transform: scale(1.7); 66 | } 67 | to { 68 | transform: scale(1); 69 | } 70 | } 71 | 72 | #max-streak { 73 | right: 0.23rem; 74 | float: right; 75 | } 76 | 77 | #toppest-container { 78 | margin: auto; 79 | } 80 | 81 | #top-container { 82 | margin: 0.6rem; 83 | border-radius: 0.64rem; 84 | padding: 0.6rem; 85 | padding-top: 0.35rem; 86 | padding-bottom: 0.35rem; 87 | box-shadow: 0.3rem 0.3rem 0.36rem rgb(28, 28, 28); 88 | background: rgb(44, 43, 41); 89 | } 90 | 91 | #streak-container:after, 92 | #settings-child-container:after { 93 | content: ""; 94 | display: table; 95 | clear: both; 96 | } 97 | 98 | #streak-container { 99 | padding: 0.4rem; 100 | padding-top: 0.3rem; 101 | } 102 | 103 | #verb-box { 104 | display: inline-block; 105 | padding: 0.45rem; 106 | border-radius: 1.14rem; 107 | /* Using position relative because setting negative margins caused alignment to rely on streak text above*/ 108 | position: relative; 109 | } 110 | 111 | #verb-box p { 112 | margin-left: 1.18rem; 113 | margin-right: 1.18rem; 114 | } 115 | 116 | #verb-container { 117 | text-align: center; 118 | } 119 | 120 | #verb-text { 121 | font-size: 2.2rem; 122 | margin-top: 0; 123 | margin-bottom: 0.25rem; 124 | 125 | display: flex; 126 | line-height: 1; 127 | align-items: flex-end; 128 | justify-content: center; 129 | } 130 | 131 | ruby { 132 | display: inline-flex; 133 | flex-direction: column-reverse; 134 | } 135 | 136 | span.rt { 137 | line-height: 1; 138 | font-size: 0.5em; 139 | } 140 | 141 | #translation { 142 | font-size: 0.8rem; 143 | margin-top: 0; 144 | margin-bottom: 0.18rem; 145 | } 146 | 147 | #verb-type { 148 | line-height: 1; 149 | font-size: 0.8rem; 150 | margin-top: 0.6rem; 151 | margin-bottom: 0.15rem; 152 | } 153 | 154 | #conjugation-inquery-text { 155 | font-size: 1.3rem; 156 | margin-top: 0.8rem; 157 | margin-bottom: 0.5rem; 158 | } 159 | 160 | #status-container { 161 | text-align: center; 162 | min-height: 4rem; 163 | } 164 | 165 | #status-box { 166 | display: inline-flex; 167 | background: green; 168 | border-radius: 0.91rem; 169 | min-width: 66%; 170 | min-height: 4rem; 171 | justify-content: center; 172 | flex-direction: column; 173 | } 174 | 175 | #status-text { 176 | line-height: 1.5; 177 | vertical-align: middle; 178 | font-size: 1.09rem; 179 | color: white; 180 | margin-left: 0.8rem; 181 | margin-right: 0.8rem; 182 | margin-top: 0.3rem; 183 | margin-bottom: 0.3rem; 184 | } 185 | 186 | .sub-conjugation-indicator { 187 | font-size: 0.8rem; 188 | display: inline-block; 189 | padding-left: 0.3rem; 190 | } 191 | 192 | #input-container { 193 | text-align: center; 194 | padding-top: 0.36rem; 195 | margin: 0.45rem; 196 | position: relative; 197 | margin-bottom: 0.3rem; 198 | } 199 | 200 | .tooltip-fade-animation { 201 | animation: tooltip-fade-animation 6s; 202 | } 203 | 204 | @keyframes tooltip-fade-animation { 205 | 0% { 206 | opacity: 0; 207 | } 208 | 6% { 209 | opacity: 1; 210 | } 211 | 80% { 212 | opacity: 1; 213 | } 214 | 100% { 215 | opacity: 0; 216 | } 217 | } 218 | 219 | .tooltip { 220 | position: absolute; 221 | font-size: 0.66rem; 222 | color: white; 223 | background: red; 224 | border-radius: 0.3rem; 225 | padding: 0 0.4rem; 226 | bottom: 100%; 227 | left: 7%; 228 | 229 | opacity: 0; 230 | } 231 | 232 | .tooltip::after { 233 | content: ""; 234 | position: absolute; 235 | top: 100%; 236 | left: 14%; 237 | margin-left: -5px; 238 | border-width: 5px; 239 | border-style: solid; 240 | border-color: red transparent transparent transparent; 241 | } 242 | 243 | #main-text-input, 244 | #settings-child-container { 245 | width: 88%; 246 | } 247 | 248 | #main-text-input { 249 | border-radius: 5rem; 250 | font-size: 1rem; 251 | border: 0.068rem; 252 | background: white; 253 | padding-top: 0.27rem; 254 | padding-bottom: 0.18rem; 255 | padding-left: 0.45rem; 256 | padding-right: 0.45rem; 257 | } 258 | 259 | #main-text-input:hover:not(:focus):not(:disabled) { 260 | background: rgb(224, 224, 224); 261 | } 262 | 263 | #main-text-input:disabled { 264 | background: rgb(150, 150, 150); 265 | } 266 | 267 | #settings-container { 268 | text-align: center; 269 | margin: 0; 270 | } 271 | 272 | #settings-child-container { 273 | display: inline-block; 274 | } 275 | 276 | #settings-table { 277 | table-layout: fixed; 278 | width: 100%; 279 | } 280 | 281 | button { 282 | float: right; 283 | background: rgb(63, 63, 63); 284 | border: none; 285 | box-shadow: 0 0.045rem 0 rgb(35, 35, 35), 0.045rem 0 0 rgb(35, 35, 35), 286 | 0.09rem 0.045rem 0 rgb(35, 35, 35), 0.045rem 0.09rem 0 rgb(35, 35, 35), 287 | 0.136rem 0.09rem 0 rgb(35, 35, 35), 0.09rem 0.136rem 0 rgb(35, 35, 35); 288 | border-radius: 0.4rem; 289 | color: var(--whiteTextColor); 290 | padding-top: 0.18rem; 291 | padding-bottom: 0.18rem; 292 | padding-right: 0.27rem; 293 | padding-left: 0.55rem; 294 | font-size: 0.73rem; 295 | margin-right: -0.27rem; 296 | } 297 | 298 | #back-button { 299 | padding-right: 0.4rem; 300 | } 301 | 302 | button:hover { 303 | background: rgb(70, 70, 70); 304 | cursor: pointer; 305 | } 306 | 307 | button:disabled { 308 | background: rgb(40, 40, 40); 309 | color: rgb(135, 135, 135); 310 | } 311 | 312 | #press-any-key-text { 313 | margin: 0; 314 | font-size: 0.64rem; 315 | color: var(--whiteTextColor); 316 | } 317 | 318 | h2 { 319 | text-align: center; 320 | color: var(--whiteTextColor); 321 | margin-top: 0.1rem; 322 | margin-bottom: 0.45rem; 323 | font-size: 1rem; 324 | } 325 | 326 | #options-view { 327 | padding-left: 0.73rem; 328 | padding-right: 0.73rem; 329 | } 330 | 331 | #options-form { 332 | font-size: 0.8rem; 333 | text-align: left; 334 | color: var(--whiteTextColor); 335 | } 336 | 337 | #options-form .option-row { 338 | margin-bottom: 0.18rem; 339 | } 340 | 341 | #options-form .sub-option-row { 342 | margin-bottom: 0.09rem; 343 | } 344 | 345 | #top-must-choose { 346 | max-width: 70%; 347 | } 348 | 349 | .settings-error-text { 350 | float: right; 351 | color: rgb(236, 51, 51); 352 | text-align: right; 353 | font-size: 0.6rem; 354 | } 355 | 356 | #options-form td:not(.settings-error-text) { 357 | width: 35%; 358 | } 359 | 360 | #options-form input { 361 | min-width: 13px; 362 | min-height: 13px; 363 | width: 0.6rem; 364 | height: 0.6rem; 365 | } 366 | 367 | #options-form label { 368 | padding-left: 0.25rem; 369 | /* Japanese characters mess with line height - make it uniform */ 370 | line-height: 1.4; 371 | } 372 | 373 | .options-indent { 374 | padding-left: 1.36rem; 375 | } 376 | 377 | #back-button-container { 378 | display: inline-block; 379 | width: 100%; 380 | margin-top: 0.45rem; 381 | } 382 | 383 | #options-form h3 { 384 | display: inline-block; 385 | margin-top: 0; 386 | margin-bottom: 0; 387 | } 388 | 389 | .transparent-furigana .rt, 390 | .transparent { 391 | opacity: 0; 392 | } 393 | 394 | .hide-furigana .rt, 395 | .display-none, 396 | .hide-emojis .inquery-emoji { 397 | display: none !important; 398 | } 399 | 400 | .background-none { 401 | background: none !important; 402 | } 403 | 404 | hr { 405 | margin: 0.18rem; 406 | border: 0.045rem solid rgb(66, 66, 66); 407 | } 408 | 409 | #adjectives-h3-container, 410 | #verbs-h3-container { 411 | margin-top: 0.45rem; 412 | margin-bottom: 0.45rem; 413 | } 414 | 415 | .footer-text { 416 | color: gray; 417 | font-size: 0.61rem; 418 | margin-bottom: 0.1rem; 419 | margin-top: 0.3rem; 420 | } 421 | 422 | #donation-section { 423 | margin: 0.6rem; 424 | text-align: center; 425 | } 426 | 427 | .conjugation-inquery { 428 | display: inline-block; 429 | } 430 | 431 | .inquery-emoji { 432 | font-size: 0.7rem; 433 | line-height: 1.1; 434 | } 435 | 436 | .inquery-text { 437 | line-height: 1.1; 438 | } 439 | 440 | .advanced-section { 441 | padding-left: 0.3rem; 442 | padding-right: 0.4rem; 443 | padding-top: 0.2rem; 444 | padding-bottom: 0.2rem; 445 | margin-left: -0.23rem; 446 | border-radius: 10px; 447 | max-width: fit-content; 448 | box-shadow: 0.14rem 0.1rem 5px #232323, 0.1rem 0.14rem 5px #232323; 449 | margin-bottom: 0.5rem; 450 | margin-top: 0.1rem; 451 | border: 2px solid #424242; 452 | } 453 | .advanced-option { 454 | margin-bottom: 0.2rem; 455 | } 456 | 457 | #advanced-text { 458 | font-size: 0.7em; 459 | font-weight: 600; 460 | padding-left: 0.2rem; 461 | font-style: italic; 462 | margin-bottom: 0.2rem; 463 | color: #6e6e6e; 464 | display: flex; 465 | align-items: center; 466 | } 467 | 468 | .question-screen #verb-type, 469 | .results-screen #verb-box.background-none #verb-type { 470 | display: none; 471 | } 472 | 473 | .question-screen #status-container { 474 | min-height: 0.8rem; 475 | } 476 | 477 | /* On smaller screens, we prevent verb-type and status-container from taking up screen height when they're invisible so on-screen keyboards don't cover up parts of the app while answering. 478 | On larger screens, we allow verb-type and status-container to always take up screen height so the app stays the same height between the question and results screen. */ 479 | @media screen and (min-height: 820px), screen and (min-width: 510px) { 480 | .question-screen #verb-type, 481 | .results-screen #verb-box.background-none #verb-type { 482 | display: block; 483 | } 484 | 485 | .question-screen #status-container { 486 | min-height: 4rem; 487 | } 488 | } 489 | 490 | @media screen and (min-width: 510px) { 491 | html { 492 | font-size: 18px; 493 | } 494 | #toppest-container { 495 | width: 510px; 496 | } 497 | #top-container { 498 | padding: 0.6rem 0.6rem; 499 | } 500 | h1 { 501 | font-size: 1.4rem; 502 | margin-bottom: 0.9rem; 503 | margin-top: 0.9rem; 504 | display: block; 505 | } 506 | #input-container { 507 | margin-bottom: 0.4rem; 508 | } 509 | #conjugation-inquery-text { 510 | margin-top: 1rem; 511 | } 512 | #status-container { 513 | margin: 1rem; 514 | } 515 | } 516 | 517 | @media screen and (min-width: 750px) { 518 | html { 519 | font-size: 20px; 520 | } 521 | #toppest-container { 522 | width: 575px; 523 | } 524 | } 525 | 526 | @media screen and (min-width: 1100px) { 527 | html { 528 | font-size: 22px; 529 | } 530 | #toppest-container { 531 | width: 650px; 532 | } 533 | h1 { 534 | margin-bottom: 1rem; 535 | margin-top: 1rem; 536 | } 537 | } 538 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Japanese Conjugation Practice 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /src/settingManagement.js: -------------------------------------------------------------------------------- 1 | import { CONJUGATION_TYPES, PARTS_OF_SPEECH } from "./wordEnums.js"; 2 | import { toggleDisplayNone } from "./utils.js"; 3 | 4 | // Enum for radio options that conditionally show/hide UI elements 5 | export const CONDITIONAL_UI_TIMINGS = Object.freeze({ 6 | always: "always", 7 | onlyAfterAnswering: "after", 8 | }); 9 | 10 | const nonConjugationSettings = getNonConjugationSettingsSet(); 11 | 12 | function getNonConjugationSettingsSet() { 13 | const settings = new Set(); 14 | document 15 | .querySelectorAll("#non-conjugation-settings input") 16 | .forEach((input) => settings.add(input.getAttribute("name"))); 17 | return settings; 18 | } 19 | 20 | export function removeNonConjugationSettings(settings) { 21 | let prunedSettings = JSON.parse(JSON.stringify(settings)); 22 | 23 | nonConjugationSettings.forEach((s) => { 24 | delete prunedSettings[s]; 25 | }); 26 | return prunedSettings; 27 | } 28 | 29 | /** 30 | * The settings that should be set for new users 31 | * @returns {Object} settings 32 | */ 33 | export const getDefaultSettings = () => { 34 | // First set all checkboxes to true 35 | const inputs = document 36 | .getElementById("options-form") 37 | .querySelectorAll('[type="checkbox"]'); 38 | const settings = {}; 39 | for (const input of Array.from(inputs)) { 40 | settings[input.name] = true; 41 | } 42 | 43 | // Set any advanced conjugation checkboxes to false 44 | const advancedInputs = document 45 | .getElementById("options-form") 46 | .querySelectorAll('.advanced-section [type="checkbox"]'); 47 | for (const input of Array.from(advancedInputs)) { 48 | settings[input.name] = false; 49 | } 50 | 51 | // Set input radio values 52 | settings["translationTiming"] = CONDITIONAL_UI_TIMINGS.always; 53 | settings["furiganaTiming"] = CONDITIONAL_UI_TIMINGS.always; 54 | 55 | return settings; 56 | }; 57 | 58 | /** 59 | * The settings that should be added to a returning user's settings object 60 | * @returns {Object} settings 61 | */ 62 | export const getDefaultAdditiveSettings = () => { 63 | const settings = {}; 64 | 65 | const nonConjugationInputs = document 66 | .getElementById("non-conjugation-settings") 67 | .querySelectorAll('[type="checkbox"]'); 68 | for (let input of Array.from(nonConjugationInputs)) { 69 | settings[input.name] = true; 70 | } 71 | 72 | // Set input radio values 73 | settings["translationTiming"] = CONDITIONAL_UI_TIMINGS.always; 74 | settings["furiganaTiming"] = CONDITIONAL_UI_TIMINGS.always; 75 | 76 | // All conjugation settings (including advanced options) are added as false 77 | const conjugationInputs = document 78 | .getElementById("conjugation-settings") 79 | .querySelectorAll('[type="checkbox"]'); 80 | for (let input of Array.from(conjugationInputs)) { 81 | settings[input.name] = false; 82 | } 83 | 84 | return settings; 85 | }; 86 | 87 | export function optionsMenuInit() { 88 | const optionsGroups = document.getElementsByClassName("options-group"); 89 | for (const optionGroup of Array.from(optionsGroups)) { 90 | // Note that this registers a listener for a click anywhere in the 91 | // options-group element (not just the checkboxes). 92 | optionGroup.addEventListener("click", (e) => 93 | optionsGroupCheckError(e.currentTarget) 94 | ); 95 | } 96 | 97 | const verbInputsWithVariations = document.getElementsByClassName( 98 | "verb-has-variations" 99 | ); 100 | const verbInputsWithPolitenessOnly = document.getElementsByClassName( 101 | "verb-has-politeness" 102 | ); 103 | for (const input of Array.from(verbInputsWithVariations).concat( 104 | Array.from(verbInputsWithPolitenessOnly) 105 | )) { 106 | input.addEventListener("click", showHideVerbVariationOptions); 107 | } 108 | 109 | const adjectiveInputsWithVariations = document.getElementsByClassName( 110 | "adjective-has-variations" 111 | ); 112 | for (const input of Array.from(adjectiveInputsWithVariations)) { 113 | input.addEventListener("click", showHideAdjectiveVariationOptions); 114 | } 115 | 116 | document 117 | .getElementById("furigana-checkbox") 118 | .addEventListener("click", showHideFuriganaSubOptions); 119 | document 120 | .getElementById("translation-checkbox") 121 | .addEventListener("click", showHideTranslationSubOptions); 122 | 123 | document 124 | .getElementById("verbs-checkbox") 125 | .addEventListener("click", verbAndAdjCheckError); 126 | document 127 | .getElementById("adjectives-checkbox") 128 | .addEventListener("click", verbAndAdjCheckError); 129 | 130 | // top level errors 131 | const optionsView = document.getElementById("options-view"); 132 | optionsView.addEventListener("click", verbPresAffPlainCheckError); 133 | optionsView.addEventListener("click", adjPresAffPlainCheckError); 134 | } 135 | 136 | function checkToEnableBackButton() { 137 | let errors = document.getElementsByClassName("settings-error-text"); 138 | for (let error of Array.from(errors)) { 139 | // checks if any error messages take up space on the screen 140 | if (error.offsetWidth > 0 && error.offsetHeight > 0) { 141 | document.getElementById("back-button").disabled = true; 142 | return; 143 | } 144 | } 145 | 146 | document.getElementById("back-button").disabled = false; 147 | } 148 | 149 | /** 150 | * If enabled is true, sets errorElement's content to errorMessage. 151 | * Otherwise, hides errorElement and tries to enable the back button. 152 | * 153 | * @param {boolean} enabled 154 | * @param {Element} errorElement 155 | * @param {String} errorMessage 156 | */ 157 | function toggleError(enabled, errorElement, errorMessage) { 158 | if (enabled) { 159 | let backButton = document.getElementById("back-button"); 160 | errorElement.textContent = errorMessage; 161 | toggleDisplayNone(errorElement, false); 162 | backButton.disabled = true; 163 | } else { 164 | toggleDisplayNone(errorElement, true); 165 | checkToEnableBackButton(); 166 | } 167 | } 168 | 169 | function doCheckboxesHaveValue(inputs, shouldBeChecked) { 170 | for (let input of Array.from(inputs)) { 171 | if (input.checked !== shouldBeChecked) { 172 | return false; 173 | } 174 | } 175 | return true; 176 | } 177 | 178 | function checkInputsAndToggleError( 179 | inputs, 180 | errorElement, 181 | errorMessage, 182 | shouldBeChecked 183 | ) { 184 | toggleError( 185 | doCheckboxesHaveValue(inputs, shouldBeChecked), 186 | errorElement, 187 | errorMessage 188 | ); 189 | } 190 | 191 | function optionsGroupCheckError(groupElement) { 192 | let inputs = groupElement.getElementsByTagName("input"); 193 | let errorElement = groupElement.getElementsByClassName( 194 | "settings-error-text" 195 | )[0]; 196 | 197 | checkInputsAndToggleError( 198 | inputs, 199 | errorElement, 200 | "*Must choose at least 1 option from this category", 201 | false 202 | ); 203 | } 204 | 205 | function verbAndAdjCheckError() { 206 | let inputs = [ 207 | document.querySelector('input[name="verb"]'), 208 | document.querySelector('input[name="adjective"]'), 209 | ]; 210 | toggleDisplayNone( 211 | document.getElementById("verb-options-container"), 212 | !inputs[0].checked 213 | ); 214 | toggleDisplayNone( 215 | document.getElementById("adjective-options-container"), 216 | !inputs[1].checked 217 | ); 218 | let errorElement = document.getElementById("top-must-choose"); 219 | 220 | checkInputsAndToggleError( 221 | inputs, 222 | errorElement, 223 | "*Must choose at least 1 option from this category", 224 | false 225 | ); 226 | } 227 | 228 | // Relies on naming between verb and adjective checkboxes being parallel in the html 229 | function areOnlyPresAffPlainChecked(partOfSpeech) { 230 | const allInputsToValidate = Array.from( 231 | document 232 | .getElementById(`${partOfSpeech}-conjugation-type-group`) 233 | .getElementsByTagName("input") 234 | ).concat( 235 | Array.from( 236 | document 237 | .getElementById(`${partOfSpeech}-variations-container`) 238 | .getElementsByTagName("input") 239 | ) 240 | ); 241 | 242 | const inputsToBeChecked = new Set([ 243 | `${partOfSpeech}present`, 244 | `${partOfSpeech}affirmative`, 245 | `${partOfSpeech}plain`, 246 | ]); 247 | for (const input of allInputsToValidate) { 248 | // We're validating that only the inputs in inputsToBeChecked are checked. 249 | // Otherwise, return early to prevent the error from being displayed. 250 | if ( 251 | (!input.checked && inputsToBeChecked.has(input.name)) || 252 | (input.checked && !inputsToBeChecked.has(input.name)) 253 | ) { 254 | return false; 255 | } 256 | } 257 | 258 | // If we make it here, then only present, affirmative, and plain were checked in their respective option groups 259 | return true; 260 | } 261 | 262 | function verbPresAffPlainCheckError() { 263 | let optionsGroup = document.getElementById("verb-conjugation-type-group"); 264 | let errorElement = optionsGroup.getElementsByClassName( 265 | "settings-error-text" 266 | )[0]; 267 | 268 | if (areOnlyPresAffPlainChecked(PARTS_OF_SPEECH.verb)) { 269 | toggleError( 270 | true, 271 | errorElement, 272 | "*Invalid combination: present, affirmative, plain" 273 | ); 274 | // These inputs could be hidden because the parent "Verb" option is unchecked, so check to enable back button 275 | checkToEnableBackButton(); 276 | } else { 277 | optionsGroupCheckError(optionsGroup); 278 | } 279 | } 280 | 281 | function adjPresAffPlainCheckError() { 282 | let optionsGroup = document.getElementById("adjective-type-group"); 283 | let errorElement = optionsGroup.getElementsByClassName( 284 | "settings-error-text" 285 | )[0]; 286 | 287 | let iAdjInput = document.querySelector('input[name="adjectivei"]'); 288 | let irrAdjInput = document.querySelector('input[name="adjectiveirregular"]'); 289 | let naAdjInput = document.querySelector('input[name="adjectivena"]'); 290 | 291 | if ( 292 | areOnlyPresAffPlainChecked(PARTS_OF_SPEECH.adjective) && 293 | !naAdjInput.checked && 294 | (iAdjInput.checked || irrAdjInput.checked) 295 | ) { 296 | toggleError( 297 | true, 298 | errorElement, 299 | "*Invalid combination: い/irregular, present, affirmative, plain" 300 | ); 301 | // element could be hidden because verb is unchecked, so check to enable back button 302 | checkToEnableBackButton(); 303 | } else if (document.querySelector('input[name="adjective"]').checked) { 304 | optionsGroupCheckError(optionsGroup); 305 | } 306 | } 307 | 308 | /** 309 | * Shows or hides UI options based on the values of checkboxes. 310 | * 311 | * @param {string} triggeringInputsClass - The class that's been put on inputs that trigger this show/hide 312 | * @param {string} showHideContainerId - The container to show/hide. Should either be an element with an "options-group" class, or be an element that contains other "options-group" elements 313 | * @returns {boolean} - true if the options were shown, false if hidden 314 | */ 315 | function showHideUiOptions(triggeringInputsClass, showHideContainerId) { 316 | const inputsThatTrigger = document.getElementsByClassName( 317 | triggeringInputsClass 318 | ); 319 | const showHideContainer = document.getElementById(showHideContainerId); 320 | // Check if showHideContainer is an options-group itself, or if it contains options-group elements 321 | const optionGroups = showHideContainer.classList.contains("options-group") 322 | ? [showHideContainer] 323 | : showHideContainer.getElementsByClassName("options-group"); 324 | 325 | for (const input of Array.from(inputsThatTrigger)) { 326 | if (input.checked) { 327 | for (const optionGroup of Array.from(optionGroups)) { 328 | optionsGroupCheckError(optionGroup); 329 | toggleDisplayNone(optionGroup, false); 330 | } 331 | 332 | return true; 333 | } 334 | } 335 | 336 | for (const optionGroup of Array.from(optionGroups)) { 337 | toggleDisplayNone(optionGroup, true); 338 | } 339 | return false; 340 | } 341 | 342 | // In this context the options Affirmative, Negative, Plain, and Polite 343 | // are considered "variations" on other conjugation types. 344 | // Not all types (like て for verbs, adverbs for adjectives) have variations. 345 | function showHideVerbVariationOptions() { 346 | // First try to show/hide all variation options 347 | const showingAllVariations = showHideUiOptions( 348 | "verb-has-variations", 349 | "verb-variations-container" 350 | ); 351 | 352 | // If all variations aren't shown, see if just politeness options should be shown 353 | if (!showingAllVariations) { 354 | showHideUiOptions("verb-has-politeness", "verb-politeness-container"); 355 | } 356 | } 357 | function showHideAdjectiveVariationOptions() { 358 | showHideUiOptions( 359 | "adjective-has-variations", 360 | "adjective-variations-container" 361 | ); 362 | } 363 | 364 | function showHideFuriganaSubOptions() { 365 | toggleDisplayNone( 366 | document.getElementById("furigana-sub-options"), 367 | !document.getElementById("furigana-checkbox").checked 368 | ); 369 | } 370 | 371 | function showHideTranslationSubOptions() { 372 | toggleDisplayNone( 373 | document.getElementById("translation-sub-options"), 374 | !document.getElementById("translation-checkbox").checked 375 | ); 376 | } 377 | 378 | export function applyNonConjugationSettings(settings) { 379 | showEmojis(settings.emoji); 380 | showStreak(settings.streak); 381 | // showTranslation and showFurigana are dependent on the state, so we can't set them here 382 | } 383 | 384 | export function applyAllSettingsFilterWords(settings, completeWordList) { 385 | applyNonConjugationSettings(settings); 386 | 387 | let verbs = []; 388 | const verbRegex = /^verb.+/; 389 | if (settings.verb !== false) { 390 | // Copy all of the verbs over 391 | verbs = [...completeWordList.verbs]; 392 | 393 | let verbOptions = Object.keys(settings).filter((el) => 394 | verbRegex.test(el) 395 | ); 396 | // Filter out the verbs we don't want 397 | for (let i = 0; i < verbOptions.length; i++) { 398 | if (settings[verbOptions[i]] === false) { 399 | verbs = verbs.filter( 400 | questionRemoveFilters.verbs[verbOptions[i]] 401 | ); 402 | } 403 | } 404 | } 405 | 406 | let adjectives = []; 407 | const adjectiveRegex = /^adjective.+/; 408 | if (settings.adjective !== false) { 409 | // Copy all of the adjectives over 410 | adjectives = [...completeWordList.adjectives]; 411 | 412 | let adjectiveOptions = Object.keys(settings).filter((el) => 413 | adjectiveRegex.test(el) 414 | ); 415 | // Filter out the adjectives we don't want 416 | for (let i = 0; i < adjectiveOptions.length; i++) { 417 | if (settings[adjectiveOptions[i]] === false) { 418 | adjectives = adjectives.filter( 419 | questionRemoveFilters.adjectives[adjectiveOptions[i]] 420 | ); 421 | } 422 | } 423 | } 424 | 425 | return verbs.concat(adjectives); 426 | } 427 | 428 | // The input to these functions is a "Word" object defined in main.js. 429 | // If one of these filters is applied to an array of Words, 430 | // that type of Word will be removed from the array. 431 | const questionRemoveFilters = { 432 | verbs: { 433 | verbpresent: function (word) { 434 | return word.conjugation.type !== CONJUGATION_TYPES.present; 435 | }, 436 | verbpast: function (word) { 437 | return word.conjugation.type !== CONJUGATION_TYPES.past; 438 | }, 439 | verbte: function (word) { 440 | return word.conjugation.type !== CONJUGATION_TYPES.te; 441 | }, 442 | verbvolitional: function (word) { 443 | return word.conjugation.type !== CONJUGATION_TYPES.volitional; 444 | }, 445 | verbpassive: function (word) { 446 | return word.conjugation.type !== CONJUGATION_TYPES.passive; 447 | }, 448 | verbcausative: function (word) { 449 | return word.conjugation.type !== CONJUGATION_TYPES.causative; 450 | }, 451 | verbpotential: function (word) { 452 | return word.conjugation.type !== CONJUGATION_TYPES.potential; 453 | }, 454 | verbimperative: function (word) { 455 | return word.conjugation.type !== CONJUGATION_TYPES.imperative; 456 | }, 457 | verbcausativepassive: function (word) { 458 | return word.conjugation.type !== CONJUGATION_TYPES.causativePassive; 459 | }, 460 | 461 | verbaffirmative: function (word) { 462 | return word.conjugation.affirmative !== true; 463 | }, 464 | verbnegative: function (word) { 465 | return word.conjugation.affirmative !== false; 466 | }, 467 | 468 | verbplain: function (word) { 469 | return word.conjugation.polite !== false; 470 | }, 471 | verbpolite: function (word) { 472 | return word.conjugation.polite !== true; 473 | }, 474 | 475 | verbu: function (word) { 476 | return word.wordJSON.type != "u"; 477 | }, 478 | verbru: function (word) { 479 | return word.wordJSON.type != "ru"; 480 | }, 481 | verbirregular: function (word) { 482 | return word.wordJSON.type != "irv"; 483 | }, 484 | }, 485 | adjectives: { 486 | adjectivepresent: function (word) { 487 | return word.conjugation.type !== CONJUGATION_TYPES.present; 488 | }, 489 | adjectivepast: function (word) { 490 | return word.conjugation.type !== CONJUGATION_TYPES.past; 491 | }, 492 | adjectiveadverb: function (word) { 493 | return word.conjugation.type !== CONJUGATION_TYPES.adverb; 494 | }, 495 | 496 | adjectiveaffirmative: function (word) { 497 | return word.conjugation.affirmative !== true; 498 | }, 499 | adjectivenegative: function (word) { 500 | return word.conjugation.affirmative !== false; 501 | }, 502 | 503 | adjectiveplain: function (word) { 504 | return word.conjugation.polite !== false; 505 | }, 506 | adjectivepolite: function (word) { 507 | return word.conjugation.polite !== true; 508 | }, 509 | 510 | adjectivei: function (word) { 511 | return word.wordJSON.type != "i"; 512 | }, 513 | adjectivena: function (word) { 514 | return word.wordJSON.type != "na"; 515 | }, 516 | adjectiveirregular: function (word) { 517 | return word.wordJSON.type != "ira"; 518 | }, 519 | }, 520 | }; 521 | 522 | /** 523 | * Searches the maxScoreObjects array for a maxScoreObject with specified settings. 524 | * Make sure visibleConjugationSettings doesn't contain any settings that aren't tied to max score (like "Show English translations" for example) 525 | * 526 | * @param {Array} maxScoreObjects 527 | * @param {Object} visibleConjugationSettings 528 | * @returns The index where the match was found. If no match was found, returns -1. 529 | */ 530 | export function findMaxScoreIndex(maxScoreObjects, visibleConjugationSettings) { 531 | let settingKeys = Object.keys(visibleConjugationSettings); 532 | let flag; 533 | for (let i = 0; i < maxScoreObjects.length; i++) { 534 | flag = true; 535 | for (let s of settingKeys) { 536 | if (maxScoreObjects[i].settings[s] != visibleConjugationSettings[s]) { 537 | flag = false; 538 | break; 539 | } 540 | } 541 | if (flag == true) { 542 | return i; 543 | } 544 | } 545 | return -1; 546 | } 547 | 548 | export const showEmojis = function (show) { 549 | document.getElementById("conjugation-inquery-text").className = show 550 | ? "" 551 | : "hide-emojis"; 552 | }; 553 | 554 | export const showStreak = function (show) { 555 | document.querySelectorAll(".streak").forEach((s) => { 556 | if (show) { 557 | s.classList.remove("display-none"); 558 | } else { 559 | s.classList.add("display-none"); 560 | } 561 | }); 562 | }; 563 | 564 | // Can be shown never, always, or only after answering. 565 | export const showFurigana = function (showInDom, makeTransparent = false) { 566 | const el = document.getElementById("verb-text"); 567 | setDisplayAndTransparency( 568 | el, 569 | showInDom, 570 | "hide-furigana", 571 | makeTransparent, 572 | "transparent-furigana" 573 | ); 574 | }; 575 | 576 | // Can be shown never, always, or only after answering. 577 | export const showTranslation = function (showInDom, makeTransparent = false) { 578 | const el = document.getElementById("translation"); 579 | setDisplayAndTransparency( 580 | el, 581 | showInDom, 582 | "display-none", 583 | makeTransparent, 584 | "transparent" 585 | ); 586 | }; 587 | 588 | // removeClass should lead to display:none 589 | // transparentClass should lead to something like opacity: 0 to keep height when hidden 590 | function setDisplayAndTransparency( 591 | element, 592 | showInDom, 593 | removeClass, 594 | makeTransparent, 595 | transparentClass 596 | ) { 597 | // Reset state 598 | element.classList.remove(removeClass); 599 | element.classList.remove(transparentClass); 600 | 601 | if (!showInDom) { 602 | element.classList.add(removeClass); 603 | return; 604 | } 605 | 606 | if (makeTransparent) { 607 | element.classList.add(transparentClass); 608 | return; 609 | } 610 | } 611 | 612 | export function selectCheckboxesInUi(settings) { 613 | let checkboxInputs = document.querySelectorAll( 614 | `#options-form input[type="checkbox"]` 615 | ); 616 | for (let input of Array.from(checkboxInputs)) { 617 | input.checked = settings[input.name]; 618 | } 619 | 620 | selectConditionalUiRadio( 621 | settings.furiganaTiming, 622 | "furigana-always-radio", 623 | "furigana-after-radio" 624 | ); 625 | selectConditionalUiRadio( 626 | settings.translationTiming, 627 | "translation-always-radio", 628 | "translation-after-radio" 629 | ); 630 | 631 | function selectConditionalUiRadio( 632 | radioValue, 633 | alwaysRadioId, 634 | onlyAfterAnsweringRadioId 635 | ) { 636 | switch (radioValue) { 637 | case CONDITIONAL_UI_TIMINGS.always: 638 | document.getElementById(alwaysRadioId).checked = true; 639 | break; 640 | case CONDITIONAL_UI_TIMINGS.onlyAfterAnswering: 641 | document.getElementById(onlyAfterAnsweringRadioId).checked = true; 642 | break; 643 | } 644 | } 645 | } 646 | 647 | export function showHideOptionsAndCheckErrors() { 648 | showHideVerbVariationOptions(); 649 | showHideAdjectiveVariationOptions(); 650 | 651 | showHideFuriganaSubOptions(); 652 | showHideTranslationSubOptions(); 653 | 654 | let optionsGroups = document.getElementsByClassName("options-group"); 655 | for (let group of Array.from(optionsGroups)) { 656 | optionsGroupCheckError(group); 657 | } 658 | 659 | verbAndAdjCheckError(); 660 | } 661 | 662 | /** 663 | * Overrides values in the settings object based on values selected in the UI 664 | * 665 | * @param {Object} settings 666 | */ 667 | export function insertSettingsFromUi(settings) { 668 | const checkboxInputs = document.querySelectorAll( 669 | '#options-form input[type="checkbox"]' 670 | ); 671 | 672 | for (let input of Array.from(checkboxInputs)) { 673 | settings[input.name] = input.checked; 674 | } 675 | 676 | settings.furiganaTiming = getConditionalUiSetting("furiganaTiming"); 677 | settings.translationTiming = getConditionalUiSetting("translationTiming"); 678 | 679 | // Default to "always" 680 | function getConditionalUiSetting(radioName) { 681 | return ( 682 | document.querySelector(`input[name="${radioName}"]:checked`)?.value ?? 683 | CONDITIONAL_UI_TIMINGS.always 684 | ); 685 | } 686 | 687 | return settings; 688 | } 689 | 690 | /** 691 | * Get a settings object that only contains the settings that are currently visible on the screen. 692 | * Useful for storing max score objects which want as little information as possible since they are stored in localStorage. 693 | */ 694 | export function getVisibleConjugationSettings() { 695 | const visibleConjugationSettings = {}; 696 | const checkboxInputs = document.querySelectorAll( 697 | '#options-form input[type="checkbox"]' 698 | ); 699 | 700 | for (let input of Array.from(checkboxInputs)) { 701 | if ( 702 | input.offsetWidth > 0 && 703 | input.offsetHeight > 0 && 704 | !nonConjugationSettings.has(input.name) 705 | ) { 706 | visibleConjugationSettings[input.name] = input.checked; 707 | } 708 | } 709 | 710 | return visibleConjugationSettings; 711 | } 712 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // since the weights are mostly only used to make things repeat after x amount of rounds, they are overkill 2 | // would be less work to just wait x rounds and immeditely show what you missed, without updating any weights. 3 | "use strict"; 4 | import { bind, isJapanese } from "wanakana"; 5 | import { 6 | CONDITIONAL_UI_TIMINGS, 7 | getDefaultSettings, 8 | getVisibleConjugationSettings, 9 | removeNonConjugationSettings, 10 | showFurigana, 11 | showTranslation, 12 | findMaxScoreIndex, 13 | applyAllSettingsFilterWords, 14 | applyNonConjugationSettings, 15 | optionsMenuInit, 16 | selectCheckboxesInUi, 17 | showHideOptionsAndCheckErrors, 18 | insertSettingsFromUi, 19 | getDefaultAdditiveSettings, 20 | } from "./settingManagement.js"; 21 | import { wordData } from "./wordData.js"; 22 | import { CONJUGATION_TYPES, PARTS_OF_SPEECH } from "./wordEnums.js"; 23 | import { 24 | toggleDisplayNone, 25 | toggleBackgroundNone, 26 | } from "./utils.js"; 27 | 28 | const isTouch = "ontouchstart" in window || navigator.msMaxTouchPoints > 0; 29 | document.getElementById("press-any-key-text").textContent = isTouch 30 | ? "Tap to continue" 31 | : "Press Enter/Return to continue"; 32 | 33 | // Stored in state.activeScreen 34 | const SCREENS = Object.freeze({ 35 | question: 0, 36 | // Incorrect and correct answers are considered the same "results" screen 37 | results: 1, 38 | settings: 2, 39 | }); 40 | 41 | function wordTypeToDisplayText(type) { 42 | if (type == "u") { 43 | return "う-verb"; 44 | } else if (type == "ru") { 45 | return "る-verb"; 46 | } else if (type == "irv" || type == "ira") { 47 | return "Irregular"; 48 | } else if (type == "i") { 49 | return "い-adjective"; 50 | } else if (type == "na") { 51 | return "な-adjective"; 52 | } 53 | } 54 | 55 | function conjugationInqueryFormatting(conjugation) { 56 | let newString = ""; 57 | 58 | function createInqueryText(text, emoji) { 59 | return `
${emoji}
${text}
`; 60 | } 61 | 62 | if (conjugation.type === CONJUGATION_TYPES.past) { 63 | newString += createInqueryText(CONJUGATION_TYPES.past, "⌚"); 64 | } else if ( 65 | conjugation.type === CONJUGATION_TYPES.te || 66 | conjugation.type === CONJUGATION_TYPES.adverb 67 | ) { 68 | newString += conjugation.type; 69 | } else if (conjugation.type === CONJUGATION_TYPES.volitional) { 70 | newString += createInqueryText(CONJUGATION_TYPES.volitional, "🍻"); 71 | } else if (conjugation.type === CONJUGATION_TYPES.passive) { 72 | newString += createInqueryText(CONJUGATION_TYPES.passive, "🧘"); 73 | } else if (conjugation.type === CONJUGATION_TYPES.causative) { 74 | newString += createInqueryText(CONJUGATION_TYPES.causative, "👩‍🏫"); 75 | } else if (conjugation.type === CONJUGATION_TYPES.potential) { 76 | newString += createInqueryText(CONJUGATION_TYPES.potential, "‍🏋"); 77 | } else if (conjugation.type === CONJUGATION_TYPES.imperative) { 78 | newString += createInqueryText(CONJUGATION_TYPES.imperative, "📢"); 79 | } else if (conjugation.type === CONJUGATION_TYPES.causativePassive) { 80 | newString += createInqueryText(CONJUGATION_TYPES.causativePassive, "😒"); 81 | } 82 | 83 | // This used to also add "Affirmative" text when affirmative was true, but it was a little redundant. 84 | // Now it only adds "Negative" text when affirmative is false. 85 | if (conjugation.affirmative === false) { 86 | newString += createInqueryText("Negative", "🚫"); 87 | } 88 | 89 | if (conjugation.polite === true) { 90 | newString += createInqueryText("Polite", "👔"); 91 | } else if (conjugation.polite === false) { 92 | newString += createInqueryText("Plain", "👪"); 93 | } 94 | 95 | return newString; 96 | } 97 | 98 | function changeVerbBoxFontColor(color) { 99 | let ps = document.getElementById("verb-box").getElementsByTagName("p"); 100 | for (let p of Array.from(ps)) { 101 | p.style.color = color; 102 | } 103 | } 104 | 105 | function loadNewWord(wordList) { 106 | let word = pickRandomWord(wordList); 107 | updateCurrentWord(word); 108 | changeVerbBoxFontColor("rgb(232, 232, 232)"); 109 | return word; 110 | } 111 | 112 | function updateCurrentWord(word) { 113 | // Caution: verb-box is controlled using a combination of the background-none class and setting style.background directly. 114 | // The background-none class is useful for other CSS selectors to grab onto, 115 | // while the style.background is useful for setting variable bg colors. 116 | toggleBackgroundNone(document.getElementById("verb-box"), true); 117 | // The element had different padding on different browsers. 118 | // Rather than attacking it with CSS, just replace it with a span we have control over. 119 | const verbHtml = word.wordJSON.kanji 120 | .replaceAll("", '') 121 | .replaceAll("", ""); 122 | document.getElementById("verb-text").innerHTML = verbHtml; 123 | document.getElementById("translation").textContent = word.wordJSON.eng; 124 | // Set verb-type to a non-breaking space to preserve vertical height 125 | document.getElementById("verb-type").textContent = "\u00A0"; 126 | document.getElementById("conjugation-inquery-text").innerHTML = 127 | conjugationInqueryFormatting(word.conjugation); 128 | } 129 | 130 | function touConjugation(affirmative, polite, conjugationType, isKanji) { 131 | const firstLetter = isKanji ? "問" : "と"; 132 | const plainForm = firstLetter + "う"; 133 | if (conjugationType === CONJUGATION_TYPES.present) { 134 | if (affirmative && polite) { 135 | return `${firstLetter}います`; 136 | } else if (affirmative && !polite) { 137 | return `${firstLetter}う`; 138 | } else if (!affirmative && polite) { 139 | return [`${firstLetter}いません`, `${firstLetter}わないです`]; 140 | } else if (!affirmative && !polite) { 141 | return `${firstLetter}わない`; 142 | } 143 | } else if (conjugationType === CONJUGATION_TYPES.past) { 144 | if (affirmative && polite) { 145 | return `${firstLetter}いました`; 146 | } else if (affirmative && !polite) { 147 | return `${firstLetter}うた`; 148 | } else if (!affirmative && polite) { 149 | return [ 150 | `${firstLetter}いませんでした`, 151 | `${firstLetter}わなかったです`, 152 | ]; 153 | } else if (!affirmative && !polite) { 154 | return `${firstLetter}わなかった`; 155 | } 156 | } else if (conjugationType === CONJUGATION_TYPES.te) { 157 | return `${firstLetter}うて`; 158 | } else if (conjugationType === CONJUGATION_TYPES.volitional) { 159 | if (polite) { 160 | return `${firstLetter}いましょう`; 161 | } else { 162 | return `${firstLetter}おう`; 163 | } 164 | } else if ( 165 | conjugationType === CONJUGATION_TYPES.passive || 166 | conjugationType === CONJUGATION_TYPES.causative || 167 | conjugationType === CONJUGATION_TYPES.potential || 168 | conjugationType === CONJUGATION_TYPES.imperative || 169 | conjugationType === CONJUGATION_TYPES.causativePassive 170 | ) { 171 | return conjugationFunctions.verb[conjugationType]( 172 | plainForm, 173 | "u", 174 | affirmative, 175 | polite 176 | ); 177 | } 178 | } 179 | 180 | function aruConjugation(affirmative, polite, conjugationType) { 181 | if (conjugationType == CONJUGATION_TYPES.present) { 182 | if (affirmative && polite) { 183 | return "あります"; 184 | } else if (affirmative && !polite) { 185 | return "ある"; 186 | } else if (!affirmative && polite) { 187 | return ["ありません", "ないです"]; 188 | } else if (!affirmative && !polite) { 189 | return "ない"; 190 | } 191 | } else if (conjugationType == CONJUGATION_TYPES.past) { 192 | if (affirmative && polite) { 193 | return "ありました"; 194 | } else if (affirmative && !polite) { 195 | return "あった"; 196 | } else if (!affirmative && polite) { 197 | return ["ありませんでした", "なかったです"]; 198 | } else if (!affirmative && !polite) { 199 | return "なかった"; 200 | } 201 | } else if (conjugationType == CONJUGATION_TYPES.te) { 202 | return "あって"; 203 | } else if (conjugationType === CONJUGATION_TYPES.volitional) { 204 | if (polite) { 205 | return "ありましょう"; 206 | } else { 207 | return "あろう"; 208 | } 209 | } else if ( 210 | conjugationType === CONJUGATION_TYPES.passive || 211 | conjugationType === CONJUGATION_TYPES.causative || 212 | conjugationType === CONJUGATION_TYPES.imperative || 213 | conjugationType === CONJUGATION_TYPES.causativePassive 214 | ) { 215 | return conjugationFunctions.verb[conjugationType]( 216 | "ある", 217 | "u", 218 | affirmative, 219 | polite 220 | ); 221 | } else if (conjugationType === CONJUGATION_TYPES.potential) { 222 | // あれる seems to technically be valid but never used. 223 | // This leaves あれる out of the answer array so people don't enter あれる without ever seeing that ありえる is the common approach. 224 | if (affirmative && polite) { 225 | return ["ありえます", "あり得ます"]; 226 | } else if (affirmative && !polite) { 227 | // ありうる is only used for the plain form 228 | return ["ありえる", "あり得る", "ありうる"]; 229 | } else if (!affirmative && polite) { 230 | return ["ありえません", "あり得ません"]; 231 | } else if (!affirmative && !polite) { 232 | return ["ありえない", "あり得ない"]; 233 | } 234 | } 235 | } 236 | 237 | function kuruConjugation(affirmative, polite, conjugationType, isKanji) { 238 | let retval; 239 | if (conjugationType === CONJUGATION_TYPES.present) { 240 | if (affirmative && polite) { 241 | retval = "きます"; 242 | } else if (affirmative && !polite) { 243 | retval = "くる"; 244 | } else if (!affirmative && polite) { 245 | retval = ["きません", "こないです"]; 246 | } else if (!affirmative && !polite) { 247 | retval = "こない"; 248 | } 249 | } else if (conjugationType === CONJUGATION_TYPES.past) { 250 | if (affirmative && polite) { 251 | retval = "きました"; 252 | } else if (affirmative && !polite) { 253 | retval = "きた"; 254 | } else if (!affirmative && polite) { 255 | retval = ["きませんでした", "こなかったです"]; 256 | } else if (!affirmative && !polite) { 257 | retval = "こなかった"; 258 | } 259 | } else if (conjugationType === CONJUGATION_TYPES.te) { 260 | retval = "きて"; 261 | } else if (conjugationType === CONJUGATION_TYPES.volitional) { 262 | if (polite) { 263 | retval = "きましょう"; 264 | } else { 265 | retval = "こよう"; 266 | } 267 | } else if ( 268 | conjugationType === CONJUGATION_TYPES.passive || 269 | conjugationType === CONJUGATION_TYPES.causative || 270 | conjugationType === CONJUGATION_TYPES.potential || 271 | conjugationType === CONJUGATION_TYPES.causativePassive 272 | ) { 273 | retval = conjugationFunctions.verb[conjugationType]( 274 | "こる", 275 | "ru", 276 | affirmative, 277 | polite 278 | ); 279 | } else if (conjugationType === CONJUGATION_TYPES.imperative) { 280 | retval = "こい"; 281 | } 282 | 283 | if (isKanji) { 284 | if (typeof retval === "string") { 285 | retval = "来" + retval.substring(1); 286 | } else { 287 | for (let i = 0; i < retval.length; i++) { 288 | retval[i] = "来" + retval[i].substring(1); 289 | } 290 | } 291 | } 292 | return retval; 293 | } 294 | 295 | function suruConjugation(affirmative, polite, conjugationType) { 296 | if (conjugationType === CONJUGATION_TYPES.present) { 297 | if (affirmative && polite) { 298 | return "します"; 299 | } else if (affirmative && !polite) { 300 | return "する"; 301 | } else if (!affirmative && polite) { 302 | return ["しません", "しないです"]; 303 | } else if (!affirmative && !polite) { 304 | return "しない"; 305 | } 306 | } else if (conjugationType === CONJUGATION_TYPES.past) { 307 | if (affirmative && polite) { 308 | return "しました"; 309 | } else if (affirmative && !polite) { 310 | return "した"; 311 | } else if (!affirmative && polite) { 312 | return ["しませんでした", "しなかったです"]; 313 | } else if (!affirmative && !polite) { 314 | return "しなかった"; 315 | } 316 | } else if (conjugationType === CONJUGATION_TYPES.te) { 317 | return "して"; 318 | } else if (conjugationType === CONJUGATION_TYPES.volitional) { 319 | if (polite) { 320 | return "しましょう"; 321 | } else { 322 | return "しよう"; 323 | } 324 | } else if (conjugationType === CONJUGATION_TYPES.passive) { 325 | if (affirmative && polite) { 326 | return "されます"; 327 | } else if (affirmative && !polite) { 328 | return "される"; 329 | } else if (!affirmative && polite) { 330 | return "されません"; 331 | } else if (!affirmative && !polite) { 332 | return "されない"; 333 | } 334 | } else if (conjugationType === CONJUGATION_TYPES.causative) { 335 | if (affirmative && polite) { 336 | return "させます"; 337 | } else if (affirmative && !polite) { 338 | return "させる"; 339 | } else if (!affirmative && polite) { 340 | return "させません"; 341 | } else if (!affirmative && !polite) { 342 | return "させない"; 343 | } 344 | } else if (conjugationType === CONJUGATION_TYPES.causativePassive) { 345 | if (affirmative && polite) { 346 | return "させられます"; 347 | } else if (affirmative && !polite) { 348 | return "させられる"; 349 | } else if (!affirmative && polite) { 350 | return "させられません"; 351 | } else if (!affirmative && !polite) { 352 | return "させられない"; 353 | } 354 | } else if (conjugationType === CONJUGATION_TYPES.potential) { 355 | // I'm not sure if the kanji form 出来る is the same verb as the potential form of する, できる. 356 | // Just allow the kanji anyways, who gives a CRAP. 357 | if (affirmative && polite) { 358 | return ["できます", "出来ます"]; 359 | } else if (affirmative && !polite) { 360 | return ["できる", "出来る"]; 361 | } else if (!affirmative && polite) { 362 | return ["できません", "出来ません"]; 363 | } else if (!affirmative && !polite) { 364 | return ["できない", "出来ない"]; 365 | } 366 | } else if (conjugationType === CONJUGATION_TYPES.imperative) { 367 | return ["しろ", "せよ"]; 368 | } 369 | } 370 | 371 | function ikuConjugation(affirmative, polite, conjugationType, isKanji) { 372 | const firstLetter = isKanji ? "行" : "い"; 373 | const plainForm = firstLetter + "く"; 374 | if (conjugationType === CONJUGATION_TYPES.present) { 375 | if (affirmative && polite) { 376 | return `${firstLetter}きます`; 377 | } else if (affirmative && !polite) { 378 | return `${firstLetter}く`; 379 | } else if (!affirmative && polite) { 380 | return [`${firstLetter}きません`, `${firstLetter}かないです`]; 381 | } else if (!affirmative && !polite) { 382 | return `${firstLetter}かない`; 383 | } 384 | } else if (conjugationType === CONJUGATION_TYPES.past) { 385 | if (affirmative && polite) { 386 | return `${firstLetter}きました`; 387 | } else if (affirmative && !polite) { 388 | return `${firstLetter}った`; 389 | } else if (!affirmative && polite) { 390 | return [ 391 | `${firstLetter}きませんでした`, 392 | `${firstLetter}かなかったです`, 393 | ]; 394 | } else if (!affirmative && !polite) { 395 | return `${firstLetter}かなかった`; 396 | } 397 | } else if (conjugationType === CONJUGATION_TYPES.te) { 398 | return `${firstLetter}って`; 399 | } else if (conjugationType === CONJUGATION_TYPES.volitional) { 400 | if (polite) { 401 | return `${firstLetter}きましょう`; 402 | } else { 403 | return `${firstLetter}こう`; 404 | } 405 | } else if ( 406 | conjugationType === CONJUGATION_TYPES.passive || 407 | conjugationType === CONJUGATION_TYPES.causative || 408 | conjugationType === CONJUGATION_TYPES.potential || 409 | conjugationType === CONJUGATION_TYPES.imperative || 410 | conjugationType === CONJUGATION_TYPES.causativePassive 411 | ) { 412 | return conjugationFunctions.verb[conjugationType]( 413 | plainForm, 414 | "u", 415 | affirmative, 416 | polite 417 | ); 418 | } 419 | } 420 | 421 | function checkSuffix(hiraganaWord, suffix) { 422 | for (let i = 1; i <= suffix.length; i++) { 423 | if (hiraganaWord[hiraganaWord.length - i] != suffix[suffix.length - i]) { 424 | return false; 425 | } 426 | } 427 | return hiraganaWord.replace(suffix, ""); 428 | } 429 | 430 | function irregularVerbConjugation( 431 | hiraganaVerb, 432 | affirmative, 433 | polite, 434 | conjugationType 435 | ) { 436 | let prefix, conjugatedSuffix; 437 | if ((prefix = checkSuffix(hiraganaVerb, "いく")) !== false) { 438 | conjugatedSuffix = ikuConjugation( 439 | affirmative, 440 | polite, 441 | conjugationType, 442 | false 443 | ); 444 | } else if ((prefix = checkSuffix(hiraganaVerb, "行く")) !== false) { 445 | conjugatedSuffix = ikuConjugation( 446 | affirmative, 447 | polite, 448 | conjugationType, 449 | true 450 | ); 451 | } else if ((prefix = checkSuffix(hiraganaVerb, "する")) !== false) { 452 | conjugatedSuffix = suruConjugation(affirmative, polite, conjugationType); 453 | } else if ((prefix = checkSuffix(hiraganaVerb, "くる")) !== false) { 454 | conjugatedSuffix = kuruConjugation( 455 | affirmative, 456 | polite, 457 | conjugationType, 458 | false 459 | ); 460 | } else if ((prefix = checkSuffix(hiraganaVerb, "来る")) !== false) { 461 | conjugatedSuffix = kuruConjugation( 462 | affirmative, 463 | polite, 464 | conjugationType, 465 | true 466 | ); 467 | } else if ((prefix = checkSuffix(hiraganaVerb, "ある")) !== false) { 468 | conjugatedSuffix = aruConjugation(affirmative, polite, conjugationType); 469 | } else if ((prefix = checkSuffix(hiraganaVerb, "とう")) !== false) { 470 | conjugatedSuffix = touConjugation( 471 | affirmative, 472 | polite, 473 | conjugationType, 474 | false 475 | ); 476 | } else if ((prefix = checkSuffix(hiraganaVerb, "問う")) !== false) { 477 | conjugatedSuffix = touConjugation( 478 | affirmative, 479 | polite, 480 | conjugationType, 481 | true 482 | ); 483 | } 484 | 485 | // There may be multiple correct suffixes 486 | if (typeof conjugatedSuffix === "string") { 487 | return prefix + conjugatedSuffix; 488 | } else if (conjugatedSuffix && conjugatedSuffix.constructor === Array) { 489 | let retvals = []; 490 | for (let i = 0; i < conjugatedSuffix.length; i++) { 491 | retvals[i] = prefix + conjugatedSuffix[i]; 492 | } 493 | return retvals; 494 | } 495 | 496 | return "Error"; 497 | } 498 | 499 | function iiConjugation(affirmative, polite, conjugationType) { 500 | if (conjugationType === CONJUGATION_TYPES.present) { 501 | if (affirmative && polite) { 502 | return ["いいです", "良いです"]; 503 | } else if (affirmative && !polite) { 504 | return ["いい", "良い"]; 505 | } else if (!affirmative && polite) { 506 | return [ 507 | "よくないです", 508 | "よくありません", 509 | "良くないです", 510 | "良くありません", 511 | ]; 512 | } else if (!affirmative && !polite) { 513 | return ["よくない", "良くない"]; 514 | } 515 | } else if (conjugationType === CONJUGATION_TYPES.past) { 516 | if (affirmative && polite) { 517 | return ["よかったです", "良かったです"]; 518 | } else if (affirmative && !polite) { 519 | return ["よかった", "良かった"]; 520 | } else if (!affirmative && polite) { 521 | return [ 522 | "よくなかったです", 523 | "よくありませんでした", 524 | "良くなかったです", 525 | "良くありませんでした", 526 | ]; 527 | } else if (!affirmative && !polite) { 528 | return ["よくなかった", "良くなかった"]; 529 | } 530 | } else if (conjugationType === CONJUGATION_TYPES.adverb) { 531 | return ["よく", "良く"]; 532 | } 533 | } 534 | 535 | function irregularAdjectiveConjugation( 536 | hiraganaAdjective, 537 | affirmative, 538 | polite, 539 | conjugationType 540 | ) { 541 | if (hiraganaAdjective == "いい") { 542 | return iiConjugation(affirmative, polite, conjugationType); 543 | } else if (hiraganaAdjective == "かっこいい") { 544 | let conjugations = [].concat( 545 | iiConjugation(affirmative, polite, conjugationType) 546 | ); 547 | for (let i = 0; i < conjugations.length; i++) { 548 | conjugations[i] = "かっこ" + conjugations[i]; 549 | } 550 | return conjugations; 551 | } 552 | } 553 | 554 | function changeUtoI(c) { 555 | if (c == "う") { 556 | return "い"; 557 | } else if (c === "く") { 558 | return "き"; 559 | } else if (c === "ぐ") { 560 | return "ぎ"; 561 | } else if (c === "す") { 562 | return "し"; 563 | } else if (c === "ず") { 564 | return "じ"; 565 | } else if (c === "つ") { 566 | return "ち"; 567 | } else if (c === "づ") { 568 | return "ぢ"; 569 | } else if (c === "ぬ") { 570 | return "に"; 571 | } else if (c === "ふ") { 572 | return "ひ"; 573 | } else if (c === "ぶ") { 574 | return "び"; 575 | } else if (c === "ぷ") { 576 | return "ぴ"; 577 | } else if (c === "む") { 578 | return "み"; 579 | } else if (c === "る") { 580 | return "り"; 581 | } else { 582 | console.debug("Input was not う in changeUtoI, was " + c); 583 | } 584 | } 585 | 586 | function changeUtoA(c) { 587 | if (c === "う") { 588 | return "わ"; 589 | } else if (c === "く") { 590 | return "か"; 591 | } else if (c === "ぐ") { 592 | return "が"; 593 | } else if (c === "す") { 594 | return "さ"; 595 | } else if (c === "ず") { 596 | return "ざ"; 597 | } else if (c === "つ") { 598 | return "た"; 599 | } else if (c === "づ") { 600 | return "だ"; 601 | } else if (c === "ぬ") { 602 | return "な"; 603 | } else if (c === "ふ") { 604 | return "は"; 605 | } else if (c === "ぶ") { 606 | return "ば"; 607 | } else if (c === "ぷ") { 608 | return "ぱ"; 609 | } else if (c === "む") { 610 | return "ま"; 611 | } else if (c === "る") { 612 | return "ら"; 613 | } else { 614 | console.debug("Input was not う in changeUtoA, was " + c); 615 | } 616 | } 617 | 618 | function changeUtoO(c) { 619 | if (c === "う") { 620 | return "お"; 621 | } else if (c === "く") { 622 | return "こ"; 623 | } else if (c === "ぐ") { 624 | return "ご"; 625 | } else if (c === "す") { 626 | return "そ"; 627 | } else if (c === "ず") { 628 | return "ぞ"; 629 | } else if (c === "つ") { 630 | return "と"; 631 | } else if (c === "づ") { 632 | return "ど"; 633 | } else if (c === "ぬ") { 634 | return "の"; 635 | } else if (c === "ふ") { 636 | return "ほ"; 637 | } else if (c === "ぶ") { 638 | return "ぼ"; 639 | } else if (c === "ぷ") { 640 | return "ぽ"; 641 | } else if (c === "む") { 642 | return "も"; 643 | } else if (c === "る") { 644 | return "ろ"; 645 | } else { 646 | console.debug("Input was not う in changeUtoO, was " + c); 647 | } 648 | } 649 | 650 | function changeUtoE(c) { 651 | if (c === "う") { 652 | return "え"; 653 | } else if (c === "く") { 654 | return "け"; 655 | } else if (c === "ぐ") { 656 | return "げ"; 657 | } else if (c === "す") { 658 | return "せ"; 659 | } else if (c === "ず") { 660 | return "ぜ"; 661 | } else if (c === "つ") { 662 | return "て"; 663 | } else if (c === "づ") { 664 | return "で"; 665 | } else if (c === "ぬ") { 666 | return "ね"; 667 | } else if (c === "ふ") { 668 | return "へ"; 669 | } else if (c === "ぶ") { 670 | return "べ"; 671 | } else if (c === "ぷ") { 672 | return "ぺ"; 673 | } else if (c === "む") { 674 | return "め"; 675 | } else if (c === "る") { 676 | return "れ"; 677 | } else { 678 | console.debug("Input was not う in changeUtoE, was " + c); 679 | } 680 | } 681 | 682 | function changeToPastPlain(c) { 683 | if (c == "す") { 684 | return "した"; 685 | } else if (c == "く") { 686 | return "いた"; 687 | } else if (c == "ぐ") { 688 | return "いだ"; 689 | } else if (c == "む" || c == "ぶ" || c == "ぬ") { 690 | return "んだ"; 691 | } else if (c == "る" || c == "う" || c == "つ") { 692 | return "った"; 693 | } else { 694 | console.debug( 695 | "Input was not real verb ending changeToPastPlain, was " + c 696 | ); 697 | } 698 | } 699 | 700 | /** 701 | * る is dropped for ichidan, う goes to い for godan 702 | */ 703 | function masuStem(baseVerbText, type) { 704 | return type == "u" 705 | ? baseVerbText.substring(0, baseVerbText.length - 1) + 706 | changeUtoI(baseVerbText.charAt(baseVerbText.length - 1)) 707 | : baseVerbText.substring(0, baseVerbText.length - 1); 708 | } 709 | 710 | // used by present plain negative and past plain negative 711 | function plainNegativeComplete(hiraganaVerb, type) { 712 | return type == "u" 713 | ? hiraganaVerb.substring(0, hiraganaVerb.length - 1) + 714 | changeUtoA(hiraganaVerb.charAt(hiraganaVerb.length - 1)) + 715 | "ない" 716 | : hiraganaVerb.substring(0, hiraganaVerb.length - 1) + "ない"; 717 | } 718 | 719 | function dropFinalLetter(word) { 720 | return word.substring(0, word.length - 1); 721 | } 722 | 723 | // Conjugation functions can return a single string value, or an array of string values 724 | const conjugationFunctions = { 725 | [PARTS_OF_SPEECH.verb]: { 726 | [CONJUGATION_TYPES.present]: function ( 727 | baseVerbText, 728 | type, 729 | affirmative, 730 | polite 731 | ) { 732 | if (type == "irv") { 733 | return irregularVerbConjugation( 734 | baseVerbText, 735 | affirmative, 736 | polite, 737 | CONJUGATION_TYPES.present 738 | ); 739 | } else if (affirmative && polite) { 740 | return masuStem(baseVerbText, type) + "ます"; 741 | } else if (affirmative && !polite) { 742 | return baseVerbText; 743 | } else if (!affirmative && polite) { 744 | return [ 745 | masuStem(baseVerbText, type) + "ません", 746 | plainNegativeComplete(baseVerbText, type) + "です", 747 | ]; 748 | } else if (!affirmative && !polite) { 749 | return plainNegativeComplete(baseVerbText, type); 750 | } 751 | }, 752 | [CONJUGATION_TYPES.past]: function ( 753 | baseVerbText, 754 | type, 755 | affirmative, 756 | polite 757 | ) { 758 | if (type == "irv") { 759 | return irregularVerbConjugation( 760 | baseVerbText, 761 | affirmative, 762 | polite, 763 | CONJUGATION_TYPES.past 764 | ); 765 | } else if (affirmative && polite) { 766 | return masuStem(baseVerbText, type) + "ました"; 767 | } else if (affirmative && !polite && type == "u") { 768 | return ( 769 | dropFinalLetter(baseVerbText) + 770 | changeToPastPlain(baseVerbText.charAt(baseVerbText.length - 1)) 771 | ); 772 | } else if (affirmative && !polite && type == "ru") { 773 | return masuStem(baseVerbText, type) + "た"; 774 | } else if (!affirmative && polite) { 775 | let plainNegative = plainNegativeComplete(baseVerbText, type); 776 | let plainNegativePast = dropFinalLetter(plainNegative) + "かった"; 777 | return [ 778 | masuStem(baseVerbText, type) + "ませんでした", 779 | plainNegativePast + "です", 780 | ]; 781 | } else if (!affirmative && !polite) { 782 | let plainNegative = plainNegativeComplete(baseVerbText, type); 783 | return dropFinalLetter(plainNegative) + "かった"; 784 | } 785 | }, 786 | [CONJUGATION_TYPES.te]: function (baseVerbText, type) { 787 | if (type == "irv") { 788 | return irregularVerbConjugation( 789 | baseVerbText, 790 | false, 791 | false, 792 | CONJUGATION_TYPES.te 793 | ); 794 | } else if (type == "u") { 795 | let finalChar = baseVerbText.charAt(baseVerbText.length - 1); 796 | if (finalChar == "う" || finalChar == "つ" || finalChar == "る") { 797 | return dropFinalLetter(baseVerbText) + "って"; 798 | } else if ( 799 | finalChar == "む" || 800 | finalChar == "ぶ" || 801 | finalChar == "ぬ" 802 | ) { 803 | return dropFinalLetter(baseVerbText) + "んで"; 804 | } else if (finalChar == "く") { 805 | return dropFinalLetter(baseVerbText) + "いて"; 806 | } else if (finalChar == "ぐ") { 807 | return dropFinalLetter(baseVerbText) + "いで"; 808 | } else if (finalChar == "す") { 809 | return dropFinalLetter(baseVerbText) + "して"; 810 | } 811 | } else if (type == "ru") { 812 | return masuStem(baseVerbText, type) + "て"; 813 | } 814 | }, 815 | // Volitional does not distinguish between affirmative and negative, 816 | // but take it in as a param so this function's structure matches the other conjugation functions 817 | [CONJUGATION_TYPES.volitional]: function ( 818 | baseVerbText, 819 | type, 820 | affirmative, 821 | polite 822 | ) { 823 | if (type === "irv") { 824 | return irregularVerbConjugation( 825 | baseVerbText, 826 | false, 827 | polite, 828 | CONJUGATION_TYPES.volitional 829 | ); 830 | } else if (polite) { 831 | return masuStem(baseVerbText, type) + "ましょう"; 832 | } else if (!polite) { 833 | if (type === "u") { 834 | return ( 835 | dropFinalLetter(baseVerbText) + 836 | changeUtoO(baseVerbText.charAt(baseVerbText.length - 1)) + 837 | "う" 838 | ); 839 | } else if (type === "ru") { 840 | return masuStem(baseVerbText, type) + "よう"; 841 | } 842 | } 843 | }, 844 | [CONJUGATION_TYPES.passive]: function ( 845 | baseVerbText, 846 | type, 847 | affirmative, 848 | polite 849 | ) { 850 | if (type === "irv") { 851 | return irregularVerbConjugation( 852 | baseVerbText, 853 | affirmative, 854 | polite, 855 | CONJUGATION_TYPES.passive 856 | ); 857 | } 858 | 859 | const verbEndingWithA = 860 | dropFinalLetter(baseVerbText) + 861 | changeUtoA(baseVerbText.charAt(baseVerbText.length - 1)); 862 | 863 | if (affirmative && polite) { 864 | return verbEndingWithA + "れます"; 865 | } else if (affirmative && !polite) { 866 | return verbEndingWithA + "れる"; 867 | } else if (!affirmative && polite) { 868 | return verbEndingWithA + "れません"; 869 | } else if (!affirmative && !polite) { 870 | return verbEndingWithA + "れない"; 871 | } 872 | }, 873 | [CONJUGATION_TYPES.causative]: function ( 874 | baseVerbText, 875 | type, 876 | affirmative, 877 | polite 878 | ) { 879 | if (type === "irv") { 880 | return irregularVerbConjugation( 881 | baseVerbText, 882 | affirmative, 883 | polite, 884 | CONJUGATION_TYPES.causative 885 | ); 886 | } 887 | 888 | let verbCausativeRoot; 889 | if (type === "ru") { 890 | verbCausativeRoot = dropFinalLetter(baseVerbText) + "さ"; 891 | } else if (type === "u") { 892 | verbCausativeRoot = 893 | dropFinalLetter(baseVerbText) + 894 | changeUtoA(baseVerbText.charAt(baseVerbText.length - 1)); 895 | } 896 | 897 | if (affirmative && polite) { 898 | return verbCausativeRoot + "せます"; 899 | } else if (affirmative && !polite) { 900 | return verbCausativeRoot + "せる"; 901 | } else if (!affirmative && polite) { 902 | return verbCausativeRoot + "せません"; 903 | } else if (!affirmative && !polite) { 904 | return verbCausativeRoot + "せない"; 905 | } 906 | }, 907 | [CONJUGATION_TYPES.potential]: function ( 908 | baseVerbText, 909 | type, 910 | affirmative, 911 | polite 912 | ) { 913 | if (type === "irv") { 914 | return irregularVerbConjugation( 915 | baseVerbText, 916 | affirmative, 917 | polite, 918 | CONJUGATION_TYPES.potential 919 | ); 920 | } 921 | 922 | const roots = []; 923 | if (type === "u") { 924 | roots.push( 925 | dropFinalLetter(baseVerbText) + 926 | changeUtoE(baseVerbText.charAt(baseVerbText.length - 1)) 927 | ); 928 | } else if (type === "ru") { 929 | // The default spelling should be the dictionary correct "られる", 930 | // but also allow the common shortened version "れる". 931 | roots.push(dropFinalLetter(baseVerbText) + "られ"); 932 | roots.push(dropFinalLetter(baseVerbText) + "れ"); 933 | } 934 | 935 | if (affirmative && polite) { 936 | return roots.map((r) => r + "ます"); 937 | } else if (affirmative && !polite) { 938 | return roots.map((r) => r + "る"); 939 | } else if (!affirmative && polite) { 940 | return roots.map((r) => r + "ません"); 941 | } else if (!affirmative && !polite) { 942 | return roots.map((r) => r + "ない"); 943 | } 944 | }, 945 | [CONJUGATION_TYPES.imperative]: function (baseVerbText, type) { 946 | if (type === "irv") { 947 | return irregularVerbConjugation( 948 | baseVerbText, 949 | null, 950 | null, 951 | CONJUGATION_TYPES.imperative 952 | ); 953 | } 954 | 955 | if (type === "ru") { 956 | return [ 957 | dropFinalLetter(baseVerbText) + "ろ", 958 | // よ seems to be used as an ending only in written Japanese, but still allow it 959 | dropFinalLetter(baseVerbText) + "よ", 960 | ]; 961 | } 962 | 963 | if (type === "u") { 964 | return ( 965 | dropFinalLetter(baseVerbText) + 966 | changeUtoE(baseVerbText.charAt(baseVerbText.length - 1)) 967 | ); 968 | } 969 | }, 970 | [CONJUGATION_TYPES.causativePassive]: function ( 971 | baseVerbText, 972 | type, 973 | affirmative, 974 | polite 975 | ) { 976 | if (type === "irv") { 977 | return irregularVerbConjugation( 978 | baseVerbText, 979 | affirmative, 980 | polite, 981 | CONJUGATION_TYPES.causativePassive 982 | ); 983 | } 984 | const causativePassiveRoot = []; 985 | if (type === "u") { 986 | const finalChar = baseVerbText.charAt(baseVerbText.length - 1); 987 | const root = dropFinalLetter(baseVerbText) + changeUtoA(finalChar); 988 | if (finalChar === "す") { 989 | causativePassiveRoot.push(root + "せられ"); 990 | } else { 991 | causativePassiveRoot.push(root + "せられ"); 992 | causativePassiveRoot.push(root + "され"); 993 | } 994 | } else if (type === "ru") { 995 | causativePassiveRoot.push(dropFinalLetter(baseVerbText) + "させられ"); 996 | } 997 | if (affirmative && polite) { 998 | return causativePassiveRoot.map((r) => r + "ます"); 999 | } else if (affirmative && !polite) { 1000 | return causativePassiveRoot.map((r) => r + "る"); 1001 | } else if (!affirmative && polite) { 1002 | return causativePassiveRoot.map((r) => r + "ません"); 1003 | } else if (!affirmative && !polite) { 1004 | return causativePassiveRoot.map((r) => r + "ない"); 1005 | } 1006 | }, 1007 | }, 1008 | 1009 | [PARTS_OF_SPEECH.adjective]: { 1010 | [CONJUGATION_TYPES.present]: function ( 1011 | baseAdjectiveText, 1012 | type, 1013 | affirmative, 1014 | polite 1015 | ) { 1016 | if (type == "ira") { 1017 | return irregularAdjectiveConjugation( 1018 | baseAdjectiveText, 1019 | affirmative, 1020 | polite, 1021 | CONJUGATION_TYPES.present 1022 | ); 1023 | } else if (affirmative && polite) { 1024 | return baseAdjectiveText + "です"; 1025 | } else if (affirmative && !polite && type == "i") { 1026 | return baseAdjectiveText; 1027 | } else if (affirmative && !polite && type == "na") { 1028 | return baseAdjectiveText + "だ"; 1029 | } else if (!affirmative && polite && type == "i") { 1030 | return [ 1031 | dropFinalLetter(baseAdjectiveText) + "くないです", 1032 | dropFinalLetter(baseAdjectiveText) + "くありません", 1033 | ]; 1034 | } else if (!affirmative && polite && type == "na") { 1035 | return [ 1036 | baseAdjectiveText + "じゃないです", 1037 | baseAdjectiveText + "ではないです", 1038 | baseAdjectiveText + "じゃありません", 1039 | baseAdjectiveText + "ではありません", 1040 | ]; 1041 | } else if (!affirmative && !polite && type == "i") { 1042 | return dropFinalLetter(baseAdjectiveText) + "くない"; 1043 | } else if (!affirmative && !polite && type == "na") { 1044 | return [ 1045 | baseAdjectiveText + "じゃない", 1046 | baseAdjectiveText + "ではない", 1047 | ]; 1048 | } 1049 | }, 1050 | [CONJUGATION_TYPES.past]: function ( 1051 | baseAdjectiveText, 1052 | type, 1053 | affirmative, 1054 | polite 1055 | ) { 1056 | if (type == "ira") { 1057 | return irregularAdjectiveConjugation( 1058 | baseAdjectiveText, 1059 | affirmative, 1060 | polite, 1061 | CONJUGATION_TYPES.past 1062 | ); 1063 | } else if (affirmative && polite && type == "i") { 1064 | return dropFinalLetter(baseAdjectiveText) + "かったです"; 1065 | } else if (affirmative && polite && type == "na") { 1066 | return baseAdjectiveText + "でした"; 1067 | } else if (affirmative && !polite && type == "i") { 1068 | return dropFinalLetter(baseAdjectiveText) + "かった"; 1069 | } else if (affirmative && !polite && type == "na") { 1070 | return baseAdjectiveText + "だった"; 1071 | } else if (!affirmative && polite && type == "i") { 1072 | return [ 1073 | dropFinalLetter(baseAdjectiveText) + "くなかったです", 1074 | dropFinalLetter(baseAdjectiveText) + "くありませんでした", 1075 | ]; 1076 | } else if (!affirmative && polite && type == "na") { 1077 | return [ 1078 | baseAdjectiveText + "じゃなかったです", 1079 | baseAdjectiveText + "ではなかったです", 1080 | baseAdjectiveText + "じゃありませんでした", 1081 | baseAdjectiveText + "ではありませんでした", 1082 | ]; 1083 | } else if (!affirmative && !polite && type == "i") { 1084 | return dropFinalLetter(baseAdjectiveText) + "くなかった"; 1085 | } else if (!affirmative && !polite && type == "na") { 1086 | return [ 1087 | baseAdjectiveText + "じゃなかった", 1088 | baseAdjectiveText + "ではなかった", 1089 | ]; 1090 | } 1091 | }, 1092 | [CONJUGATION_TYPES.adverb]: function (baseAdjectiveText, type) { 1093 | if (type == "ira") { 1094 | return irregularAdjectiveConjugation( 1095 | baseAdjectiveText, 1096 | false, 1097 | false, 1098 | CONJUGATION_TYPES.adverb 1099 | ); 1100 | } else if (type == "i") { 1101 | return dropFinalLetter(baseAdjectiveText) + "く"; 1102 | } else if (type == "na") { 1103 | return baseAdjectiveText + "に"; 1104 | } 1105 | }, 1106 | }, 1107 | }; 1108 | 1109 | function toKanjiPlusHiragana(wordHtml) { 1110 | // ".*?<\/rt>" ensures if there are multiple tags, they are removed one by one instead of as a huge block 1111 | return wordHtml.replace(/|<\/ruby>|.*?<\/rt>/g, ""); 1112 | } 1113 | 1114 | function toHiragana(wordHtml) { 1115 | // "." relies on there being exactly one kanji character before each furigana element 1116 | return wordHtml.replace(/|<\/ruby>|.|<\/rt>/g, ""); 1117 | } 1118 | 1119 | // Determines word part of speech based on wordJSON.type 1120 | function getPartOfSpeech(wordJSON) { 1121 | if ( 1122 | wordJSON.type === "u" || 1123 | wordJSON.type === "ru" || 1124 | wordJSON.type === "irv" 1125 | ) { 1126 | return PARTS_OF_SPEECH.verb; 1127 | } else if ( 1128 | wordJSON.type === "i" || 1129 | wordJSON.type === "na" || 1130 | wordJSON.type === "ira" 1131 | ) { 1132 | return PARTS_OF_SPEECH.adjective; 1133 | } 1134 | } 1135 | 1136 | // Standard variations are affirmative, negative, plain, and polite 1137 | // Returns an array of Conjugations 1138 | function getStandardVariationConjugations( 1139 | wordJSON, 1140 | partOfSpeech, 1141 | conjugationType, 1142 | validBaseWordSpellings 1143 | ) { 1144 | const conjugationObjects = []; 1145 | let affirmative = false, 1146 | polite = false; 1147 | 1148 | for (let i = 0; i < 4; i++) { 1149 | if (i % 2 == 0) { 1150 | affirmative = !affirmative; 1151 | } 1152 | polite = !polite; 1153 | 1154 | // don't need present plain affirmative since it's the dictionary form 1155 | if ( 1156 | affirmative && 1157 | !polite && 1158 | conjugationType === CONJUGATION_TYPES.present && 1159 | wordJSON.type != "na" 1160 | ) 1161 | continue; 1162 | 1163 | conjugationObjects.push( 1164 | getConjugation( 1165 | wordJSON, 1166 | partOfSpeech, 1167 | conjugationType, 1168 | validBaseWordSpellings, 1169 | affirmative, 1170 | polite 1171 | ) 1172 | ); 1173 | } 1174 | 1175 | return conjugationObjects; 1176 | } 1177 | 1178 | function getConjugation( 1179 | wordJSON, 1180 | partOfSpeech, 1181 | conjugationType, 1182 | validBaseWordSpellings, 1183 | affirmative, 1184 | polite 1185 | ) { 1186 | const validConjugatedAnswers = []; 1187 | const conjugationFunction = 1188 | conjugationFunctions[partOfSpeech][conjugationType]; 1189 | 1190 | validBaseWordSpellings?.forEach((baseWord) => { 1191 | validConjugatedAnswers.push( 1192 | conjugationFunction(baseWord, wordJSON.type, affirmative, polite) 1193 | ); 1194 | }); 1195 | 1196 | return new Conjugation( 1197 | // conjugationFunction may return a string or array, so flatten to get rid of nested arrays 1198 | validConjugatedAnswers.flat(), 1199 | conjugationType, 1200 | affirmative, 1201 | polite 1202 | ); 1203 | } 1204 | 1205 | function getAllConjugations(wordJSON) { 1206 | const allConjugations = []; 1207 | const partOfSpeech = getPartOfSpeech(wordJSON); 1208 | 1209 | // Get all valid spellings for the base word 1210 | // For example ["あがる", "上がる", "上る"] 1211 | let validBaseWordSpellings = [ 1212 | toHiragana(wordJSON.kanji), 1213 | toKanjiPlusHiragana(wordJSON.kanji), 1214 | ]; 1215 | if (wordJSON.altOkurigana?.length) { 1216 | validBaseWordSpellings = validBaseWordSpellings.concat( 1217 | wordJSON.altOkurigana 1218 | ); 1219 | } 1220 | 1221 | // Present and past have standard variations for verbs and adjectives 1222 | const typesWithStandardVariations = [ 1223 | CONJUGATION_TYPES.present, 1224 | CONJUGATION_TYPES.past, 1225 | ]; 1226 | 1227 | if (partOfSpeech === PARTS_OF_SPEECH.verb) { 1228 | typesWithStandardVariations.push(CONJUGATION_TYPES.passive); 1229 | typesWithStandardVariations.push(CONJUGATION_TYPES.causative); 1230 | typesWithStandardVariations.push(CONJUGATION_TYPES.causativePassive); 1231 | // わかる does not have a potential form 1232 | if (toHiragana(wordJSON.kanji) !== "わかる") { 1233 | typesWithStandardVariations.push(CONJUGATION_TYPES.potential); 1234 | } 1235 | } 1236 | 1237 | typesWithStandardVariations.forEach((conjugationType) => { 1238 | allConjugations.push( 1239 | getStandardVariationConjugations( 1240 | wordJSON, 1241 | partOfSpeech, 1242 | conjugationType, 1243 | validBaseWordSpellings 1244 | ) 1245 | ); 1246 | }); 1247 | 1248 | if (partOfSpeech === PARTS_OF_SPEECH.verb) { 1249 | // te 1250 | allConjugations.push( 1251 | getConjugation( 1252 | wordJSON, 1253 | partOfSpeech, 1254 | CONJUGATION_TYPES.te, 1255 | validBaseWordSpellings, 1256 | null, 1257 | null 1258 | ) 1259 | ); 1260 | // volitional 1261 | [true, false].forEach((polite) => { 1262 | allConjugations.push( 1263 | getConjugation( 1264 | wordJSON, 1265 | partOfSpeech, 1266 | CONJUGATION_TYPES.volitional, 1267 | validBaseWordSpellings, 1268 | null, 1269 | polite 1270 | ) 1271 | ); 1272 | }); 1273 | // imperative 1274 | allConjugations.push( 1275 | getConjugation( 1276 | wordJSON, 1277 | partOfSpeech, 1278 | CONJUGATION_TYPES.imperative, 1279 | validBaseWordSpellings, 1280 | null, 1281 | null 1282 | ) 1283 | ); 1284 | } else if (partOfSpeech === PARTS_OF_SPEECH.adjective) { 1285 | // Add adverb 1286 | allConjugations.push( 1287 | getConjugation( 1288 | wordJSON, 1289 | partOfSpeech, 1290 | CONJUGATION_TYPES.adverb, 1291 | validBaseWordSpellings, 1292 | null, 1293 | null 1294 | ) 1295 | ); 1296 | } 1297 | 1298 | // allConjugations contains either Conjugations or arrays of Conjugations. 1299 | // Flatten to make into one array. 1300 | return allConjugations.flat(); 1301 | } 1302 | 1303 | class Conjugation { 1304 | // conjugationType is CONJUGATION_TYPES enum 1305 | constructor(validAnswers, conjugationType, affirmative, polite) { 1306 | this.validAnswers = validAnswers; 1307 | this.type = conjugationType; 1308 | this.affirmative = affirmative; 1309 | this.polite = polite; 1310 | } 1311 | } 1312 | 1313 | class Word { 1314 | // conjugation is Conjugation class object 1315 | constructor(wordJSON, conjugation) { 1316 | this.wordJSON = wordJSON; 1317 | this.conjugation = conjugation; 1318 | 1319 | // Probability is updated directly by external functions 1320 | this.probability = 0; 1321 | // wasRecentlyIncorrect is used when calculating probability 1322 | this.wasRecentlyIncorrect = false; 1323 | } 1324 | } 1325 | 1326 | class WordRecentlySeen { 1327 | constructor(word, wasCorrect) { 1328 | this.word = word; 1329 | this.wasCorrect = wasCorrect; 1330 | } 1331 | } 1332 | 1333 | function findMinProb(currentWords) { 1334 | let min = 2; 1335 | for (let i = 0; i < currentWords.length; i++) { 1336 | min = currentWords[i].probability < min && 1337 | currentWords[i].probability != 0 1338 | ? currentWords[i].probability 1339 | : min; 1340 | } 1341 | return min; 1342 | } 1343 | 1344 | function findMaxProb(currentWords) { 1345 | let max = 0; 1346 | for (let i = 0; i < currentWords.length; i++) { 1347 | max = currentWords[i].probability > max 1348 | ? currentWords[i].probability 1349 | : max; 1350 | } 1351 | return max; 1352 | } 1353 | 1354 | function normalizeProbabilities(currentWords) { 1355 | let totalProbability = 0; 1356 | // get total of probabilities 1357 | for (let i = 0; i < currentWords.length; i++) { 1358 | totalProbability += currentWords[i].probability; 1359 | } 1360 | 1361 | // normalize 1362 | for (let i = 0; i < currentWords.length; i++) { 1363 | currentWords[i].probability /= totalProbability; 1364 | } 1365 | } 1366 | 1367 | function setAllProbabilitiesToValue(currentWords, value) { 1368 | for (let i = 0; i < currentWords.length; i++) { 1369 | currentWords[i].probability = value; 1370 | } 1371 | } 1372 | 1373 | // Sets all of the probabilities to the same normalized value 1374 | function equalizeProbabilities(currentWords) { 1375 | setAllProbabilitiesToValue(currentWords, 1); 1376 | 1377 | // Now that all of the probabilities are equal, 1378 | // normalize them so together they all add up to 1. 1379 | normalizeProbabilities(currentWords); 1380 | } 1381 | 1382 | function updateProbabilites( 1383 | currentWords, 1384 | wordsRecentlySeenQueue, 1385 | currentWord, 1386 | currentWordWasCorrect 1387 | ) { 1388 | const roundsToWait = 2; 1389 | 1390 | // If the number of current verb + adjective conjugations is less than roundsToWait + 1, 1391 | // the pool of conjugations is too small for our wordsRecentlySeenQueue to work. 1392 | if (currentWords.length < roundsToWait + 1) { 1393 | // Set all probabilities except the current word to be equal to avoid getting the same question twice 1394 | setAllProbabilitiesToValue(currentWords, 1); 1395 | currentWord.probability = 0; 1396 | normalizeProbabilities(currentWords); 1397 | return; 1398 | } 1399 | 1400 | // Lower probability of running into words in the same group 1401 | if (currentWord.wordJSON.group) { 1402 | const currentConjugation = currentWord.conjugation; 1403 | const group = currentWord.wordJSON.group; 1404 | 1405 | currentWords.filter((word) => { 1406 | const conjugation = word.conjugation; 1407 | // Only alter probabilities of the exact same conjugation for other words in the group 1408 | return ( 1409 | word.wordJSON.group === group && 1410 | word !== currentWord && 1411 | conjugation.type === currentConjugation.type && 1412 | conjugation.affirmative === currentConjugation.affirmative && 1413 | conjugation.polite === currentConjugation.polite 1414 | ); 1415 | }) 1416 | .forEach((word) => { 1417 | // Have to be careful with lowering this too much, because it can affect findMinProb for other conjugations. 1418 | // Also, lowering it by a lot will make all of these words appear in a cluster after all the other words have been seen. 1419 | // Note that this is happening whether currentWordWasCorrect is true or false, 1420 | // so if someone got currentWord wrong many times it would tank the probabilities in this forEach over time. 1421 | word.probability /= 3; 1422 | }); 1423 | } 1424 | 1425 | // We wait "roundsToWait" rounds to set the probability of questions. 1426 | // This allows us to have a few rounds immediately after a question where it's guaranteed to not appear again, 1427 | // followed by the ability to set a high probability for the question to show up immediately after that waiting period (if the answer was incorrect). 1428 | if (wordsRecentlySeenQueue.length >= roundsToWait) { 1429 | let dequeuedWord = wordsRecentlySeenQueue.shift(); 1430 | // Using findMinProb isn't a good solution because if you get one correct it's going to shrink the min prob a lot and affect future questions you get right or wrong. 1431 | // In the future there should probably be a static probability given to corrects, incorrects, and unseens, where that probability slowly grows the longer the word hasn't been seen. 1432 | let currentMinProb = findMinProb(currentWords); 1433 | const correctProbModifier = 0.5; 1434 | const incorrectProbModifier = 0.85; 1435 | 1436 | let newProbability; 1437 | 1438 | if (dequeuedWord.wasCorrect && !dequeuedWord.word.wasRecentlyIncorrect) { 1439 | newProbability = currentMinProb * correctProbModifier; 1440 | } else if ( 1441 | dequeuedWord.wasCorrect && 1442 | dequeuedWord.word.wasRecentlyIncorrect 1443 | ) { 1444 | newProbability = currentMinProb * incorrectProbModifier; 1445 | dequeuedWord.word.wasRecentlyIncorrect = false; 1446 | } else if (!dequeuedWord.wasCorrect) { 1447 | // Set to an arbitrary high number to (nearly) guarantee this question is asked next. 1448 | newProbability = 10; 1449 | } 1450 | 1451 | dequeuedWord.word.probability = newProbability; 1452 | } 1453 | 1454 | // Keep track of misses so when the user finally gets it right, 1455 | // we can still give it a higher probability of appearing again than 1456 | // questions they got right on the first try. 1457 | if (!currentWordWasCorrect) { 1458 | currentWord.wasRecentlyIncorrect = true; 1459 | } 1460 | 1461 | wordsRecentlySeenQueue.push( 1462 | new WordRecentlySeen(currentWord, currentWordWasCorrect) 1463 | ); 1464 | // Make sure the user will not see the current question until at least "roundsToWait" number of rounds 1465 | currentWord.probability = 0; 1466 | 1467 | normalizeProbabilities(currentWords); 1468 | } 1469 | 1470 | // returns new object with all conjugations 1471 | function createWordList(JSONWords) { 1472 | let wordList = {}; 1473 | for (const [key, value] of Object.entries(JSONWords)) { 1474 | wordList[key] = []; 1475 | for (let i = 0; i < value.length; i++) { 1476 | let conjugations = getAllConjugations(value[i]); 1477 | for (let j = 0; j < conjugations.length; j++) { 1478 | wordList[key].push(new Word(value[i], conjugations[j])); 1479 | } 1480 | } 1481 | } 1482 | return wordList; 1483 | } 1484 | 1485 | function pickRandomWord(wordList) { 1486 | let random = Math.random(); 1487 | 1488 | try { 1489 | for (let i = 0; i < wordList.length; i++) { 1490 | if (random < wordList[i].probability) { 1491 | return wordList[i]; 1492 | } 1493 | random -= wordList[i].probability; 1494 | } 1495 | throw "no random word chosen"; 1496 | } catch (err) { 1497 | console.error(err); 1498 | return wordList[0]; 1499 | } 1500 | } 1501 | 1502 | function addToScore(amount = 1, maxScoreObjects, maxScoreIndex) { 1503 | if (amount == 0) { 1504 | return; 1505 | } 1506 | let max = document.getElementById("max-streak-text"); 1507 | let current = document.getElementById("current-streak-text"); 1508 | 1509 | if (parseInt(max.textContent) <= parseInt(current.textContent)) { 1510 | let newAmount = parseInt(max.textContent) + amount; 1511 | max.textContent = newAmount; 1512 | if ( 1513 | !document 1514 | .getElementById("max-streak") 1515 | .classList.contains("display-none") 1516 | ) { 1517 | max.classList.add("grow-animation"); 1518 | } 1519 | 1520 | maxScoreObjects[maxScoreIndex].score = newAmount; 1521 | localStorage.setItem("maxScoreObjects", JSON.stringify(maxScoreObjects)); 1522 | } 1523 | 1524 | current.textContent = parseInt(current.textContent) + amount; 1525 | if ( 1526 | !document 1527 | .getElementById("current-streak") 1528 | .classList.contains("display-none") 1529 | ) { 1530 | current.classList.add("grow-animation"); 1531 | } 1532 | } 1533 | 1534 | function typeToWordBoxColor(type) { 1535 | switch (type) { 1536 | case "u": 1537 | return "rgb(255, 125, 0)"; 1538 | case "ru": 1539 | return "rgb(5, 80, 245)"; 1540 | case "irv": 1541 | return "gray"; 1542 | case "ira": 1543 | return "gray"; 1544 | case "i": 1545 | return "rgb(0, 180, 240)"; 1546 | case "na": 1547 | return "rgb(143, 73, 40)"; 1548 | } 1549 | } 1550 | 1551 | function updateStatusBoxes(word, entryText) { 1552 | let statusBox = document.getElementById("status-box"); 1553 | toggleDisplayNone(statusBox, false); 1554 | 1555 | if (word.conjugation.validAnswers.some((e) => e == entryText)) { 1556 | statusBox.style.background = "green"; 1557 | const subConjugationForm = getSubConjugationForm(word, entryText); 1558 | document.getElementById("status-text").innerHTML = `Correct${ 1559 | subConjugationForm != null 1560 | ? '(' + 1561 | subConjugationForm + 1562 | ")" 1563 | : "" 1564 | }
${entryText} ○`; 1565 | } else { 1566 | document.getElementById("verb-box").style.background = typeToWordBoxColor( 1567 | word.wordJSON.type 1568 | ); 1569 | toggleBackgroundNone(document.getElementById("verb-box"), false); 1570 | changeVerbBoxFontColor("white"); 1571 | document.getElementById("verb-type").textContent = wordTypeToDisplayText( 1572 | word.wordJSON.type 1573 | ); 1574 | 1575 | statusBox.style.background = "rgb(218, 5, 5)"; 1576 | // Assuming validAnswers[0] is the hiragana answer 1577 | document.getElementById("status-text").innerHTML = 1578 | (entryText == "" ? "_" : entryText) + 1579 | " ×
" + 1580 | word.conjugation.validAnswers[0] + 1581 | " ○"; 1582 | } 1583 | } 1584 | 1585 | // If this valid answer is in a non-standard form worth pointing out to the user, 1586 | // return a string containing that form's name. 1587 | // This applies to conjugation types that allow multiple correct answers for the same question, 1588 | // where the user may enter a correct answer without realizing why it was correct. 1589 | function getSubConjugationForm(word, validAnswer) { 1590 | const kanjiWord = toKanjiPlusHiragana(word.wordJSON.kanji); 1591 | const hiraganaWord = toHiragana(word.wordJSON.kanji); 1592 | 1593 | // Check for potential "れる" short form 1594 | if ( 1595 | word.conjugation.type === CONJUGATION_TYPES.potential && 1596 | (word.wordJSON.type === "ru" || kanjiWord === "来る") 1597 | ) { 1598 | const shortFormStems = []; 1599 | 1600 | shortFormStems.push(dropFinalLetter(kanjiWord) + "れ"); 1601 | if (word.wordJSON.type === "ru") { 1602 | shortFormStems.push(dropFinalLetter(hiraganaWord) + "れ"); 1603 | } else if (kanjiWord === "来る") { 1604 | shortFormStems.push("これ"); 1605 | } 1606 | 1607 | if (shortFormStems.some((stem) => validAnswer.startsWith(stem))) { 1608 | return "ら-omitted short form"; 1609 | } 1610 | } 1611 | 1612 | return null; 1613 | } 1614 | 1615 | // stored in array in local storage 1616 | export class MaxScoreObject { 1617 | constructor(score, settings) { 1618 | this.score = score; 1619 | this.settings = settings; 1620 | } 1621 | } 1622 | 1623 | function initApp() { 1624 | new ConjugationApp(wordData); 1625 | } 1626 | 1627 | class ConjugationApp { 1628 | constructor(words) { 1629 | const mainInput = document.getElementById("main-text-input"); 1630 | bind(mainInput); 1631 | 1632 | this.initState(words); 1633 | 1634 | mainInput.addEventListener("keydown", (e) => this.inputKeyPress(e)); 1635 | document 1636 | .getElementById("options-button") 1637 | .addEventListener("click", (e) => this.settingsButtonClicked(e)); 1638 | document 1639 | .getElementById("options-form") 1640 | .addEventListener("submit", (e) => this.backButtonClicked(e)); 1641 | 1642 | document 1643 | .getElementById("current-streak-text") 1644 | .addEventListener("animationend", (e) => { 1645 | document 1646 | .getElementById("current-streak-text") 1647 | .classList.remove(e.animationName); 1648 | }); 1649 | document 1650 | .getElementById("max-streak-text") 1651 | .addEventListener("animationend", (e) => { 1652 | document 1653 | .getElementById("max-streak-text") 1654 | .classList.remove(e.animationName); 1655 | }); 1656 | 1657 | document 1658 | .getElementById("status-box") 1659 | .addEventListener("animationend", (e) => { 1660 | document 1661 | .getElementById("status-box") 1662 | .classList.remove(e.animationName); 1663 | }); 1664 | 1665 | document 1666 | .getElementById("input-tooltip") 1667 | .addEventListener("animationend", (e) => { 1668 | document 1669 | .getElementById("input-tooltip") 1670 | .classList.remove(e.animationName); 1671 | }); 1672 | 1673 | document.addEventListener("keydown", this.onKeyDown.bind(this)); 1674 | document.addEventListener("touchend", this.onTouchEnd.bind(this)); 1675 | 1676 | optionsMenuInit(); 1677 | } 1678 | 1679 | loadMainView() { 1680 | this.state.activeScreen = SCREENS.question; 1681 | document.getElementById("main-view").classList.add("question-screen"); 1682 | document.getElementById("main-view").classList.remove("results-screen"); 1683 | 1684 | document 1685 | .getElementById("input-tooltip") 1686 | .classList.remove("tooltip-fade-animation"); 1687 | 1688 | toggleDisplayNone(document.getElementById("press-any-key-text"), true); 1689 | toggleDisplayNone(document.getElementById("status-box"), true); 1690 | 1691 | if (this.state.currentStreak0OnReset) { 1692 | document.getElementById("current-streak-text").textContent = "0"; 1693 | this.state.currentStreak0OnReset = false; 1694 | } 1695 | 1696 | if (this.state.loadWordOnReset) { 1697 | this.state.currentWord = loadNewWord(this.state.currentWordList); 1698 | this.state.loadWordOnReset = false; 1699 | } 1700 | 1701 | // Furigana and translation may need to be hidden during the question screen 1702 | showFurigana( 1703 | this.state.settings.furigana, 1704 | this.state.settings.furiganaTiming === 1705 | CONDITIONAL_UI_TIMINGS.onlyAfterAnswering 1706 | ); 1707 | showTranslation( 1708 | this.state.settings.translation, 1709 | this.state.settings.translationTiming === 1710 | CONDITIONAL_UI_TIMINGS.onlyAfterAnswering 1711 | ); 1712 | 1713 | const mainInput = document.getElementById("main-text-input"); 1714 | mainInput.disabled = false; 1715 | mainInput.value = ""; 1716 | if (!isTouch) { 1717 | mainInput.focus(); 1718 | } 1719 | } 1720 | 1721 | // Handle generic keydown events that aren't targeting a specific element 1722 | onKeyDown(e) { 1723 | let keyCode = e.keyCode ? e.keyCode : e.which; 1724 | if ( 1725 | this.state.activeScreen === SCREENS.results && 1726 | keyCode == "13" && 1727 | document.activeElement.id !== "options-button" 1728 | ) { 1729 | this.loadMainView(); 1730 | } 1731 | } 1732 | 1733 | // Handle generic touchend events that aren't targeting a specific element 1734 | onTouchEnd(e) { 1735 | if ( 1736 | this.state.activeScreen === SCREENS.results && 1737 | e.target != document.getElementById("options-button") 1738 | ) { 1739 | this.loadMainView(); 1740 | } 1741 | } 1742 | 1743 | inputKeyPress(e) { 1744 | let keyCode = e.keyCode ? e.keyCode : e.which; 1745 | if (keyCode == "13") { 1746 | e.stopPropagation(); 1747 | 1748 | const mainInput = document.getElementById("main-text-input"); 1749 | let inputValue = mainInput.value; 1750 | 1751 | const finalChar = inputValue[inputValue.length - 1]; 1752 | switch (finalChar) { 1753 | // Set hanging n to ん 1754 | case "n": 1755 | inputValue = inputValue.replace(/n$/, "ん"); 1756 | break; 1757 | // Remove hanging 。 1758 | case "。": 1759 | inputValue = inputValue.replace(/。$/, ""); 1760 | } 1761 | 1762 | if (!isJapanese(inputValue)) { 1763 | document 1764 | .getElementById("input-tooltip") 1765 | .classList.add("tooltip-fade-animation"); 1766 | return; 1767 | } else { 1768 | document 1769 | .getElementById("input-tooltip") 1770 | .classList.remove("tooltip-fade-animation"); 1771 | } 1772 | 1773 | this.state.activeScreen = SCREENS.results; 1774 | document 1775 | .getElementById("main-view") 1776 | .classList.remove("question-screen"); 1777 | document.getElementById("main-view").classList.add("results-screen"); 1778 | 1779 | mainInput.blur(); 1780 | updateStatusBoxes(this.state.currentWord, inputValue); 1781 | // If the furigana or translation were made transparent during the question, make them visible now 1782 | showFurigana(this.state.settings.furigana, false); 1783 | showTranslation(this.state.settings.translation, false); 1784 | 1785 | // update probabilities before next word is chosen so don't choose same word 1786 | const inputWasCorrect = 1787 | this.state.currentWord.conjugation.validAnswers.some( 1788 | (e) => e == inputValue 1789 | ); 1790 | 1791 | updateProbabilites( 1792 | this.state.currentWordList, 1793 | this.state.wordsRecentlySeenQueue, 1794 | this.state.currentWord, 1795 | inputWasCorrect 1796 | ); 1797 | 1798 | if (inputWasCorrect) { 1799 | addToScore(1, this.state.maxScoreObjects, this.state.maxScoreIndex); 1800 | this.state.currentStreak0OnReset = false; 1801 | } else { 1802 | this.state.currentStreak0OnReset = true; 1803 | } 1804 | this.state.loadWordOnReset = true; 1805 | 1806 | mainInput.disabled = true; 1807 | toggleDisplayNone( 1808 | document.getElementById("press-any-key-text"), 1809 | false 1810 | ); 1811 | 1812 | mainInput.value = ""; 1813 | } 1814 | } 1815 | 1816 | settingsButtonClicked(e) { 1817 | this.state.activeScreen = SCREENS.settings; 1818 | 1819 | selectCheckboxesInUi(this.state.settings); 1820 | showHideOptionsAndCheckErrors(); 1821 | 1822 | toggleDisplayNone(document.getElementById("main-view"), true); 1823 | toggleDisplayNone(document.getElementById("options-view"), false); 1824 | toggleDisplayNone(document.getElementById("donation-section"), false); 1825 | } 1826 | 1827 | backButtonClicked(e) { 1828 | e.preventDefault(); 1829 | 1830 | insertSettingsFromUi(this.state.settings); 1831 | localStorage.setItem("settings", JSON.stringify(this.state.settings)); 1832 | 1833 | const visibleConjugationSettings = getVisibleConjugationSettings(); 1834 | let newMaxScoreIndex = findMaxScoreIndex( 1835 | this.state.maxScoreObjects, 1836 | visibleConjugationSettings 1837 | ); 1838 | 1839 | if (newMaxScoreIndex === -1) { 1840 | this.state.maxScoreObjects.push( 1841 | new MaxScoreObject(0, visibleConjugationSettings) 1842 | ); 1843 | localStorage.setItem( 1844 | "maxScoreObjects", 1845 | JSON.stringify(this.state.maxScoreObjects) 1846 | ); 1847 | newMaxScoreIndex = this.state.maxScoreObjects.length - 1; 1848 | } 1849 | 1850 | if (newMaxScoreIndex !== this.state.maxScoreIndex) { 1851 | localStorage.setItem("maxScoreIndex", newMaxScoreIndex); 1852 | this.state.maxScoreIndex = newMaxScoreIndex; 1853 | this.state.currentStreak0OnReset = true; 1854 | this.state.loadWordOnReset = true; 1855 | 1856 | this.applySettingsUpdateWordList(); 1857 | 1858 | // Note that the wordsRecentlySeenQueue is not cleared. 1859 | // This is intentional, so if the new word list happens to include the words you recently missed, 1860 | // they still have the chance of appearing again in a couple of rounds to retry. 1861 | // If currentWordList doesn't contain those words in the queue, they won't be chosen anyways so the queue probability logic silenty fails. 1862 | } else { 1863 | // If none of the conjugation settings were changed, don't reload the word list or reset the probabilities 1864 | applyNonConjugationSettings(this.state.settings); 1865 | } 1866 | 1867 | document.getElementById("max-streak-text").textContent = 1868 | this.state.maxScoreObjects[this.state.maxScoreIndex].score; 1869 | 1870 | toggleDisplayNone(document.getElementById("main-view"), false); 1871 | toggleDisplayNone(document.getElementById("options-view"), true); 1872 | toggleDisplayNone(document.getElementById("donation-section"), true); 1873 | 1874 | this.loadMainView(); 1875 | } 1876 | 1877 | initState(words) { 1878 | this.state = {}; 1879 | this.state.completeWordList = createWordList(words); 1880 | 1881 | if ( 1882 | !localStorage.getItem("maxScoreObjects") || 1883 | !localStorage.getItem("maxScoreIndex") || 1884 | !localStorage.getItem("settings") 1885 | ) { 1886 | this.state.maxScoreIndex = 0; 1887 | localStorage.setItem("maxScoreIndex", this.state.maxScoreIndex); 1888 | 1889 | this.state.settings = getDefaultSettings(); 1890 | localStorage.setItem("settings", JSON.stringify(this.state.settings)); 1891 | 1892 | this.state.maxScoreObjects = [ 1893 | new MaxScoreObject( 1894 | 0, 1895 | removeNonConjugationSettings(this.state.settings) 1896 | ), 1897 | ]; 1898 | localStorage.setItem( 1899 | "maxScoreObjects", 1900 | JSON.stringify(this.state.maxScoreObjects) 1901 | ); 1902 | } else { 1903 | this.state.maxScoreIndex = parseInt( 1904 | localStorage.getItem("maxScoreIndex") 1905 | ); 1906 | this.state.settings = Object.assign( 1907 | getDefaultAdditiveSettings(), 1908 | JSON.parse(localStorage.getItem("settings")) 1909 | ); 1910 | this.state.maxScoreObjects = JSON.parse( 1911 | localStorage.getItem("maxScoreObjects") 1912 | ); 1913 | } 1914 | 1915 | this.applySettingsUpdateWordList(); 1916 | this.state.currentWord = loadNewWord(this.state.currentWordList); 1917 | this.state.wordsRecentlySeenQueue = []; 1918 | 1919 | this.state.currentStreak0OnReset = false; 1920 | this.state.loadWordOnReset = false; 1921 | 1922 | document.getElementById("max-streak-text").textContent = 1923 | this.state.maxScoreObjects[this.state.maxScoreIndex].score; 1924 | 1925 | this.loadMainView(); 1926 | } 1927 | 1928 | applySettingsUpdateWordList() { 1929 | const filteredWords = applyAllSettingsFilterWords( 1930 | this.state.settings, 1931 | this.state.completeWordList 1932 | ); 1933 | equalizeProbabilities(filteredWords); 1934 | this.state.currentWordList = filteredWords; 1935 | } 1936 | } 1937 | 1938 | initApp(); 1939 | 1940 | // Keeping the top container hidden at the beginning prevents 1 frame of malformed UI being shown 1941 | toggleDisplayNone(document.getElementById("toppest-container"), false); 1942 | if (!isTouch) { 1943 | document.getElementById("main-text-input").focus(); 1944 | } 1945 | --------------------------------------------------------------------------------