functionMagicJS(scriptName="MagicJS",logLevel="INFO"){returnnewclass{constructor(){if(this.version="2.2.3.3",this.scriptName=scriptName,this.logLevels={DEBUG:5,INFO:4,NOTIFY:3,WARNING:2,ERROR:1,CRITICAL:0,NONE:-1},this.isLoon="undefined"!=typeof$loon,this.isQuanX="undefined"!=typeof$task,this.isJSBox="undefined"!=typeof$drive,this.isNode="undefined"!=typeofmodule&&!this.isJSBox,this.isSurge="undefined"!=typeof$httpClient&&!this.isLoon,this.node={request:void0,fs:void0,data:{}},this.iOSUserAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1",this.pcUserAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59",this.logLevel=logLevel,this._barkUrl="",this.isNode){this.node.fs=require("fs"),this.node.request=require("request");try{this.node.fs.accessSync("./magic.json",this.node.fs.constants.R_OK|this.node.fs.constants.W_OK)}catch(err){this.node.fs.writeFileSync("./magic.json","{}",{encoding:"utf8"})}this.node.data=require("./magic.json")}elsethis.isJSBox&&($file.exists("drive://MagicJS")||$file.mkdir("drive://MagicJS"),$file.exists("drive://MagicJS/magic.json")||$file.write({data:$data({string:"{}"}),path:"drive://MagicJS/magic.json"}))}setbarkUrl(url){this._barkUrl=url.replace(/\/+$/g,"")}setlogLevel(level){this._logLevel="string"==typeoflevel?level.toUpperCase():"DEBUG"}getlogLevel(){returnthis._logLevel}getisRequest(){return"undefined"!=typeof$request&&"undefined"==typeof$response}getisResponse(){return"undefined"!=typeof$response}getrequest(){return"undefined"!=typeof$request?$request:void0}getresponse(){return"undefined"!=typeof$response?($response.hasOwnProperty("status")&&($response.statusCode=$response.status),$response.hasOwnProperty("statusCode")&&($response.status=$response.statusCode),$response):void0}getplatform(){returnthis.isSurge?"Surge":this.isQuanX?"Quantumult X":this.isLoon?"Loon":this.isJSBox?"JSBox":this.isNode?"Node.js":"Unknown"}read(key,session=""){letval="";this.isSurge||this.isLoon?val=$persistentStore.read(key):this.isQuanX?val=$prefs.valueForKey(key):this.isNode?val=this.node.data:this.isJSBox&&(val=$file.read("drive://MagicJS/magic.json").string);try{this.isNode&&(val=val[key]),this.isJSBox&&(val=JSON.parse(val)[key]),session&&("string"==typeofval&&(val=JSON.parse(val)),val=val&&"object"==typeofval?val[session]:null)}catch(err){this.logError(err),val=session?{}:null,this.del(key)}void0===val&&(val=null);try{val&&"string"==typeofval&&(val=JSON.parse(val))}catch(err){}returnthis.logDebug(`READ DATA [${key}]${session?`[${session}]`:""}(${typeofval})\n${JSON.stringify(val)}`),val}write(key,val,session=""){letdata=session?{}:"";if(session&&(this.isSurge||this.isLoon)?data=$persistentStore.read(key):session&&this.isQuanX?data=$prefs.valueForKey(key):this.isNode?data=this.node.data:this.isJSBox&&(data=JSON.parse($file.read("drive://MagicJS/magic.json").string)),session){try{"string"==typeofdata&&(data=JSON.parse(data)),data="object"==typeofdata&&data?data:{}}catch(err){this.logError(err),this.del(key),data={}}this.isJSBox||this.isNode?(data[key]&&"object"==typeofdata[key]||(data[key]={}),data[key].hasOwnProperty(session)||(data[key][session]=null),void0===val?deletedata[key][session]:data[key][session]=val):void0===val?deletedata[session]:data[session]=val}elsethis.isNode||this.isJSBox?void0===val?deletedata[key]:data[key]=val:data=void0===val?null:val;"object"==typeofdata&&(data=JSON.stringify(data)),this.