Skip to content

Commit 964e29e

Browse files
committed
updated api
1 parent f376785 commit 964e29e

File tree

7 files changed

+59
-16
lines changed

7 files changed

+59
-16
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
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?_=1519625029415
21-
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1519625029415
20+
// @resource ui https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.html?_=1520937486364
21+
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1520937486364
22+
// @resource count https://greasyfork.org/scripts/by-site.json
2223
// @grant GM_xmlhttpRequest
2324
// @grant GM_getResourceText
2425
// @grant GM_getValue

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
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?_=1519625029412
21-
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1519625029412
20+
// @resource ui https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.html?_=1520937486364
21+
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_=1520937486364
22+
// @resource count https://greasyfork.org/scripts/by-site.json
2223
// @grant GM_xmlhttpRequest
2324
// @grant GM_getResourceText
2425
// @grant GM_getValue

dist/ui.js

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

src/common/js/tools.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@ export default {
1717
},
1818
dispatchEvent (eventName) {
1919
parent.document.getElementById('jae_userscript_box').dispatchEvent(new Event(eventName))
20+
},
21+
sleep (ms) {
22+
return new Promise(resolve => setTimeout(resolve, ms))
2023
},
2124
// 获取油猴缓存好的脚本数据
2225
getData () {
26+
this.dispatchEvent('fetchData')
2327
let data = sessionStorage.getItem('jae_fetch_userjs_cache')
28+
while(!data) {
29+
data = sessionStorage.getItem('jae_fetch_userjs_cache')
30+
await this.sleep(1000)
31+
}
2432
data = JSON.parse(data)
2533
return data
34+
},
35+
36+
getCount () {
37+
return 12
2638
}
2739
}

src/components/Table.vue

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,16 @@
106106
components: { Info, Indicator },
107107
mounted: function () {
108108
// let host = location.host.split('.').splice(-2).join('.');
109-
/* let host = 'baidu.com'
109+
/**let host = 'baidu.com'
110110
fetch(`https://greasyfork.org/zh-CN/scripts/by-site/${host}.json`)
111111
.then((r) => {
112112
r.json().then((json) => {
113113
this.data = json
114114
})
115-
}) */
116-
this.data = Tools.getData()
115+
})**/
116+
//this.data = Tools.getData()
117+
// this.data = [];
118+
this.count = Tools.getCount()
117119
},
118120
data: function () {
119121
return {
@@ -224,9 +226,6 @@
224226
}
225227
},
226228
watch: {
227-
data (val) {
228-
this.count = val.length
229-
},
230229
showBody (val) {
231230
if (val) {
232231
// 最大化
@@ -244,11 +243,35 @@
244243
close () {
245244
Tools.dispatchEvent('close')
246245
},
246+
247+
getData (callback) {
248+
let host = 'baidu.com'
249+
fetch(`https://greasyfork.org/zh-CN/scripts/by-site/${host}.json`)
250+
.then((r) => {
251+
r.json().then((json) => {
252+
callback(json)
253+
})
254+
})
255+
},
256+
247257
bodySwitch () {
248-
this.showBody = !this.showBody
249-
setTimeout(() => {
250-
this.showTitle = this.showBody
251-
}, 500)
258+
if(this.data.length == 0 && this.showBody == false) {
259+
this.$Spin.show();
260+
Tools.getData((json)=>{
261+
this.data = json
262+
this.$Spin.hide();
263+
this.showBody = !this.showBody
264+
setTimeout(() => {
265+
this.showTitle = this.showBody
266+
}, 500)
267+
})
268+
}else {
269+
this.showBody = !this.showBody
270+
setTimeout(() => {
271+
this.showTitle = this.showBody
272+
}, 500)
273+
}
274+
252275
},
253276
open (url) {
254277
window.open(url)

userscript/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ class FetchUserjs {
8383
sessionStorage.setItem(this.quietKey, 1);
8484
$('#jae_userscript_box').remove();
8585
})
86+
87+
this.addEventListener('fetchData',() => {
88+
console.log('fetchData')
89+
this.getData(this.host)
90+
})
8691
}
8792

8893
execFrameJs(frameWindow) {

userscript/tpl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
{ljs}
1919
// @resource ui https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.html?_={time}
2020
// @resource uiJs https://raw.githubusercontent.com/jae-jae/Show-Site-All-UserJS/master/dist/ui.js?_={time}
21+
// @resource count https://greasyfork.org/scripts/by-site.json
2122
// @grant GM_xmlhttpRequest
2223
// @grant GM_getResourceText
2324
// @grant GM_getValue

0 commit comments

Comments
 (0)