Skip to content

Commit 8de50d2

Browse files
committed
add search filter
1 parent 300c536 commit 8de50d2

File tree

8 files changed

+78
-19
lines changed

8 files changed

+78
-19
lines changed

dist/show-site-all-userjs.gf.user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// @name:zh-TW Userscript+ : 顯示當前網站所有可用的UserJS腳本 Jaeger
66
// @name:ja Userscript +:現在のサイトの利用可能なすべてのUserJSスクリプトを表示するJaeger
77
// @namespace https://github.com/jae-jae/Userscript-Plus
8-
// @version 2.2.0
8+
// @version 2.3.0
99
// @description Show current site all UserJS,The easier way to install UserJs for Tampermonkey.
1010
// @description:zh 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
1111
// @description:zh-CN 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
@@ -17,8 +17,8 @@
1717
// @exclude http://www.dev/Show-Site-All-UserJS/ui.html
1818
// @require https://greasyfork.org/scripts/23419-l-js/code/ljs.js
1919
// @require https://greasyfork.org/scripts/23420-userjs-base-js/code/userjs-basejs.js
20-
// @resource ui https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.html?_=1521174237027
21-
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1521174237027
20+
// @resource ui https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.html?_=1521784041819
21+
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1521784041819
2222
// @resource count https://greasyfork.org/scripts/by-site.json
2323
// @grant GM_xmlhttpRequest
2424
// @grant GM_getResourceText

dist/show-site-all-userjs.user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// @name:zh-TW Userscript+ : 顯示當前網站所有可用的UserJS腳本 Jaeger
66
// @name:ja Userscript +:現在のサイトの利用可能なすべてのUserJSスクリプトを表示するJaeger
77
// @namespace https://github.com/jae-jae/Userscript-Plus
8-
// @version 2.2.0
8+
// @version 2.3.0
99
// @description Show current site all UserJS,The easier way to install UserJs for Tampermonkey.
1010
// @description:zh 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
1111
// @description:zh-CN 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
@@ -17,8 +17,8 @@
1717
// @exclude http://www.dev/Show-Site-All-UserJS/ui.html
1818
// @require https://raw.githubusercontent.com/jae-jae/l.js/master/userjs/l.userjs.min.js
1919
// @require https://gist.githubusercontent.com/jae-jae/35a1833079d26e6c9d9c6d5bed982353/raw/userjs-base.js
20-
// @resource ui https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.html?_=1521174237026
21-
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1521174237026
20+
// @resource ui https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.html?_=1521784041818
21+
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1521784041818
2222
// @resource count https://greasyfork.org/scripts/by-site.json
2323
// @grant GM_xmlhttpRequest
2424
// @grant GM_getResourceText

