22
33//通过DOM判断是否为Unipus
44function isTarget ( ) {
5- if ( window . location . href . match ( / b o o k \d + \/ / ) )
5+ if ( window . location . href . match ( / b o o k \d + \/ / ) )
66 return true
77 return false
88}
@@ -12,10 +12,10 @@ var autoRun = false
1212
1313function getPageInfo ( ) {
1414 var regex_result = window . location . href . match ( / b o o k (?< BookID > \d + ) \/ .+ U n i t I D = (?< UnitID > \d + ) & S e c t i o n I D = (?< SectionID > \d + ) & S i s t e r I D = (?< SisterID > \d + ) / )
15- if ( regex_result )
15+ if ( regex_result )
1616 locator = regex_result . groups
17- else if ( autoRun )
18- document . querySelector ( '.item1 a' ) && document . querySelector ( '.item1 a' ) . click ( )
17+ else if ( autoRun )
18+ document . querySelector ( '.item1 a' ) && document . querySelector ( '.item1 a' ) . click ( )
1919}
2020
2121var keyTab , keyData
@@ -30,6 +30,8 @@ var setting
3030
3131//在Storage中搜寻答案
3232function searchKey ( ) {
33+ if ( ! locator )
34+ return
3335 let { BookID, UnitID, SectionID, SisterID } = locator
3436 keyTab = `key-${ BookID } -${ UnitID } -${ SectionID } -${ SisterID } `
3537 console . log ( `keyTab=${ keyTab } ` )
@@ -68,16 +70,14 @@ function BBQ(str) {
6870//转化答案
6971function parseKey ( type , content ) {
7072 let result = BBQ ( content )
71- if ( type === 'blank' || type === 'select' )
73+ if ( type === 'blank' || type === 'select' || type === 'collocation' )
7274 return result
7375 else if ( type === 'mc' )
7476 return result . join ( '' ) . replace ( / [ ] / g, "" ) . toLowerCase ( )
7577 else if ( type === 'cloze' )
7678 return result . join ( '' ) . replace ( / [ ] / g, "" ) . toLowerCase ( ) . split ( '-' ) . join ( '' )
7779 else if ( type === 'blankB' )
7880 return result . join ( ' ' ) . split ( ' ' )
79- else if ( type === 'collocation' )
80- return result . map ( e => e . split ( ' ' ) . slice ( 1 ) . join ( ' ' ) )
8181 return content
8282}
8383
@@ -120,7 +120,7 @@ function doCollocation(keys = []) {
120120 let texts = Array . prototype . map . call ( greens , item => item . innerHTML )
121121 keys . forEach ( ( key , index ) => {
122122 for ( let i = 0 ; texts [ i ] ; i ++ ) {
123- if ( key === texts [ i ] . slice ( 3 ) ) {
123+ if ( key === texts [ i ] ) {
124124 greens [ index ] . innerHTML = texts [ i ]
125125 greens [ index ] . id = `Item_${ i } `
126126 break
@@ -137,10 +137,10 @@ function doCloze(content = '') {
137137 console . log ( 'blank be filled' )
138138}
139139
140- function doSelect ( content = [ ] ) {
141- content . forEach ( ( key , index ) =>
140+ function doSelect ( content = [ ] ) {
141+ content . forEach ( ( key , index ) =>
142142 Array . from ( document . querySelectorAll ( `[name=Blank_${ index } ] > option` ) ) . forEach ( opt => {
143- if ( opt . value == key )
143+ if ( opt . value == key )
144144 opt . selected = true
145145 } )
146146 )
@@ -156,14 +156,14 @@ function doBlank(content = []) {
156156}
157157
158158function doBlankB ( content = [ ] ) {
159- for ( let i = 0 ; content [ i ] ; i ++ )
159+ for ( let i = 0 ; content [ i ] ; i ++ )
160160 document . getElementById ( `Blank_0_${ i } ` ) . value = content [ i ]
161161}
162162
163163const mcf = { 'a' : 0 , 'b' : 1 , 'c' : 2 , 'd' : 3 }
164164
165165function doMC ( content = '' ) {
166- for ( let i = 0 ; i < content . length ; i ++ )
166+ for ( let i = 0 ; i < content . length ; i ++ )
167167 document . getElementsByName ( `Radio_${ i } ` ) [ mcf [ content . charAt ( i ) ] ] . click ( )
168168 console . log ( 'MC be clicked' )
169169}
0 commit comments