forked from NobyDa/Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReal-time-debug.js
64 lines (62 loc) · 1.69 KB
/
Real-time-debug.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
59
60
61
62
63
64
/*
* LAN script real-time debug
*
* PC: Use "Live Server" plugin in VSCode to create a LAN backend
* APP: After backend address is modified in script, use this script as script path
*/
!async function() {
const _$ = new nobyda();
const _r = await new Promise(e => {
_$.get({
url: 'http://192.168.1.66:5500/debug.js' // LAN backend address
}, (t, c, o) => {
if (c && c.status == 200 && o) {
_$.write(o, 'Real-time-debug');
e(o);
}
});
setTimeout(e, 100);
});
if (_r) {
console.log("🌐 Run local network script...");
eval(_r);
} else {
console.log("⚠️ Run cache script...");
eval(_$.read('Real-time-debug'))
}
function nobyda() {
const isSurge = typeof $httpClient != "undefined";
const isQuanX = typeof $task != "undefined";
const adapterStatus = (response) => {
if (response) {
if (response.status) {
response["statusCode"] = response.status
} else if (response.statusCode) {
response["status"] = response.statusCode
}
}
return response
};
this.write = (value, key) => {
if (isQuanX) return $prefs.setValueForKey(value, key);
if (isSurge) return $persistentStore.write(value, key);
};
this.read = (key) => {
if (isQuanX) return $prefs.valueForKey(key);
if (isSurge) return $persistentStore.read(key);
};
this.get = (options, callback) => {
if (isQuanX) {
$task.fetch(options).then(response => {
callback(null, adapterStatus(response), response.body)
}, reason => callback(reason.error, null, null))
}
if (isSurge) {
$httpClient.get(options, (error, response, body) => {
callback(error, adapterStatus(response), body)
})
}
};
this.done = (value = {}) => $done(value)
}
}();