generated from taotao7/userscript-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev.user.js
58 lines (56 loc) · 1.42 KB
/
dev.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* globals GM */
'use strict';
(function () {
const url = `http://localhost:%PORT%/bundle.user.js?${Date.now()}`
new Promise(function loadBundleFromServer (resolve, reject) {
const req = GM.xmlHttpRequest({
method: 'GET',
url: url,
onload: function (r) {
if (r.status !== 200) {
return reject(r)
}
resolve(r.responseText)
},
onerror: e => reject(e)
})
if (req && 'catch' in req) {
req.catch(e => { /* ignore */ })
}
}).catch(function (e) {
const log = function (obj, b) {
let prefix = 'loadBundleFromServer: '
try {
prefix = GM.info.script.name + ': '
} catch (e) {}
if (b) {
console.log(prefix + obj, b)
} else {
console.log(prefix, obj)
}
}
if (e && 'status' in e) {
if (e.status <= 0) {
log('Server is not responding')
GM.getValue('scriptlastsource3948218', false).then(function (src) {
if (src) {
log('%cExecuting cached script version', 'color: Crimson; font-size:x-large;')
/* eslint-disable no-eval */
eval(src)
}
})
} else {
log('HTTP status: ' + e.status)
}
} else {
log(e)
}
}).then(function (s) {
if (s) {
/* eslint-disable no-eval */
eval(`${s}
//# sourceURL=${url}`)
GM.setValue('scriptlastsource3948218', s)
}
})
})()