Skip to content

Commit 2b59a9d

Browse files
committed
search ok
1 parent cb73871 commit 2b59a9d

12 files changed

Lines changed: 52 additions & 149 deletions

File tree

crx/extension/popup.js

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crx/src/common/js/locale.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

crx/src/common/js/tools.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global parent, Event, sessionStorage */
22

33
import timeago from 'timeago.js'
4-
import fuzzy from 'fuzzy'
4+
import fuzzy from 'fuzzy.js'
55

66
let config = {
77
api: 'https://greasyfork.org/en/scripts/by-site/{host}.json'
@@ -93,12 +93,28 @@ export default {
9393

9494
searcher (data,query) {
9595
let rt = []
96-
for(i =0 ; i < data.length; i++) {
96+
for(let i =0 ; i < data.length; i++) {
9797
let item = data[i]
9898
let max = null
99-
for(j in ['name','description','user']) {
100-
99+
let frt = null
100+
for(let key of ['name','description','user']) {
101+
if (key === 'user') {
102+
frt = fuzzy(item['user']['name'],query)
103+
} else {
104+
frt = fuzzy(item[key],query)
105+
}
106+
if (max === null) {
107+
max = frt
108+
} else if (max.score < frt.score) {
109+
max = frt
110+
}
101111
}
112+
rt.push({
113+
item,
114+
'score': max.score
115+
})
102116
}
117+
rt = rt.filter((a) => a.score !== 0).sort((a, b) => b.score - a.score).map((a) => a.item)
118+
return rt
103119
}
104120
}

crx/src/common/lang/en-US.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

crx/src/common/lang/zh-CN.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

crx/src/common/lang/zh-tw.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

crx/src/components/Indicator.vue

Lines changed: 0 additions & 34 deletions
This file was deleted.

crx/src/components/Table.vue

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</i18n>
1212
- Userscript+
1313
</span>
14-
<Input v-else v-model="searchInput" icon="android-search" placeholder="Enter something..." style="width: 450px"></Input>
14+
<Input v-else v-model="searchInput" icon="android-search" placeholder="Enter title、description、author..." style="width: 450px"></Input>
1515
</div>
1616
<div slot="extra">
1717
<span>
18-
<Tooltip content="Search" placement="bottom">
18+
<Tooltip :content="$t('table.search')" placement="bottom">
1919
<Button type="dashed" @click="showSearchInput = !showSearchInput">
2020
<Icon type="android-search"></Icon>
2121
</Button>
@@ -102,9 +102,8 @@
102102
/* global Event */
103103
import Tools from '../common/js/tools'
104104
import Info from './Info.vue'
105-
import Indicator from './Indicator.vue'
106105
export default {
107-
components: { Info, Indicator },
106+
components: { Info },
108107
mounted: function () {
109108
this.$Spin.show()
110109
Tools.getData((json) => {
@@ -229,19 +228,20 @@
229228
searchInput: function (val) {
230229
if (val) {
231230
val = val.toLowerCase()
232-
console.log(val)
233-
this.data = this.originData.filter(function(item) {
234-
return ['name','description','user'].some(function(key) {
235-
let str = ''
236-
if (key === 'user') {
237-
str = String(item['user']['name'])
238-
} else {
239-
str = String(item[key])
240-
}
241-
return str.toLowerCase().indexOf(val) > -1
242-
})
243-
})
244-
console.log(this.data)
231+
// console.log(val)
232+
// this.data = this.originData.filter(function(item) {
233+
// return ['name','description','user'].some(function(key) {
234+
// let str = ''
235+
// if (key === 'user') {
236+
// str = String(item['user']['name'])
237+
// } else {
238+
// str = String(item[key])
239+
// }
240+
// return str.toLowerCase().indexOf(val) > -1
241+
// })
242+
// })
243+
this.data = Tools.searcher(this.originData,val)
244+
// console.log(this.data)
245245
} else {
246246
this.data = this.originData
247247
}

crx/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import iView from 'iview'
44
import 'iview/dist/styles/iview.css' // 使用 CSS
55
import 'animate.css'
66
import VueI18n from 'vue-i18n'
7-
import localeMessage from './common/js/locale'
7+
import localeMessage from '../../src/common/js/locale'
88

99
Vue.locale = (locale) => {
1010

src/common/lang/en-US.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default {
1919
closeDonate: 'Close Donate',
2020
feedback: 'Feedback',
2121
close: 'No longer show',
22-
scriptInstalling: 'Script installing...'
22+
scriptInstalling: 'Script installing...',
23+
search: 'Search'
2324
}
2425
}

0 commit comments

Comments
 (0)