1
1
const mouseUp = ( ) => {
2
- let mark = document . getElementById ( 'getm' ) ,
3
- lineno = document . getElementById ( 'lineno' ) ,
4
- colno = document . getElementById ( 'colno' ) ,
5
- textLines = mark . value . substr ( 0 , mark . selectionStart ) . split ( "\n" ) ;
6
- lineno . innerHTML = " Line " + textLines . length ;
7
- colno . innerHTML = " Col " + textLines [ textLines . length - 1 ] . length ;
2
+ let mark = document . getElementById ( 'getm' ) ;
3
+ let lineno = document . getElementById ( 'lineno' ) ;
4
+ let colno = document . getElementById ( 'colno' ) ;
5
+ let textLines = mark . value . substr ( 0 , mark . selectionStart ) . split ( "\n" ) ;
6
+ lineno . innerHTML = ` Line ${ textLines . length } ` ;
7
+ colno . innerHTML = ` Col ${ textLines [ textLines . length - 1 ] . length } ` ;
8
8
}
9
9
const keyUp = ( ) => {
10
- let mark = document . getElementById ( 'getm' ) . value ,
11
- viewer = document . getElementById ( 'viewer' ) ,
12
- wordcount = document . getElementById ( 'wordcount' ) ,
13
- charcount = document . getElementById ( 'charcount' ) ,
14
- save = document . getElementById ( 'save' ) ,
15
- regex = / \s + / gi;
10
+ let mark = document . getElementById ( 'getm' ) . value ;
11
+ let viewer = document . getElementById ( 'viewer' ) ;
12
+ let wordcount = document . getElementById ( 'wordcount' ) ;
13
+ let charcount = document . getElementById ( 'charcount' ) ;
14
+ let save = document . getElementById ( 'save' ) ;
15
+ let regex = / \s + / gi;
16
16
if ( mark !== '' ) {
17
17
viewer . innerHTML = marked ( mark ) ;
18
- let wordCount = viewer . innerText . trim ( ) . replace ( regex , ' ' ) . split ( ' ' ) . length ,
19
- charCount = viewer . innerText . replace ( regex , '' ) . length ;
20
- wordcount . innerHTML = wordCount + " words" ;
21
- charcount . innerHTML = charCount + " chars" ;
18
+ let wordCount = viewer . innerText . trim ( ) . replace ( regex , ' ' ) . split ( ' ' ) . length ;
19
+ let charCount = viewer . innerText . replace ( regex , '' ) . length ;
20
+ wordcount . innerHTML = ` ${ wordCount } words` ;
21
+ charcount . innerHTML = ` ${ charCount } chars` ;
22
22
save . disabled = false ;
23
23
document . querySelectorAll ( 'pre code' ) . forEach ( ( block ) => {
24
24
hljs . highlightBlock ( block ) ;
@@ -32,8 +32,10 @@ const keyUp = () => {
32
32
}
33
33
}
34
34
const toggleSwitch = document . querySelector ( '.theme-switch input[type="checkbox"]' ) ;
35
- const switchTheme = ( e ) => {
36
- if ( e . target . checked ) {
35
+ const switchTheme = ( {
36
+ target
37
+ } ) => {
38
+ if ( target . checked ) {
37
39
document . documentElement . setAttribute ( 'data-theme' , 'dark' ) ;
38
40
} else {
39
41
document . documentElement . setAttribute ( 'data-theme' , 'light' ) ;
@@ -55,8 +57,10 @@ const download = () => {
55
57
anchor . click ( ) ;
56
58
document . body . removeChild ( anchor ) ;
57
59
}
58
- let openFile = ( e ) => {
59
- let input = e . target ;
60
+ let openFile = ( {
61
+ target
62
+ } ) => {
63
+ let input = target ;
60
64
let reader = new FileReader ( ) ;
61
65
reader . onload = ( ) => {
62
66
document . getElementById ( 'getm' ) . value = reader . result ;
@@ -65,16 +69,20 @@ let openFile = (e) => {
65
69
} ;
66
70
reader . readAsText ( input . files [ 0 ] ) ;
67
71
} ;
68
- document . onkeyup = ( e ) => {
69
- if ( e . altKey && e . which == 79 ) {
72
+ document . onkeyup = ( {
73
+ altKey,
74
+ which
75
+ } ) => {
76
+ if ( altKey && which == 79 ) {
70
77
document . getElementById ( "file" ) . click ( ) ;
71
- } else if ( e . altKey && e . which == 83 ) {
78
+ } else if ( altKey && which == 83 ) {
72
79
document . getElementById ( "save" ) . click ( ) ;
73
80
}
74
81
} ;
75
82
const apply = ( e ) => {
76
- let myField = document . getElementById ( "getm" ) ,
77
- myValueBefore , myValueAfter ;
83
+ let myField = document . getElementById ( "getm" ) ;
84
+ let myValueBefore ;
85
+ let myValueAfter ;
78
86
switch ( e ) {
79
87
case 'bold' :
80
88
myValueBefore = "**" ;
@@ -141,8 +149,8 @@ const apply = (e) => {
141
149
myField . focus ( ) ;
142
150
document . selection . createRange ( ) . text = myValueBefore + document . selection . createRange ( ) . text + myValueAfter ;
143
151
} else if ( myField . selectionStart || myField . selectionStart == '0' ) {
144
- let startPos = myField . selectionStart ,
145
- endPos = myField . selectionEnd ;
152
+ let startPos = myField . selectionStart ;
153
+ let endPos = myField . selectionEnd ;
146
154
myField . value = myField . value . substring ( 0 , startPos ) + myValueBefore + myField . value . substring ( startPos , endPos ) + myValueAfter + myField . value . substring ( endPos , myField . value . length ) ;
147
155
myField . selectionStart = startPos + myValueBefore . length ;
148
156
myField . selectionEnd = endPos + myValueBefore . length ;
0 commit comments