@@ -13,9 +13,20 @@ function niceDiv(div) {
13
13
div . style . borderRadius = "4px" ;
14
14
}
15
15
/**
16
- * @todo
17
- * Show number of validations too? Might be too noisy.
18
- * @returns {HTMLDivElement }
16
+ * @returns {asserts mode is typeof typecheckOptions.mode } asd
17
+ * @param {string } mode - The mode to test.
18
+ */
19
+ function assertMode ( mode ) {
20
+ switch ( mode ) {
21
+ case 'spam' :
22
+ case 'once' :
23
+ case 'never' :
24
+ return ;
25
+ }
26
+ throw new TypeError ( "wrong mode - either spam, once or never." ) ;
27
+ }
28
+ /**
29
+ * @returns {HTMLDivElement } The <div> at bottom/right position.
19
30
*/
20
31
function createDiv ( ) {
21
32
const div = document . createElement ( "div" ) ;
@@ -26,30 +37,34 @@ function createDiv() {
26
37
niceDiv ( div ) ;
27
38
const spanErrors = document . createElement ( "span" ) ;
28
39
const span = document . createElement ( "span" ) ;
29
- span . innerText = " Spam type reports:" ;
30
- const input = document . createElement ( "input" ) ;
31
- input . type = "checkbox" ;
40
+ span . innerText = " Type report mode:" ;
41
+ const select = document . createElement ( "select" ) ;
42
+ const option_spam = document . createElement ( 'option' ) ;
43
+ option_spam . text = 'spam' ;
44
+ const option_once = document . createElement ( 'option' ) ;
45
+ option_once . text = 'once' ;
46
+ const option_never = document . createElement ( 'option' ) ;
47
+ option_never . text = 'never' ;
48
+ select . append ( option_spam , option_once , option_never ) ;
32
49
const spamTypeReports = localStorage . getItem ( 'rti-spam-type-reports' ) ;
33
- input . checked = true ;
50
+ select . value = typecheckOptions . mode ;
34
51
if ( spamTypeReports !== null ) {
35
- input . checked = spamTypeReports === 'spam' ? true : false ;
52
+ select . value = spamTypeReports ;
36
53
}
37
54
const onchange = ( ) => {
38
- localStorage . setItem ( 'rti-spam-type-reports' , input . checked ? 'spam' : 'once' ) ;
39
- if ( input . checked ) {
40
- typecheckOptions . mode = "spam" ;
41
- } else {
42
- typecheckOptions . mode = "once" ;
43
- }
55
+ const { value} = select ;
56
+ localStorage . setItem ( 'rti-spam-type-reports' , value ) ;
57
+ assertMode ( value ) ;
58
+ typecheckOptions . mode = value ;
44
59
} ;
45
- input . onchange = onchange ;
46
- onchange ( ) ; // update mode from localStorage
60
+ select . onchange = onchange ;
61
+ onchange ( ) ; // set mode in typecheckOptions
47
62
const buttonHide = document . createElement ( "button" ) ;
48
63
buttonHide . textContent = 'Hide' ;
49
64
buttonHide . onclick = ( ) => {
50
65
div . style . display = 'none' ;
51
66
} ;
52
- div . append ( spanErrors , span , input , buttonHide , typecheckWarnedTable ) ;
67
+ div . append ( spanErrors , span , select , buttonHide , typecheckWarnedTable ) ;
53
68
div . style . maxHeight = '200px' ;
54
69
div . style . overflow = 'scroll' ;
55
70
const finalFunc = ( ) => document . body . append ( div ) ;
0 commit comments