Skip to content

Commit c02da57

Browse files
FLYFANFLYFAN
authored andcommitted
fix for autoRun & collocation
1 parent f7520f9 commit c02da57

5 files changed

Lines changed: 20 additions & 18 deletions

File tree

background.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
<script src="./keys/key_2_8.js"></script>
2020
<script src="./keys/key_3_1.js"></script>
2121
<script src="./keys/key_3_2.js"></script>
22+
<script src="./keys/key_3_7.js"></script>
2223
</head>
2324
</html>

key-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ window.keys = [
88
'key_2_7',
99
'key_2_8',
1010
'key_3_1',
11-
'key_3_2'
11+
'key_3_2',
12+
'key_3_7'
1213
]

keys/key_3_7.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ window.key_3_7 = {
3232
content: `1.in 2.on 3.in 4.in 5.into 6.off 7.in 8.to`
3333
},
3434
'key-139-7-7-2': {
35-
type: `cloze`,
36-
content: `1. e 2. 3. a 4. d 5. f 6. c`
35+
type: `collocation`,
36+
content: `1. e harassment 2.b spectrum 3.a futures 4.d sharply 5.f increases 6.c grief`
3737
},
3838
'key-139-7-7-3':
3939
{

main/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ chrome.runtime.onInstalled.addListener(function () {
77
const data = {
88
isRun: true,
99
setting: {
10-
correctRate: 97,
11-
autoRun:false
10+
correctRate: 100,
11+
autoRun: false
1212
}
1313
}
1414

main/content-script.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//通过DOM判断是否为Unipus
44
function isTarget() {
5-
if (window.location.href.match(/book\d+\//))
5+
if (window.location.href.match(/book\d+\//))
66
return true
77
return false
88
}
@@ -12,10 +12,10 @@ var autoRun = false
1212

1313
function getPageInfo() {
1414
var regex_result = window.location.href.match(/book(?<BookID>\d+)\/.+UnitID=(?<UnitID>\d+)&SectionID=(?<SectionID>\d+)&SisterID=(?<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

2121
var keyTab, keyData
@@ -30,6 +30,8 @@ var setting
3030

3131
//在Storage中搜寻答案
3232
function 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
//转化答案
6971
function 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

158158
function 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

163163
const mcf = { 'a': 0, 'b': 1, 'c': 2, 'd': 3 }
164164

165165
function 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

Comments
 (0)