| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | /* global parent, Event, sessionStorage */ | |
| 2 | 2 | ||
| 3 | 3 | import timeago from 'timeago.js' | |
| 4 | - import fuzzy from 'fuzzy' | ||
| 4 | + import fuzzy from 'fuzzy.js' | ||
| 5 | 5 | ||
| 6 | 6 | let config = { | |
| 7 | 7 | api: 'https://greasyfork.org/en/scripts/by-site/{host}.json' | |
@@ -93,12 +93,28 @@ export default { | |||
| 93 | 93 | ||
| 94 | 94 | searcher (data,query) { | |
| 95 | 95 | let rt = [] | |
| 96 | - for(i =0 ; i < data.length; i++) { | ||
| 96 | + for(let i =0 ; i < data.length; i++) { | ||
| 97 | 97 | let item = data[i] | |
| 98 | 98 | 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 | + } | ||
| 101 | 111 | } | |
| 112 | + rt.push({ | ||
| 113 | + item, | ||
| 114 | + 'score': max.score | ||
| 115 | + }) | ||
| 102 | 116 | } | |
| 117 | + rt = rt.filter((a) => a.score !== 0).sort((a, b) => b.score - a.score).map((a) => a.item) | ||
| 118 | + return rt | ||
| 103 | 119 | } | |
| 104 | 120 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,11 +11,11 @@ | |||
| 11 | 11 | </i18n> | |
| 12 | 12 | - Userscript+ | |
| 13 | 13 | </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> | ||
| 15 | 15 | </div> | |
| 16 | 16 | <div slot="extra"> | |
| 17 | 17 | <span> | |
| 18 | - <Tooltip content="Search" placement="bottom"> | ||
| 18 | + <Tooltip :content="$t('table.search')" placement="bottom"> | ||
| 19 | 19 | <Button type="dashed" @click="showSearchInput = !showSearchInput"> | |
| 20 | 20 | <Icon type="android-search"></Icon> | |
| 21 | 21 | </Button> | |
@@ -102,9 +102,8 @@ | |||
| 102 | 102 | /* global Event */ | |
| 103 | 103 | import Tools from '../common/js/tools' | |
| 104 | 104 | import Info from './Info.vue' | |
| 105 | - import Indicator from './Indicator.vue' | ||
| 106 | 105 | export default { | |
| 107 | - components: { Info, Indicator }, | ||
| 106 | + components: { Info }, | ||
| 108 | 107 | mounted: function () { | |
| 109 | 108 | this.$Spin.show() | |
| 110 | 109 | Tools.getData((json) => { | |
@@ -229,19 +228,20 @@ | |||
| 229 | 228 | searchInput: function (val) { | |
| 230 | 229 | if (val) { | |
| 231 | 230 | 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) | ||
| 245 | 245 | } else { | |
| 246 | 246 | this.data = this.originData | |
| 247 | 247 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ import iView from 'iview' | |||
| 4 | 4 | import 'iview/dist/styles/iview.css' // 使用 CSS | |
| 5 | 5 | import 'animate.css' | |
| 6 | 6 | import VueI18n from 'vue-i18n' | |
| 7 | - import localeMessage from './common/js/locale' | ||
| 7 | + import localeMessage from '../../src/common/js/locale' | ||
| 8 | 8 | ||
| 9 | 9 | Vue.locale = (locale) => { | |
| 10 | 10 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ export default { | |||
| 19 | 19 | closeDonate: 'Close Donate', | |
| 20 | 20 | feedback: 'Feedback', | |
| 21 | 21 | close: 'No longer show', | |
| 22 | - scriptInstalling: 'Script installing...' | ||
| 22 | + scriptInstalling: 'Script installing...', | ||
| 23 | + search: 'Search' | ||
| 23 | 24 | } | |
| 24 | 25 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments