Skip to content

Commit f25b1a9

Browse files
authored
Merge pull request #29 from cloudoptlab/fix/2.x/bug-fixes
#27 bug fixes
2 parents 3b09b4b + d21da52 commit f25b1a9

File tree

2 files changed

+59
-37
lines changed

2 files changed

+59
-37
lines changed

src/content/bookmark.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,38 @@ import {sanitize} from 'dompurify'
77
class BookmarkSearch {
88
private readonly host: string
99
private readonly innerClass: string
10-
private keyword: string
10+
private getKeyword: () => string
1111
constructor() {
1212
this.host = getHost(window.location.href)
13-
if (this.host === 'www.baidu.com') {
14-
this.keyword = $('#kw').val() as string
13+
14+
if (this.host.endsWith('.baidu.com')) {
15+
this.getKeyword = () => ($('#kw')[0]['value'] as string)
1516
this.innerClass = '#content_left'
1617
$('#kw').bind('input propertychange', () => {
17-
this.keyword = $('#kw').val() as string
18-
this.sendSearch(this.keyword)
18+
this.sendSearch(this.getKeyword())
1919
})
20-
this.sendSearch(this.keyword)
2120
} else if (this.host.startsWith('www.google.')) {
22-
this.keyword = $('#lst-ib').val() as string
21+
this.getKeyword = () => ($('input.gsfi')[0]['value'] as string)
2322
this.innerClass = '#res'
24-
$('#lst-ib').bind('input propertychange', () => {
25-
this.keyword = $('#lst-ib').val() as string
26-
this.sendSearch(this.keyword)
23+
$('input.gsfi').bind('input propertychange', () => {
24+
this.sendSearch(this.getKeyword())
2725
})
28-
this.sendSearch(this.keyword)
29-
} else if (this.host.endsWith('.bind.com')) {
30-
this.keyword = $('#sb_form_q').val() as string
31-
this.innerClass = '#b_results'
26+
} else if (this.host.endsWith('.bing.com')) {
27+
$('li.b_algo:last').after('<div id="bookmarkCard"></div>')
28+
this.getKeyword = () => ($('#sb_form_q')[0]['value'] as string)
29+
this.innerClass = '#bookmarkCard'
3230
$('#sb_form_q').bind('input propertychange', () => {
33-
this.keyword = $('#sb_form_q').val() as string
34-
this.sendSearch(this.keyword)
31+
this.sendSearch(this.getKeyword())
3532
})
36-
this.sendSearch(this.keyword)
3733
} else if (this.host.endsWith('search.naver.com')) {
38-
this.keyword = $('#nx_query').val() as string
34+
this.getKeyword = () => ($('#nx_query').val() as string)
3935
this.innerClass = '#sub_pack'
4036
$('#nx_query').bind('input propertychange', () => {
41-
this.keyword = $('#nx_query').val() as string
42-
this.sendSearch(this.keyword)
37+
this.sendSearch(this.getKeyword())
4338
})
44-
this.sendSearch(this.keyword)
4539
}
40+
41+
this.sendSearch(this.getKeyword())
4642
}
4743

4844
public sendSearch(keyword: string) {

src/core/notification.ts

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,54 @@ export function error(message: string) {
2828
notyFactory('/image/icon/red/icon512.png')(message)
2929
}
3030

31-
let isCreateNoty = false
31+
let suppressBankNoty = false
32+
let suppressShopNoty = false
33+
let suppressGameNoty = false
34+
let suppressHospitalNoty = false
35+
3236
const noRepeatNotyTime = 1000 * 60 * 5
3337
export async function labSafeTipsNoty(type: string) {
3438
const config = await coreConfig.get()
35-
if (config.labSafeTips && isCreateNoty === false) {
36-
switch (type) {
37-
case 'BANK':
39+
if (!config.labSafeTips) {
40+
return
41+
}
42+
43+
switch (type) {
44+
case 'BANK':
45+
if (!suppressBankNoty) {
3846
info(i18n.get('bankSafeTips'))
39-
break
40-
case 'SHOP':
47+
suppressBankNoty = true
48+
setTimeout(() => {
49+
suppressBankNoty = false
50+
}, noRepeatNotyTime);
51+
}
52+
break
53+
case 'SHOP':
54+
if (!suppressShopNoty) {
4155
info(i18n.get('shopSafeTips'))
42-
break
43-
case 'GAME':
56+
suppressShopNoty = true
57+
setTimeout(() => {
58+
suppressShopNoty = false
59+
}, noRepeatNotyTime);
60+
}
61+
break
62+
case 'GAME':
63+
if (!suppressGameNoty) {
4464
info(i18n.get('gameSafeTips'))
45-
break
46-
case 'HOSPITAL':
65+
suppressGameNoty = true
66+
setTimeout(() => {
67+
suppressGameNoty = false
68+
}, noRepeatNotyTime);
69+
}
70+
break
71+
case 'HOSPITAL':
72+
if (!suppressHospitalNoty) {
4773
info(i18n.get('hospitalSafeTips'))
48-
break
49-
default:
50-
break
51-
}
52-
setTimeout(() => { isCreateNoty = false }, noRepeatNotyTime)
74+
suppressHospitalNoty = true
75+
setTimeout(() => {
76+
suppressHospitalNoty = false
77+
}, noRepeatNotyTime);
78+
}
79+
break
5380
}
54-
isCreateNoty = true
5581
}

0 commit comments

Comments
 (0)