dist/ui.js

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"dependencies": {
3939
"animate.css": "^3.5.2",
40+
"fuzzy.js": "^0.1.0",
4041
"iview": "^2.2.0",
4142
"timeago.js": "^3.0.2",
4243
"vue": "^2.4.2",

src/common/js/tools.js

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

33
import timeago from 'timeago.js'
4+
import fuzzy from 'fuzzy.js'
45

56
let config = {
67
cacheKey: 'jae_fetch_userjs_cache',
@@ -64,5 +65,32 @@ export default {
6465
getCount () {
6566
let count = sessionStorage.getItem(config.countKey)
6667
return count >= 50 ? 50 : count
68+
},
69+
70+
searcher (data,query) {
71+
let rt = []
72+
for(let i =0 ; i < data.length; i++) {
73+
let item = data[i]
74+
let max = null
75+
let frt = null
76+
for(let key of ['name','description','user']) {
77+
if (key === 'user') {
78+
frt = fuzzy(item['user']['name'],query)
79+
} else {
80+
frt = fuzzy(item[key],query)
81+
}
82+
if (max === null) {
83+
max = frt
84+
} else if (max.score < frt.score) {
85+
max = frt
86+
}
87+
}
88+
rt.push({
89+
item,
90+
'score': max.score
91+
})
92+
}
93+
rt = rt.filter((a) => a.score !== 0).sort((a, b) => b.score - a.score).map((a) => a.item)
94+
return rt
6795
}
6896
}

src/components/Table.vue

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33
<transition name="custom-classes-transition" enter-active-class="animated lightSpeedIn">
44
<div v-show="showTitle">
55
<Card :padding="0">
6-
<div slot="title" @click="bodySwitch" class="card-title">
6+
<div slot="title" class="card-title">
77
<Icon :type="titleIcon"></Icon>
88
<!--<span>发现 <Badge :count="count"></Badge> 个脚本适用于当前页面</span>-->
9-
<i18n path="table.tips" tag="span">
10-
<Badge place="count" :count="count" style="padding:0px 5px;"></Badge>
11-
</i18n>
12-
<span v-show="showBody">
13-
- Userscript+
14-
</span>
9+
<span v-if="!showSearchInput" @click="bodySwitch">
10+
<i18n path="table.tips" tag="span">
11+
<Badge place="count" :count="count" style="padding:0px 5px;"></Badge>
12+
</i18n>
13+
<span v-show="showBody">
14+
- Userscript+
15+
</span>
16+
</span>
17+
<Input v-else v-model="searchInput" icon="android-search" placeholder="Enter title、description、author..." style="width: 450px;height: 25px;"></Input>
1518
</div>
1619
<div slot="extra">
1720
<span v-show="showBody">
21+
<Tooltip :content="$t('table.search')" placement="bottom">
22+
<Button type="dashed" @click="showSearchInput = !showSearchInput">
23+
<Icon type="android-search"></Icon>
24+
</Button>
25+
</Tooltip>
26+
1827
<Tooltip :content="$t('table.feedback')" placement="bottom">
1928
<Button type="dashed" @click="open('https://greasyfork.org/zh-CN/scripts/24508/feedback')">
2029
<Icon type="bug"></Icon>
@@ -125,6 +134,8 @@
125134
},
126135
data: function () {
127136
return {
137+
showSearchInput: false,
138+
searchInput: '',
128139
showTitle: false,
129140
showBody: false,
130141
titleIcon: 'chevron-up',
@@ -228,6 +239,7 @@
228239
}
229240
],
230241
// 表格数据
242+
originData: [],
231243
data: []
232244
}
233245
},
@@ -243,6 +255,14 @@
243255
Tools.dispatchEvent('min')
244256
}
245257
window.dispatchEvent(new Event('resize'))
258+
},
259+
searchInput: function (val) {
260+
if (val) {
261+
val = val.toLowerCase()
262+
this.data = Tools.searcher(this.originData,val)
263+
} else {
264+
this.data = this.originData
265+
}
246266
}
247267
},
248268
methods: {
@@ -265,6 +285,7 @@
265285
this.$Spin.show()
266286
Tools.dispatchEvent('loading')
267287
Tools.getData((json) => {
288+
this.originData = json
268289
this.data = json
269290
this.$Spin.hide()
270291
this.showBody = !this.showBody

userscript/tpl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// @name:zh-TW Userscript+ : 顯示當前網站所有可用的UserJS腳本 Jaeger
66
// @name:ja Userscript +:現在のサイトの利用可能なすべてのUserJSスクリプトを表示するJaeger
77
// @namespace https://github.com/jae-jae/Userscript-Plus
8-
// @version 2.2.0
8+
// @version 2.3.0
99
// @description Show current site all UserJS,The easier way to install UserJs for Tampermonkey.
1010
// @description:zh 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
1111
// @description:zh-CN 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,10 @@ function-bind@^1.0.2, function-bind@^1.1.1:
20152015
version "1.1.1"
20162016
resolved "http://registry.npm.taobao.org/function-bind/download/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
20172017

2018+
fuzzy.js@^0.1.0:
2019+
version "0.1.0"
2020+
resolved "http://registry.npm.taobao.org/fuzzy.js/download/fuzzy.js-0.1.0.tgz#c147ff5f5a8d0c7a5340b79bdbb01607deb6ff73"
2021+
20182022
gauge@~2.7.3:
20192023
version "2.7.4"
20202024
resolved "http://registry.npm.taobao.org/gauge/download/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"

0 commit comments

Comments
 (0)