-
Notifications
You must be signed in to change notification settings - Fork 3
/
tajlorligilumi.js
184 lines (175 loc) · 7.98 KB
/
tajlorligilumi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// ligilumi: to parse url parameters
// tajlori: to personalize
// tajlorligilumi: parsing preferences (not verses) url params
const _fbrate_values = {
l: 'l', letter: 'l',
w: 'w', word: 'w',
a: 'a', aaya: 'a',
}
function parse_fbrate (fb) {
return _fbrate_values[ fb.toLowerCase() ]
}
const _color_values = {
t: 'taj', taj: 'taj', tajweed: 'taj',
b: 'bas', bas: 'bas', basic: 'bas',
n: 'no', no: 'no', none: 'no',
}
function parse_color (color) {
return _color_values[ color.toLowerCase() ]
}
const _quizmode_values = {
i: 'imla', imla: 'imla', imlaai: 'imla',
u: 'uthm', uthm: 'uthm', uthmani: 'uthm',
}
function parse_quizmode (quizmode) {
return _quizmode_values[ quizmode.toLowerCase() ]
}
function parse_mv (mv) {
mv = mv.toLowerCase()
if (mv == ''
|| mv == 'b') { return 'bottom' }
if (mv == 'r') { return 'right' }
if (mv == 'l') { return 'left' }
}
function _tajlorligilumilo (params) {
let dark // dark mode: d/dark; l/light (default).
let color = 'taj' // color of text: c/color = t/taj/tajweed (default); b/bas/basic; n/no/none.
let mv = 'bottom' // position of buttons: m/mv/mvbtns = b (bottom; default); r (right); l (left).
let quizmode // quiz mode: q/qz/quizmode = u/uthm/uthmani (no-typing; default); i/imla/imlaai (typing)
let fbrate // imlaai-mode feedback rate: 'l' (by letter; default), 'w' (by word), 'a' (by aaya)
let nolinebreaks // uthmani-mode linebreaks between ayat (default: linebreaks)
let qari // audio recitation qari's id
let qariurl // user-provided audio recitation base_url
let teacher // teacher mode (audio recitation before ayah): t/teach/teacher (true); n/noteach/noteacher (false; default)
let disableteacher // remove teacher mode selector from the UI, teacher mode can still be set from the URL: dt/disableteacher
let disablequizmode // remove quiz mode selector from the UI, quiz mode can still be set from the URL: dq/disablequizmode
let disablecheat // disable the ability to press '!' ten times to show one letter in imlaai mode
let highcontrast // high-contrast, dark colorscheme
let lowcontrast // use a lower contrast imlaai bg color when wrong (not incompatible with highcontrast)
let emulate // keyboard layout emulation; see https://noureddin.github.io/kbt (same ids, w/o '-ar')
let fullpage // make imla_txt fill the entire page while quizzing, like Recite Desktop (PyQt5, in the `master` branch)
let cn // continuation; ie, append a "phrase" from the next aaya if in the same sura
let zz // enable embedded integration: zz (cannot be disabled if enabled)
params
.slice(1) // remove the first character (`?` or `#`)
.split('&')
.map(p => p.split('='))
//.reduce((obj, cur, i) => { i == 0 ? {} : (obj[cur[0]] = cur[1], obj), {})
.forEach((e, i) => {
const is_of = (...params) => params.includes(e[0])
if (is_of('dark', 'd')) { dark = true }
else if (is_of('light', 'l')) { dark = false }
else if (is_of('color', 'c')) { color = parse_color(e[1]) || color }
else if (is_of('mvbtns', 'mv', 'm')) { mv = parse_mv(e[1]) || mv }
else if (is_of('quizmode', 'qz', 'q')) { quizmode = parse_quizmode(e[1]) || quizmode }
else if (is_of('txt')) { quizmode = parse_quizmode('imlaai') }
else if (is_of('byaaya')) { fbrate = 'a' }
else if (is_of('byword')) { fbrate = 'w' }
else if (is_of('byletter')) { fbrate = 'l' }
else if (is_of('by')) { fbrate = parse_fbrate(e[1]) || fbrate }
else if (is_of( 'linebreaks')) { nolinebreaks = false }
else if (is_of('nolinebreaks')) { nolinebreaks = true }
else if (is_of('t', 'teach', 'teacher')) { teacher = true }
else if (is_of('n', 'noteach', 'noteacher')) { teacher = false }
else if (is_of('dt', 'disableteacher')) { disableteacher = true }
else if (is_of('dq', 'disablequizmode')) { disablequizmode = true }
else if (is_of('dc', 'disablecheat')) { disablecheat = true }
else if (is_of('hc', 'highcontrast')) { highcontrast = true }
else if (is_of('lc', 'lowcontrast')) { lowcontrast = true }
else if (is_of('emu', 'emulate', 'emulation')) { emulate = e[1] }
else if (is_of('qari')) { qari = e[1] }
else if (is_of('qariurl')) { qariurl = e[1] }
else if (is_of('fp', 'fullpage')) { fullpage = true }
else if (is_of('cn')) { cn = true }
else if (is_of('zz')) { zz = true }
})
let opts = {
dark,
color,
mv,
quizmode,
fbrate,
nolinebreaks,
teacher,
disableteacher,
disablequizmode,
disablecheat,
highcontrast,
lowcontrast,
emulate,
qari,
qariurl,
fullpage,
cn,
zz,
}
return opts
}
function tajlorligilumi () {
const opts = _tajlorligilumilo(L.hash || L.search)
//
opts.quizmode = opts.quizmode != null ? opts.quizmode : el_quizmode.value
el_quizmode.value = opts.quizmode
el_quizmode.onchange()
//
if (opts.highcontrast) {
el_body.classList.add('highcontrast')
}
//
if (opts.lowcontrast) {
el_body.classList.add('lowcontrast')
}
//
if (opts.dark == null) { // no overriding; follow system preference initially
opts.dark = window.matchMedia('(prefers-color-scheme: dark)').matches
}
el_darkmode_input.checked = opts.dark
el_darkmode_input.onchange()
//
// TODO: add a url param for this '^_^
window.prefers_reduced_motion = window.matchMedia('(prefers-reduced-motion: reduce)').matches
window.scroll_behavior =
window.prefers_reduced_motion
? {}
: { behavior: 'smooth' }
//
el_teacher_input.checked = opts.teacher
//
el_qaris.value = opts.qari
if (!el_qaris.value) { el_qaris.value = '' } // if unset or is a bad value
el_qaris.oninput()
//
if (opts.qariurl) { el_qaris.value = '_' } // an invalid value to hide "With audio"
el_qariurl.value = opts.qariurl ? opts.qariurl : ''
//
el_textclr_input.value = opts.color
el_textclr_input.onchange()
//
el_mvbtns_input.value = opts.mv
el_mvbtns_input.onchange()
//
el_feedbackrate.value = opts.fbrate === 'a' ? 'aaya' : opts.fbrate === 'w' ? 'word' : ''
el_feedbackrate.onchange()
//
el_linebreaks_input.checked = !opts.nolinebreaks
el_linebreaks_input.onchange()
//
const hide = (e) => e.style.display = 'none'
//
if (opts.disableteacher) {
hide(el_teacher_option)
}
//
if (opts.disablequizmode) {
hide(el_quizmode_option)
Qall('.mode_options_title').forEach(hide)
}
//
// options that don't have a visible ui input (in addition to qariurl)
window.allow_cheating = !opts.disablecheat // cheating is allowed by default
if (opts.emulate && mappings[opts.emulate]) { window.emulate = opts.emulate }
if (opts.fullpage) { el_body.classList.add('fullpage') }
if (opts.cn) { el_cn.value = opts.cn ? '1' : '' }
if (opts.zz) { el_zz.value = opts.zz ? '1' : '' }
}
tajlorligilumi()