| 410 | } |
| 411 | |
| 412 | function tool() { |
| 413 | const isLoon = typeof $loon != "undefined"; |
| 414 | const isSurge = typeof $httpClient != "undefined"; |
| 415 | const isQuanX = typeof $task != "undefined"; |
| 416 | const node = (() => { |
| 417 | if (typeof require == "function") { |
| 418 | const request = require("request"); |
| 419 | return { request }; |
| 420 | } else { |
| 421 | return null; |
| 422 | } |
| 423 | })(); |
| 424 | const notify = (title, subtitle, content, open_url) => { |
| 425 | if (isSurge && !isLoon) { |
| 426 | let opts = {}; |
| 427 | if (open_url) opts["url"] = open_url; |
| 428 | if (JSON.stringify(opts) == "{}") { |
| 429 | $notification.post(title, subtitle, content); |
| 430 | } else { |
| 431 | $notification.post(title, subtitle, content, opts); |
| 432 | } |
| 433 | } |
| 434 | if (isQuanX) { |
| 435 | let opts = {}; |
| 436 | if (open_url) opts["open-url"] = open_url; |
| 437 | if (JSON.stringify(opts) == "{}") { |
| 438 | $notify(title, subtitle, content); |
| 439 | } else { |
| 440 | $notify(title, subtitle, content, opts); |
| 441 | } |
| 442 | } |
| 443 | if (isLoon) { |
| 444 | let opts = {}; |
| 445 | if (open_url) opts["openUrl"] = open_url; |
| 446 | if (JSON.stringify(opts) == "{}") { |
| 447 | $notification.post(title, subtitle, content); |
| 448 | } else { |
| 449 | $notification.post(title, subtitle, content, opts); |
| 450 | } |
| 451 | } |
| 452 | if (node) { |
| 453 | let content_Node = content + (open_url == undefined ? "" : `\n\n跳转链接:${open_url}`); |
| 454 | console.log(`${title}\n${subtitle}\n${content_Node}\n\n`); |
| 455 | } |
| 456 | }; |
| 457 | const setCache = (value, key) => { |
| 458 | if (isQuanX) return $prefs.setValueForKey(value, key); |
| 459 | if (isSurge) return $persistentStore.write(value, key); |
| 460 | }; |
| 461 | const getCache = (key) => { |
| 462 | if (isQuanX) return $prefs.valueForKey(key); |
| 463 | if (isSurge) return $persistentStore.read(key); |
| 464 | }; |
| 465 | const adapterStatus = (response) => { |
| 466 | if (response.status) { |
| 467 | response["statusCode"] = response.status; |
| 468 | } else if (response.statusCode) { |
| 469 | response["status"] = response.statusCode; |