MCPcopy Create free account
hub / github.com/ClydeTime/Surge /

Class

Script/Env.js:2–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1function Env(name, opts) {
2 return new (class {
3 constructor(name, opts) {
4 this.name = name
5 this.version = '1.7.5'
6 this.data = null
7 this.logs = []
8 this.isMute = false
9 this.isNeedRewrite = false
10 this.logSeparator = '\n'
11 this.encoding = 'utf-8'
12 this.startTime = new Date().getTime()
13 Object.assign(this, opts)
14 this.log('', `🔔${this.name}, 开始!`)
15 }
16
17 platform() {
18 if ('undefined' !== typeof $environment && $environment['surge-version'])
19 return 'Surge'
20 if ('undefined' !== typeof $environment && $environment['stash-version'])
21 return 'Stash'
22 if ('undefined' !== typeof module && !!module.exports) return 'Node.js'
23 if ('undefined' !== typeof $task) return 'Quantumult X'
24 if ('undefined' !== typeof $loon) return 'Loon'
25 if ('undefined' !== typeof $rocket) return 'Shadowrocket'
26 if ('undefined' !== typeof Egern) return 'Egern'
27 }
28
29 isQuanX() {
30 return 'Quantumult X' === this.platform()
31 }
32
33 isSurge() {
34 return 'Surge' === this.platform()
35 }
36
37 isLoon() {
38 return 'Loon' === this.platform()
39 }
40
41 isShadowrocket() {
42 return 'Shadowrocket' === this.platform()
43 }
44
45 isStash() {
46 return 'Stash' === this.platform()
47 }
48
49 isEgern() {
50 return 'Egern' === this.platform()
51 }
52
53 toObj(str, defaultValue = null) {
54 try {
55 return JSON.parse(str)
56 } catch {
57 return defaultValue
58 }
59 }
60

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected