mirror of
https://github.com/xweiba/location-spoofer.git
synced 2026-09-21 22:30:46 +08:00
3 lines
40 KiB
JavaScript
3 lines
40 KiB
JavaScript
/* wloc.js - Build 2026-08-08 21:31:58 */
|
||
const e=(()=>{const e=e=>e in globalThis;switch(!0){case e("$task"):return"Quantumult X";case e("$loon"):return"Loon";case e("$rocket"):return"Shadowrocket";case e("Egern"):return"Egern";case Boolean(globalThis.$environment?.["surge-version"]):return"Surge";case Boolean(globalThis.$environment?.["stash-version"]):return"Stash";case e("Cloudflare"):return"Worker";case Boolean(globalThis.process?.versions?.node):return"Node.js";default:return}})();class t{static#e=new Map([]);static#t=[];static#a=new Map([]);static clear=()=>{};static count=(e="default")=>{switch(t.#e.has(e)){case!0:t.#e.set(e,t.#e.get(e)+1);break;case!1:t.#e.set(e,0)}t.log(`${e}: ${t.#e.get(e)}`)};static countReset=(e="default")=>{switch(t.#e.has(e)){case!0:t.#e.set(e,0),t.log(`${e}: ${t.#e.get(e)}`);break;case!1:t.warn(`Counter "${e}" doesn’t exist`)}};static debug=(...e)=>{t.#r<4||(e=e.map(e=>` ${e}`),t.log(...e))};static error(...a){if(!(t.#r<1)){switch(e){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":case"Quantumult X":default:a=a.map(e=>` ${e}`);break;case"Worker":case"Node.js":a=a.map(e=>` ${e?.stack??e}`)}t.log(...a)}}static exception=(...e)=>t.error(...e);static group=e=>t.#t.unshift(e);static groupEnd=()=>t.#t.shift();static info(...e){t.#r<3||(e=e.map(e=>` ${e}`),t.log(...e))}static#r=3;static get logLevel(){switch(t.#r){case 0:return"OFF";case 1:return"ERROR";case 2:return"WARN";case 3:default:return"INFO";case 4:return"DEBUG";case 5:return"ALL"}}static set logLevel(e){switch(typeof e){case"string":e=e.toLowerCase();break;case"number":break;default:e="warn"}switch(e){case 0:case"off":t.#r=0;break;case 1:case"error":t.#r=1;break;case 2:case"warn":case"warning":default:t.#r=2;break;case 3:case"info":t.#r=3;break;case 4:case"debug":t.#r=4;break;case 5:case"all":t.#r=5}}static log=(...e)=>{0!==t.#r&&(e=e.flatMap(e=>{switch(typeof e){case"object":return[JSON.stringify(e)];case"bigint":case"number":case"boolean":return[e.toString()];case"string":return e.split(/\r?\n/u);default:return[e]}}),t.#t.forEach(t=>{(e=e.map(e=>` ${e}`)).unshift(` ${t}:`)}),e=["",...e],console.log(e.join("\n")))};static time=(e="default")=>t.#a.set(e,Date.now());static timeEnd=(e="default")=>t.#a.delete(e);static timeLog=(e="default")=>{const a=t.#a.get(e);a?t.log(`${e}: ${Date.now()-a}ms`):t.warn(`Timer "${e}" doesn’t exist`)};static warn(...e){t.#r<2||(e=e.map(e=>` ${e}`),t.log(...e))}}class a{static escape(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,e=>t[e])}static get(e={},t="",r=void 0){Array.isArray(t)||(t=a.toPath(t));const n=t.reduce((e,t)=>Object(e)[t],e);return void 0===n?r:n}static merge(e,...t){if(null==e)return e;for(const r of t)if(null!=r)for(const t of Object.keys(r)){const n=r[t],i=e[t];switch(!0){case a.#n(n)&&a.#n(i):e[t]=a.merge(i,n);break;case n instanceof Map&&i instanceof Map:if(n.size>0)for(const[e,t]of n)i.set(e,t);break;case n instanceof Set&&i instanceof Set:if(n.size>0)for(const e of n)i.add(e);break;case Array.isArray(n)&&0===n.length&&void 0!==i:case n instanceof Map&&0===n.size&&void 0!==i:case n instanceof Set&&0===n.size&&void 0!==i:break;case void 0!==n:e[t]=n}}return e}static#n(e){if(null===e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}static omit(e={},t=[]){return Array.isArray(t)||(t=[t.toString()]),t.forEach(t=>a.unset(e,t)),e}static pick(e={},t=[]){Array.isArray(t)||(t=[t.toString()]);const a=Object.entries(e).filter(([e,a])=>t.includes(e));return Object.fromEntries(a)}static set(e,t,r){return Array.isArray(t)||(t=a.toPath(t)),t.slice(0,-1).reduce((e,a,r)=>Object(e[a])===e[a]?e[a]:e[a]=/^\d+$/.test(t[r+1])?[]:{},e)[t[t.length-1]]=r,e}static toPath(e){return e.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean)}static unescape(e){const t={"&":"&","<":"<",">":">",""":'"',"'":"'"};return e.replace(/&|<|>|"|'/g,e=>t[e])}static unset(e={},t=""){Array.isArray(t)||(t=a.toPath(t));return t.reduce((e,a,r)=>r===t.length-1?(delete e[a],!0):Object(e)[a],e)}}class r{static parse(e){let t={};switch(typeof e){case"string":{const n=e.replace(/^\?/,"");if(!n)break;const i=Object.fromEntries(n.split("&").filter(Boolean).map(e=>{const[t="",a=""]=e.split("=",2);return[r.#i(t).replace(/\[([^\[\]]+)\]/g,".$1"),r.#i(a).replace(/\"/g,"")]}));Object.keys(i).forEach(e=>a.set(t,e,i[e]));break}case"object":switch(e){case null:break;default:{const r={};Object.keys(e).forEach(t=>a.set(r,t,e[t])),t=r;break}}break;case"undefined":t={}}return t}static stringify(e={}){if(!e||"object"!=typeof e)return"";const t=[];return Object.keys(e).forEach(a=>r.#o(e,a,t)),0===t.length?"":t.map(([e,t])=>`${r.#s(r.#l(e))}=${r.#s(t)}`).join("&")}static#o(e,t,n){const i=a.get(e,t);void 0!==i&&(null!==i?Array.isArray(i)?i.forEach((a,i)=>{void 0!==a&&r.#o(e,`${t}[${i}]`,n)}):r.#n(i)?Object.keys(i).forEach(a=>r.#o(e,`${t}.${a}`,n)):n.push([t,String(i)]):n.push([t,""]))}static#l(e){const[t,...r]=a.toPath(e);return r.reduce((e,t)=>/^\d+$/.test(t)?`${e}[${t}]`:`${e}.${t}`,t)}static#n(e){if(null===e||"object"!=typeof e||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}static#s(e){return encodeURIComponent(e)}static#i(e){return decodeURIComponent(e.replace(/\+/g," "))}}t.debug(" $argument"),globalThis.$argument=r.parse(globalThis.$argument),globalThis.$argument.LogLevel&&(t.logLevel=globalThis.$argument.LogLevel),t.debug(" $argument",`$argument: ${JSON.stringify(globalThis.$argument)}`);const n={100:"Continue",101:"Switching Protocols",102:"Processing",103:"Early Hints",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",304:"Not Modified",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Content Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",510:"Not Extended",511:"Network Authentication Required"};function i(r={}){switch(e){case"Surge":r.policy&&a.set(r,"headers.X-Surge-Policy",r.policy),t.log(" 执行结束!",` ${(new Date).getTime()/1e3-$script.startTime} 秒`),$done(r);break;case"Loon":r.policy&&(r.node=r.policy),t.log(" 执行结束!",` ${(new Date-$script.startTime)/1e3} 秒`),$done(r);break;case"Stash":r.policy&&a.set(r,"headers.X-Stash-Selected-Proxy",encodeURI(r.policy)),t.log(" 执行结束!",` ${(new Date-$script.startTime)/1e3} 秒`),$done(r);break;case"Egern":case"Shadowrocket":t.log(" 执行结束!"),$done(r);break;case"Quantumult X":switch(r.policy&&a.set(r,"opts.policy",r.policy),typeof(r=a.pick(r,["status","url","headers","body","bodyBytes"])).status){case"number":r.status=`HTTP/1.1 ${r.status} ${n[r.status]}`;break;case"string":case"undefined":break;default:throw new TypeError(`${Function.name}: 参数类型错误, status 必须为数字或字符串`)}r.body instanceof ArrayBuffer?(r.bodyBytes=r.body,r.body=void 0):ArrayBuffer.isView(r.body)?(r.bodyBytes=r.body.buffer.slice(r.body.byteOffset,r.body.byteLength+r.body.byteOffset),r.body=void 0):r.body&&(r.bodyBytes=void 0),t.log(" 执行结束!"),$done(r);break;case"Worker":default:t.log(" 执行结束!");break;case"Node.js":t.log(" 执行结束!"),process.exit(1)}}class o{static data=null;static dataFile="box.dat";static#c=/^@(?<key>[^.]+)(?:\.(?<path>.*))?$/;static getItem(t,r=null){let n=r;switch(t.startsWith("@")){case!0:{const{key:e,path:r}=t.match(o.#c)?.groups;t=e;let i=o.getItem(t,{});"object"!=typeof i&&(i={}),n=a.get(i,r);try{n=JSON.parse(n)}catch{}break}default:switch(e){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":n=$persistentStore.read(t);break;case"Quantumult X":n=$prefs.valueForKey(t);break;case"Worker":o.data=o.data??{},n=o.data[t];break;case"Node.js":o.data=o.#d(o.dataFile),n=o.data?.[t];break;default:n=o.data?.[t]||null}try{n=JSON.parse(n)}catch{}}return n??r}static setItem(t=new String,r=new String){let n=!1;if("object"==typeof r)r=JSON.stringify(r);else r=String(r);switch(t.startsWith("@")){case!0:{const{key:e,path:i}=t.match(o.#c)?.groups;t=e;let s=o.getItem(t,{});"object"!=typeof s&&(s={}),a.set(s,i,r),n=o.setItem(t,s);break}default:switch(e){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":n=$persistentStore.write(r,t);break;case"Quantumult X":n=$prefs.setValueForKey(r,t);break;case"Worker":o.data=o.data??{},o.data[t]=r,n=!0;break;case"Node.js":o.data=o.#d(o.dataFile),o.data[t]=r,o.#u(o.dataFile),n=!0;break;default:n=o.data?.[t]||null}}return n}static removeItem(t){let r=!1;switch(t.startsWith("@")){case!0:{const{key:e,path:n}=t.match(o.#c)?.groups;t=e;let i=o.getItem(t);"object"!=typeof i&&(i={}),a.unset(i,n),r=o.setItem(t,i);break}default:switch(e){case"Surge":r=$persistentStore.write(null,t);break;case"Loon":case"Stash":case"Egern":case"Shadowrocket":default:r=!1;break;case"Quantumult X":r=$prefs.removeValueForKey(t);break;case"Worker":o.data=o.data??{},delete o.data[t],r=!0;break;case"Node.js":o.data=o.#d(o.dataFile),delete o.data[t],o.#u(o.dataFile),r=!0}}return r}static clear(){let t=!1;switch(e){case"Surge":case"Loon":case"Stash":case"Egern":case"Shadowrocket":default:t=!1;break;case"Quantumult X":t=$prefs.removeAllValues();break;case"Worker":o.data={},t=!0;break;case"Node.js":o.data=o.#d(o.dataFile),o.data={},o.#u(o.dataFile),t=!0}return t}static#d=t=>{if("Node.js"!==e)return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(t),a=this.path.resolve(process.cwd(),t),r=this.fs.existsSync(e),n=!r&&this.fs.existsSync(a);if(!r&&!n)return{};{const t=r?e:a;try{return JSON.parse(this.fs.readFileSync(t))}catch(e){return{}}}}};static#u=(t=this.dataFile)=>{if("Node.js"===e){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(t),a=this.path.resolve(process.cwd(),t),r=this.fs.existsSync(e),n=!r&&this.fs.existsSync(a),i=JSON.stringify(this.data);r?this.fs.writeFileSync(e,i):n?this.fs.writeFileSync(a,i):this.fs.writeFileSync(e,i)}}}function s(e){let t=e.length;for(;--t>=0;)e[t]=0}s(new Array(576));s(new Array(60));s(new Array(512));s(new Array(256));s(new Array(29));s(new Array(30));var l=(e,t,a,r)=>{let n=65535&e,i=e>>>16&65535,o=0;for(;0!==a;){o=a>2e3?2e3:a,a-=o;do{n=n+t[r++]|0,i=i+n|0}while(--o);n%=65521,i%=65521}return n|i<<16};const c=new Uint32Array((()=>{let e,t=[];for(var a=0;a<256;a++){e=a;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[a]=e}return t})());var d=(e,t,a,r)=>{const n=c,i=r+a;e^=-1;for(let a=r;a<i;a++)e=e>>>8^n[255&(e^t[a])];return-1^e},u={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},f={Z_NO_FLUSH:0,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_DEFLATED:8};const h=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var w=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const a=t.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(const t in a)h(a,t)&&(e[t]=a[t])}}return e},g=e=>{let t=0;for(let a=0,r=e.length;a<r;a++)t+=e[a].length;const a=new Uint8Array(t);for(let t=0,r=0,n=e.length;t<n;t++){let n=e[t];a.set(n,r),r+=n.length}return a};let p=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){p=!1}const b=new Uint8Array(256);for(let e=0;e<256;e++)b[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;b[254]=b[255]=1;var m=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,a,r,n,i,o=e.length,s=0;for(n=0;n<o;n++)a=e.charCodeAt(n),55296==(64512&a)&&n+1<o&&(r=e.charCodeAt(n+1),56320==(64512&r)&&(a=65536+(a-55296<<10)+(r-56320),n++)),s+=a<128?1:a<2048?2:a<65536?3:4;for(t=new Uint8Array(s),i=0,n=0;i<s;n++)a=e.charCodeAt(n),55296==(64512&a)&&n+1<o&&(r=e.charCodeAt(n+1),56320==(64512&r)&&(a=65536+(a-55296<<10)+(r-56320),n++)),a<128?t[i++]=a:a<2048?(t[i++]=192|a>>>6,t[i++]=128|63&a):a<65536?(t[i++]=224|a>>>12,t[i++]=128|a>>>6&63,t[i++]=128|63&a):(t[i++]=240|a>>>18,t[i++]=128|a>>>12&63,t[i++]=128|a>>>6&63,t[i++]=128|63&a);return t},y=(e,t)=>{const a=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let r,n;const i=new Array(2*a);for(n=0,r=0;r<a;){let t=e[r++];if(t<128){i[n++]=t;continue}let o=b[t];if(o>4)i[n++]=65533,r+=o-1;else{for(t&=2===o?31:3===o?15:7;o>1&&r<a;)t=t<<6|63&e[r++],o--;o>1?i[n++]=65533:t<65536?i[n++]=t:(t-=65536,i[n++]=55296|t>>10&1023,i[n++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&p)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let a="";for(let r=0;r<t;r++)a+=String.fromCharCode(e[r]);return a})(i,n)},k=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let a=t-1;for(;a>=0&&128==(192&e[a]);)a--;return a<0||0===a?t:a+b[e[a]]>t?a:t};var v=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const _=16209;var x=function(e,t){let a,r,n,i,o,s,l,c,d,u,f,h,w,g,p,b,m,y,k,v,x,E,A,$;const R=e.state;a=e.next_in,A=e.input,r=a+(e.avail_in-5),n=e.next_out,$=e.output,i=n-(t-e.avail_out),o=n+(e.avail_out-257),s=R.dmax,l=R.wsize,c=R.whave,d=R.wnext,u=R.window,f=R.hold,h=R.bits,w=R.lencode,g=R.distcode,p=(1<<R.lenbits)-1,b=(1<<R.distbits)-1;e:do{h<15&&(f+=A[a++]<<h,h+=8,f+=A[a++]<<h,h+=8),m=w[f&p];t:for(;;){if(y=m>>>24,f>>>=y,h-=y,y=m>>>16&255,0===y)$[n++]=65535&m;else{if(!(16&y)){if(64&y){if(32&y){R.mode=16191;break e}e.msg="invalid literal/length code",R.mode=_;break e}m=w[(65535&m)+(f&(1<<y)-1)];continue t}for(k=65535&m,y&=15,y&&(h<y&&(f+=A[a++]<<h,h+=8),k+=f&(1<<y)-1,f>>>=y,h-=y),h<15&&(f+=A[a++]<<h,h+=8,f+=A[a++]<<h,h+=8),m=g[f&b];;){if(y=m>>>24,f>>>=y,h-=y,y=m>>>16&255,16&y){if(v=65535&m,y&=15,h<y&&(f+=A[a++]<<h,h+=8,h<y&&(f+=A[a++]<<h,h+=8)),v+=f&(1<<y)-1,v>s){e.msg="invalid distance too far back",R.mode=_;break e}if(f>>>=y,h-=y,y=n-i,v>y){if(y=v-y,y>c&&R.sane){e.msg="invalid distance too far back",R.mode=_;break e}if(x=0,E=u,0===d){if(x+=l-y,y<k){k-=y;do{$[n++]=u[x++]}while(--y);x=n-v,E=$}}else if(d<y){if(x+=l+d-y,y-=d,y<k){k-=y;do{$[n++]=u[x++]}while(--y);if(x=0,d<k){y=d,k-=y;do{$[n++]=u[x++]}while(--y);x=n-v,E=$}}}else if(x+=d-y,y<k){k-=y;do{$[n++]=u[x++]}while(--y);x=n-v,E=$}for(;k>2;)$[n++]=E[x++],$[n++]=E[x++],$[n++]=E[x++],k-=3;k&&($[n++]=E[x++],k>1&&($[n++]=E[x++]))}else{x=n-v;do{$[n++]=$[x++],$[n++]=$[x++],$[n++]=$[x++],k-=3}while(k>2);k&&($[n++]=$[x++],k>1&&($[n++]=$[x++]))}break}if(64&y){e.msg="invalid distance code",R.mode=_;break e}m=g[(65535&m)+(f&(1<<y)-1)]}}break}}while(a<r&&n<o);k=h>>3,a-=k,h-=k<<3,f&=(1<<h)-1,e.next_in=a,e.next_out=n,e.avail_in=a<r?r-a+5:5-(a-r),e.avail_out=n<o?o-n+257:257-(n-o),R.hold=f,R.bits=h};const E=15,A=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),$=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,199,75]),R=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),S=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var T=(e,t,a,r,n,i,o,s)=>{const l=s.bits;let c,d,u,f,h,w,g=0,p=0,b=0,m=0,y=0,k=0,v=0,_=0,x=0,T=0,N=null;const M=new Uint16Array(16),O=new Uint16Array(16);let j,F,I,L=null;for(g=0;g<=E;g++)M[g]=0;for(p=0;p<r;p++)M[t[a+p]]++;for(y=l,m=E;m>=1&&0===M[m];m--);if(y>m&&(y=m),0===m)return n[i++]=20971520,n[i++]=20971520,s.bits=1,0;for(b=1;b<m&&0===M[b];b++);for(y<b&&(y=b),_=1,g=1;g<=E;g++)if(_<<=1,_-=M[g],_<0)return-1;if(_>0&&(0===e||1!==m))return-1;for(O[1]=0,g=1;g<E;g++)O[g+1]=O[g]+M[g];for(p=0;p<r;p++)0!==t[a+p]&&(o[O[t[a+p]]++]=p);if(0===e?(N=L=o,w=20):1===e?(N=A,L=$,w=257):(N=R,L=S,w=0),T=0,p=0,g=b,h=i,k=y,v=0,u=-1,x=1<<y,f=x-1,1===e&&x>852||2===e&&x>592)return 1;for(;;){j=g-v,o[p]+1<w?(F=0,I=o[p]):o[p]>=w?(F=L[o[p]-w],I=N[o[p]-w]):(F=96,I=0),c=1<<g-v,d=1<<k,b=d;do{d-=c,n[h+(T>>v)+d]=j<<24|F<<16|I}while(0!==d);for(c=1<<g-1;T&c;)c>>=1;if(0!==c?(T&=c-1,T+=c):T=0,p++,0===--M[g]){if(g===m)break;g=t[a+o[p]]}if(g>y&&(T&f)!==u){for(0===v&&(v=y),h+=b,k=g-v,_=1<<k;k+v<m&&(_-=M[k+v],!(_<=0));)k++,_<<=1;if(x+=1<<k,1===e&&x>852||2===e&&x>592)return 1;u=T&f,n[u]=y<<24|k<<16|h-i}}return 0!==T&&(n[h+T]=g-v<<24|64<<16),s.bits=y,0};const{Z_FINISH:N,Z_BLOCK:M,Z_TREES:O,Z_OK:j,Z_STREAM_END:F,Z_NEED_DICT:I,Z_STREAM_ERROR:L,Z_DATA_ERROR:B,Z_MEM_ERROR:C,Z_BUF_ERROR:U,Z_DEFLATED:P}=f,D=16180,Z=16190,z=16191,q=16192,H=16194,W=16199,K=16200,X=16206,Q=16209,V=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function J(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const G=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode<D||t.mode>16211?1:0},Y=e=>{if(G(e))return L;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=D,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,j},ee=e=>{if(G(e))return L;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,Y(e)},te=(e,t)=>{let a;if(G(e))return L;const r=e.state;return t<0?(a=0,t=-t):(a=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?L:(null!==r.window&&r.wbits!==t&&(r.window=null),r.wrap=a,r.wbits=t,ee(e))},ae=(e,t)=>{if(!e)return L;const a=new J;e.state=a,a.strm=e,a.window=null,a.mode=D;const r=te(e,t);return r!==j&&(e.state=null),r};let re,ne,ie=!0;const oe=e=>{if(ie){re=new Int32Array(512),ne=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(T(1,e.lens,0,288,re,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;T(2,e.lens,0,32,ne,0,e.work,{bits:5}),ie=!1}e.lencode=re,e.lenbits=9,e.distcode=ne,e.distbits=5},se=(e,t,a,r)=>{let n;const i=e.state;return null===i.window&&(i.window=new Uint8Array(1<<i.wbits)),0===i.wsize&&(i.wsize=1<<i.wbits,i.wnext=0,i.whave=0),r>=i.wsize?(i.window.set(t.subarray(a-i.wsize,a),0),i.wnext=0,i.whave=i.wsize):(n=i.wsize-i.wnext,n>r&&(n=r),i.window.set(t.subarray(a-r,a-r+n),i.wnext),(r-=n)?(i.window.set(t.subarray(a-r,a),0),i.wnext=r,i.whave=i.wsize):(i.wnext+=n,i.wnext===i.wsize&&(i.wnext=0),i.whave<i.wsize&&(i.whave+=n))),0};var le={inflateReset:ee,inflateReset2:te,inflateResetKeep:Y,inflateInit:e=>ae(e,15),inflateInit2:ae,inflate:(e,t)=>{let a,r,n,i,o,s,c,u,f,h,w,g,p,b,m,y,k,v,_,E,A,$,R=0;const S=new Uint8Array(4);let J,Y;const ee=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(G(e)||!e.output||!e.input&&0!==e.avail_in)return L;a=e.state,a.mode===z&&(a.mode=q),o=e.next_out,n=e.output,c=e.avail_out,i=e.next_in,r=e.input,s=e.avail_in,u=a.hold,f=a.bits,h=s,w=c,$=j;e:for(;;)switch(a.mode){case D:if(0===a.wrap){a.mode=q;break}for(;f<16;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(2&a.wrap&&35615===u){0===a.wbits&&(a.wbits=15),a.check=0,S[0]=255&u,S[1]=u>>>8&255,a.check=d(a.check,S,2,0),u=0,f=0,a.mode=16181;break}if(a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",a.mode=Q;break}if((15&u)!==P){e.msg="unknown compression method",a.mode=Q;break}if(u>>>=4,f-=4,A=8+(15&u),0===a.wbits&&(a.wbits=A),A>15||A>a.wbits){e.msg="invalid window size",a.mode=Q;break}a.dmax=1<<a.wbits,a.flags=0,e.adler=a.check=1,a.mode=512&u?16189:z,u=0,f=0;break;case 16181:for(;f<16;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(a.flags=u,(255&a.flags)!==P){e.msg="unknown compression method",a.mode=Q;break}if(57344&a.flags){e.msg="unknown header flags set",a.mode=Q;break}a.head&&(a.head.text=u>>8&1),512&a.flags&&4&a.wrap&&(S[0]=255&u,S[1]=u>>>8&255,a.check=d(a.check,S,2,0)),u=0,f=0,a.mode=16182;case 16182:for(;f<32;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}a.head&&(a.head.time=u),512&a.flags&&4&a.wrap&&(S[0]=255&u,S[1]=u>>>8&255,S[2]=u>>>16&255,S[3]=u>>>24&255,a.check=d(a.check,S,4,0)),u=0,f=0,a.mode=16183;case 16183:for(;f<16;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}a.head&&(a.head.xflags=255&u,a.head.os=u>>8),512&a.flags&&4&a.wrap&&(S[0]=255&u,S[1]=u>>>8&255,a.check=d(a.check,S,2,0)),u=0,f=0,a.mode=16184;case 16184:if(1024&a.flags){for(;f<16;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}a.length=u,a.head&&(a.head.extra_len=u),512&a.flags&&4&a.wrap&&(S[0]=255&u,S[1]=u>>>8&255,a.check=d(a.check,S,2,0)),u=0,f=0}else a.head&&(a.head.extra=null);a.mode=16185;case 16185:if(1024&a.flags&&(g=a.length,g>s&&(g=s),g&&(a.head&&(A=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(r.subarray(i,i+g),A)),512&a.flags&&4&a.wrap&&(a.check=d(a.check,r,g,i)),s-=g,i+=g,a.length-=g),a.length))break e;a.length=0,a.mode=16186;case 16186:if(2048&a.flags){if(0===s)break e;g=0;do{A=r[i+g++],a.head&&A&&a.length<65536&&(a.head.name+=String.fromCharCode(A))}while(A&&g<s);if(512&a.flags&&4&a.wrap&&(a.check=d(a.check,r,g,i)),s-=g,i+=g,A)break e}else a.head&&(a.head.name=null);a.length=0,a.mode=16187;case 16187:if(4096&a.flags){if(0===s)break e;g=0;do{A=r[i+g++],a.head&&A&&a.length<65536&&(a.head.comment+=String.fromCharCode(A))}while(A&&g<s);if(512&a.flags&&4&a.wrap&&(a.check=d(a.check,r,g,i)),s-=g,i+=g,A)break e}else a.head&&(a.head.comment=null);a.mode=16188;case 16188:if(512&a.flags){for(;f<16;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(4&a.wrap&&u!==(65535&a.check)){e.msg="header crc mismatch",a.mode=Q;break}u=0,f=0}a.head&&(a.head.hcrc=a.flags>>9&1,a.head.done=!0),e.adler=a.check=0,a.mode=z;break;case 16189:for(;f<32;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}e.adler=a.check=V(u),u=0,f=0,a.mode=Z;case Z:if(0===a.havedict)return e.next_out=o,e.avail_out=c,e.next_in=i,e.avail_in=s,a.hold=u,a.bits=f,I;e.adler=a.check=1,a.mode=z;case z:if(t===M||t===O)break e;case q:if(a.last){u>>>=7&f,f-=7&f,a.mode=X;break}for(;f<3;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}switch(a.last=1&u,u>>>=1,f-=1,3&u){case 0:a.mode=16193;break;case 1:if(oe(a),a.mode=W,t===O){u>>>=2,f-=2;break e}break;case 2:a.mode=16196;break;case 3:e.msg="invalid block type",a.mode=Q}u>>>=2,f-=2;break;case 16193:for(u>>>=7&f,f-=7&f;f<32;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if((65535&u)!=(u>>>16^65535)){e.msg="invalid stored block lengths",a.mode=Q;break}if(a.length=65535&u,u=0,f=0,a.mode=H,t===O)break e;case H:a.mode=16195;case 16195:if(g=a.length,g){if(g>s&&(g=s),g>c&&(g=c),0===g)break e;n.set(r.subarray(i,i+g),o),s-=g,i+=g,c-=g,o+=g,a.length-=g;break}a.mode=z;break;case 16196:for(;f<14;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(a.nlen=257+(31&u),u>>>=5,f-=5,a.ndist=1+(31&u),u>>>=5,f-=5,a.ncode=4+(15&u),u>>>=4,f-=4,a.nlen>286||a.ndist>30){e.msg="too many length or distance symbols",a.mode=Q;break}a.have=0,a.mode=16197;case 16197:for(;a.have<a.ncode;){for(;f<3;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}a.lens[ee[a.have++]]=7&u,u>>>=3,f-=3}for(;a.have<19;)a.lens[ee[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,J={bits:a.lenbits},$=T(0,a.lens,0,19,a.lencode,0,a.work,J),a.lenbits=J.bits,$){e.msg="invalid code lengths set",a.mode=Q;break}a.have=0,a.mode=16198;case 16198:for(;a.have<a.nlen+a.ndist;){for(;R=a.lencode[u&(1<<a.lenbits)-1],m=R>>>24,y=R>>>16&255,k=65535&R,!(m<=f);){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(k<16)u>>>=m,f-=m,a.lens[a.have++]=k;else{if(16===k){for(Y=m+2;f<Y;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(u>>>=m,f-=m,0===a.have){e.msg="invalid bit length repeat",a.mode=Q;break}A=a.lens[a.have-1],g=3+(3&u),u>>>=2,f-=2}else if(17===k){for(Y=m+3;f<Y;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}u>>>=m,f-=m,A=0,g=3+(7&u),u>>>=3,f-=3}else{for(Y=m+7;f<Y;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}u>>>=m,f-=m,A=0,g=11+(127&u),u>>>=7,f-=7}if(a.have+g>a.nlen+a.ndist){e.msg="invalid bit length repeat",a.mode=Q;break}for(;g--;)a.lens[a.have++]=A}}if(a.mode===Q)break;if(0===a.lens[256]){e.msg="invalid code -- missing end-of-block",a.mode=Q;break}if(a.lenbits=9,J={bits:a.lenbits},$=T(1,a.lens,0,a.nlen,a.lencode,0,a.work,J),a.lenbits=J.bits,$){e.msg="invalid literal/lengths set",a.mode=Q;break}if(a.distbits=6,a.distcode=a.distdyn,J={bits:a.distbits},$=T(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,J),a.distbits=J.bits,$){e.msg="invalid distances set",a.mode=Q;break}if(a.mode=W,t===O)break e;case W:a.mode=K;case K:if(s>=6&&c>=258){e.next_out=o,e.avail_out=c,e.next_in=i,e.avail_in=s,a.hold=u,a.bits=f,x(e,w),o=e.next_out,n=e.output,c=e.avail_out,i=e.next_in,r=e.input,s=e.avail_in,u=a.hold,f=a.bits,a.mode===z&&(a.back=-1);break}for(a.back=0;R=a.lencode[u&(1<<a.lenbits)-1],m=R>>>24,y=R>>>16&255,k=65535&R,!(m<=f);){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(y&&!(240&y)){for(v=m,_=y,E=k;R=a.lencode[E+((u&(1<<v+_)-1)>>v)],m=R>>>24,y=R>>>16&255,k=65535&R,!(v+m<=f);){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}u>>>=v,f-=v,a.back+=v}if(u>>>=m,f-=m,a.back+=m,a.length=k,0===y){a.mode=16205;break}if(32&y){a.back=-1,a.mode=z;break}if(64&y){e.msg="invalid literal/length code",a.mode=Q;break}a.extra=15&y,a.mode=16201;case 16201:if(a.extra){for(Y=a.extra;f<Y;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}a.length+=u&(1<<a.extra)-1,u>>>=a.extra,f-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=16202;case 16202:for(;R=a.distcode[u&(1<<a.distbits)-1],m=R>>>24,y=R>>>16&255,k=65535&R,!(m<=f);){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(!(240&y)){for(v=m,_=y,E=k;R=a.distcode[E+((u&(1<<v+_)-1)>>v)],m=R>>>24,y=R>>>16&255,k=65535&R,!(v+m<=f);){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}u>>>=v,f-=v,a.back+=v}if(u>>>=m,f-=m,a.back+=m,64&y){e.msg="invalid distance code",a.mode=Q;break}a.offset=k,a.extra=15&y,a.mode=16203;case 16203:if(a.extra){for(Y=a.extra;f<Y;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}a.offset+=u&(1<<a.extra)-1,u>>>=a.extra,f-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){e.msg="invalid distance too far back",a.mode=Q;break}a.mode=16204;case 16204:if(0===c)break e;if(g=w-c,a.offset>g){if(g=a.offset-g,g>a.whave&&a.sane){e.msg="invalid distance too far back",a.mode=Q;break}g>a.wnext?(g-=a.wnext,p=a.wsize-g):p=a.wnext-g,g>a.length&&(g=a.length),b=a.window}else b=n,p=o-a.offset,g=a.length;g>c&&(g=c),c-=g,a.length-=g;do{n[o++]=b[p++]}while(--g);0===a.length&&(a.mode=K);break;case 16205:if(0===c)break e;n[o++]=a.length,c--,a.mode=K;break;case X:if(a.wrap){for(;f<32;){if(0===s)break e;s--,u|=r[i++]<<f,f+=8}if(w-=c,e.total_out+=w,a.total+=w,4&a.wrap&&w&&(e.adler=a.check=a.flags?d(a.check,n,w,o-w):l(a.check,n,w,o-w)),w=c,4&a.wrap&&(a.flags?u:V(u))!==a.check){e.msg="incorrect data check",a.mode=Q;break}u=0,f=0}a.mode=16207;case 16207:if(a.wrap&&a.flags){for(;f<32;){if(0===s)break e;s--,u+=r[i++]<<f,f+=8}if(4&a.wrap&&u!==(4294967295&a.total)){e.msg="incorrect length check",a.mode=Q;break}u=0,f=0}a.mode=16208;case 16208:$=F;break e;case Q:$=B;break e;case 16210:return C;default:return L}return e.next_out=o,e.avail_out=c,e.next_in=i,e.avail_in=s,a.hold=u,a.bits=f,(a.wsize||w!==e.avail_out&&a.mode<Q&&(a.mode<X||t!==N))&&se(e,e.output,e.next_out,w-e.avail_out),h-=e.avail_in,w-=e.avail_out,e.total_in+=h,e.total_out+=w,a.total+=w,4&a.wrap&&w&&(e.adler=a.check=a.flags?d(a.check,n,w,e.next_out-w):l(a.check,n,w,e.next_out-w)),e.data_type=a.bits+(a.last?64:0)+(a.mode===z?128:0)+(a.mode===W||a.mode===H?256:0),(0===h&&0===w||t===N)&&$===j&&($=U),$},inflateEnd:e=>{if(G(e))return L;let t=e.state;return t.window&&(t.window=null),e.state=null,j},inflateGetHeader:(e,t)=>{if(G(e))return L;const a=e.state;return 2&a.wrap?(a.head=t,t.done=!1,j):L},inflateSetDictionary:(e,t)=>{const a=t.length;let r,n,i;return G(e)?L:(r=e.state,0!==r.wrap&&r.mode!==Z?L:r.mode===Z&&(n=1,n=l(n,t,a,0),n!==r.check)?B:(i=se(e,t,a,a),i?(r.mode=16210,C):(r.havedict=1,j)))},inflateInfo:"pako inflate (from Nodeca project)"};var ce=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const de=Object.prototype.toString,{Z_NO_FLUSH:ue,Z_FINISH:fe,Z_OK:he,Z_STREAM_END:we,Z_NEED_DICT:ge,Z_STREAM_ERROR:pe,Z_DATA_ERROR:be,Z_MEM_ERROR:me,Z_BUF_ERROR:ye}=f,ke={chunkSize:65536,windowBits:15,to:""};function ve(e){this.options=w({},ke,e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(15&t.windowBits||(t.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new v,this.strm.avail_out=0;let a=le.inflateInit2(this.strm,t.windowBits);if(a!==he)throw new Error(u[a]);if(this.header=new ce,le.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=m(t.dictionary):"[object ArrayBuffer]"===de.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(a=le.inflateSetDictionary(this.strm,t.dictionary),a!==he)))throw new Error(u[a])}ve.prototype.push=function(e,t){const a=this.strm,r=this.options.chunkSize,n=this.options.dictionary;let i,o,s;if(this.ended)return!1;for(o=t===~~t?t:!0===t?fe:ue,"[object ArrayBuffer]"===de.call(e)?a.input=new Uint8Array(e):a.input=e,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(r),a.next_out=0,a.avail_out=r),i=le.inflate(a,o),i===ge&&n&&(i=le.inflateSetDictionary(a,n),i===he?i=le.inflate(a,o):i===be&&(i=ge));a.avail_in>0&&i===we&&2&a.state.wrap&&0!==a.state.flags&&0!==a.input[a.next_in];)le.inflateReset(a),i=le.inflate(a,o);switch(i){case pe:case be:case ge:case me:return this.onEnd(i),this.ended=!0,!1}if(s=a.avail_out,a.next_out&&(0===a.avail_out||i===we||o>0))if("string"===this.options.to){let e=k(a.output,a.next_out),t=a.next_out-e,n=y(a.output,e);a.next_out=t,a.avail_out=r-t,t&&a.output.set(a.output.subarray(e,e+t),0),this.onData(n)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out)),a.avail_out=0,a.next_out=0;if(i!==he&&i!==ye||0!==s){if(i===we)return i=le.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,!0;if(0===a.avail_in){if(o===fe)return i=le.inflateEnd(this.strm),this.onEnd(i===he?ye:i),this.ended=!0,!1;break}}}return!0},ve.prototype.onData=function(e){this.chunks.push(e)},ve.prototype.onEnd=function(e){e===he&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=g(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var _e={ungzip:function(e,t){const a=new ve(t);if(a.push(e,!0),a.err)throw a.msg||u[a.err];return a.result}};const{ungzip:xe}=_e;var Ee=xe;function Ae(e,t){let a=0,r=1,n=0;for(;t<e.length;){const i=255&e[t++];if(n<56&&(a+=(127&i)*r),!(128&i))return[a,t];if(r*=128,n+=7,n>=70)throw new Error("varint too long at "+t)}throw new Error("truncated varint")}function $e(e){let t=Math.floor(e);if(t>=0){const e=[];for(;t>=128;)e.push(t%128|128),t=Math.floor(t/128);return e.push(t),e}const a=[0,0,0,0,0,0,0,0];let r=-t;for(let e=0;e<8;e++)a[e]=255&r,r=Math.floor(r/256);let n=1;for(let e=0;e<8;e++){const t=(255&~a[e])+n;a[e]=255&t,n=t>>8}const i=[];for(let e=0;e<10;e++){let t=0;for(let r=0;r<7;r++){const n=7*e+r;n<64&&(t|=(a[n>>3]>>(7&n)&1)<<r)}e<9&&(t|=128),i.push(t)}return i}function Re(e){const t=[];for(let a=0;a<e.length;a++)for(let r=0;r<e[a].length;r++)t.push(255&e[a][r]);return t}function Se(e){const t=[];let a=0;for(;a<e.length;){const r=a,[n,i]=Ae(e,a);a=i;const o=Math.floor(n/8),s=7&n;if(0===o)throw new Error("invalid protobuf field 0 at "+r);let l;if(0===s){const[t,r]=Ae(e,a);l=t,a=r}else if(1===s)l=e.slice(a,a+8),a+=8;else if(2===s){const[t,r]=Ae(e,a);a=r,l=e.slice(a,a+t),a+=t}else{if(5!==s)throw new Error("unsupported wire type "+s);l=e.slice(a,a+4),a+=4}t.push({fieldNo:o,wireType:s,value:l,raw:e.slice(r,a)})}return t}function Te(e,t,a){const r=$e(8*e+t);if(0===t)return Re([r,$e(a)]);if(1===t||5===t)return Re([r,a]);if(2===t)return Re([r,$e(a.length),a]);throw new Error("cannot encode wire type "+t)}function Ne(e,t,a){const r=Se(e);let n=!1,i=!1;for(const e of r)1===e.fieldNo&&0===e.wireType&&(n=!0),2===e.fieldNo&&0===e.wireType&&(i=!0);if(!n||!i)return e;const o=[];for(const e of r)1===e.fieldNo&&0===e.wireType?o.push(Te(1,0,Math.round(1e8*t.latitude))):2===e.fieldNo&&0===e.wireType?o.push(Te(2,0,Math.round(1e8*t.longitude))):3===e.fieldNo&&0===e.wireType?o.push(Te(3,0,t.accuracy)):o.push(e.raw);return a.locations++,Re(o)}function Me(e,t,a){const r=Se(e);let n=!1;for(const e of r)if(1===e.fieldNo&&2===e.wireType){const t=Array.from(e.value).map(e=>String.fromCharCode(255&e)).join("");n=/^[0-9a-fA-F]{1,2}(:[0-9a-fA-F]{1,2}){5}$/.test(t)}if(!n)return e;let i=!1;const o=[];for(const e of r)if(2===e.fieldNo&&2===e.wireType)try{const r=Ne(e.value,t,a);r.length===e.value.length&&r.join(",")===e.value.join(",")||(i=!0),o.push(Te(e.fieldNo,e.wireType,r))}catch{a.skipped++,o.push(e.raw)}else o.push(e.raw);return i&&a.wifi++,Re(o)}function Oe(e,t,a){const r=Se(e);let n=!1;const i=[];for(const e of r)if(5===e.fieldNo&&2===e.wireType)try{const r=Ne(e.value,t,a);r.length===e.value.length&&r.join(",")===e.value.join(",")||(n=!0),i.push(Te(e.fieldNo,e.wireType,r))}catch{a.skipped++,i.push(e.raw)}else i.push(e.raw);return n&&a.cell++,Re(i)}function je(e,t,a){const r=Se(e),n=[];for(const e of r)2===e.wireType&&2===e.fieldNo?n.push(Te(e.fieldNo,e.wireType,Me(e.value,t,a))):2!==e.wireType||22!==e.fieldNo&&24!==e.fieldNo?n.push(e.raw):n.push(Te(e.fieldNo,e.wireType,Oe(e.value,t,a)));return Re(n)}function Fe(e){return{wifi:e.wifi||0,cell:e.cell||0,locations:e.locations||0,skipped:e.skipped||0}}function Ie(e,t){e.wifi=t.wifi,e.cell=t.cell,e.locations=t.locations,e.skipped=t.skipped}function Le(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}function Be(e,t,a,r){if(e.length<t+10)throw new Error("body too short: "+e.length+", base="+t);const n=(255&e[t+8])<<8|255&e[t+9];if(n<=0)throw new Error("invalid empty frame length at "+t);if(n+t+10>e.length)throw new Error("invalid frame length "+n+" at "+t+" for "+e.length);const i=e.slice(0,t+8),o=e.slice(t+10,t+10+n),s=e.slice(t+10+n),l=Fe(r),c=je(o,a,r),d=r.locations-l.locations+(r.wifi-l.wifi)+(r.cell-l.cell);if(c.length>65535)throw new Error("patched payload too large: "+c.length);if(d<=0||Le(o,c))throw Ie(r,l),new Error("frame parsed but no patchable wloc payload at "+t);return Re([i,[c.length>>8&255,255&c.length],c,s])}function Ce(e,a){const r={wifi:0,cell:0,locations:0,skipped:0};if(e.length<10)throw new Error("body too short: "+e.length);const n=[],i=[0,2,4,6,8,10,12,14,16],o=Math.min(96,Math.max(0,e.length-10));for(let e=0;e<=o;e++)i.indexOf(e)<0&&i.push(e);for(let o=0;o<i.length;o++){const s=i[o],l=Fe(r);try{const n=Be(e,s,a,r);return t.info(`[wloc] patched at offset=${s} locations=${r.locations} wifi=${r.wifi} cell=${r.cell} skipped=${r.skipped}`),{data:n,stats:r}}catch(e){Ie(r,l),n.length<6&&n.push("@"+s+":"+(e&&e.message?e.message:String(e)))}}try{const n=function(e,t,a){const r=[],n=Math.min(256,e.length);for(let i=0;i<=n;i++){const n=Fe(a);try{const r=e.slice(i),o=je(r,t,a);if(a.locations-n.locations+(a.wifi-n.wifi)+(a.cell-n.cell)>0&&!Le(r,o))return Re([e.slice(0,i),o]);Ie(a,n)}catch(e){Ie(a,n),r.length<6&&r.push("raw@"+i+":"+(e&&e.message?e.message:String(e)))}}throw new Error("raw protobuf scan failed; "+r.join(" | "))}(e,a,r);return t.info(`[wloc] patched via raw fallback locations=${r.locations} wifi=${r.wifi} cell=${r.cell} skipped=${r.skipped}`),{data:n,stats:r}}catch(e){n.push("raw:"+(e&&e.message?e.message:String(e)))}throw new Error("no patchable wloc payload found; "+n.join(" | "))}function Ue(e){return e.length>=2&&31===e[0]&&139===e[1]}async function Pe(e,a,r){const n=e.url||"";t.group(`[wloc] Response ${n}`);try{let e=function(e){if(!e)return[];if("undefined"!=typeof ArrayBuffer){if(e instanceof ArrayBuffer)return Array.prototype.slice.call(new Uint8Array(e));if(ArrayBuffer.isView&&ArrayBuffer.isView(e))return Array.prototype.slice.call(new Uint8Array(e.buffer,e.byteOffset,e.byteLength))}if("number"==typeof e.length&&"string"!=typeof e){const t=[];for(let a=0;a<e.length;a++)t.push(255&e[a]);return t}if("string"==typeof e){const t=[];for(let a=0;a<e.length;a++)t.push(255&e.charCodeAt(a));return t}return[]}(a.bodyBytes||a.rawBody||a.body);if(!e.length)return t.warn("[wloc] 无二进制 body,跳过"),a;if(t.debug(`[wloc] input length=${e.length} gzip=${Ue(e)}`),null==r.longitude||null==r.latitude)return t.info("[wloc] 透传模式:未设置坐标,不修改响应(恢复真实定位)"),a;let n=e;Ue(e)&&(n=Array.from(Ee(new Uint8Array(e))));const i=function(e){const t=Number(e.randomRadius);if(!Number.isFinite(t)||t<=0)return e;const a=Math.sqrt(Math.random())*t,r=2*Math.random()*Math.PI,n=a/6378137,i=e.latitude*Math.PI/180,o=e.longitude*Math.PI/180,s=Math.asin(Math.sin(i)*Math.cos(n)+Math.cos(i)*Math.sin(n)*Math.cos(r)),l=(o+Math.atan2(Math.sin(r)*Math.sin(n)*Math.cos(i),Math.cos(n)-Math.sin(i)*Math.sin(s))+3*Math.PI)%(2*Math.PI)-Math.PI;return{...e,longitude:Number((180*l/Math.PI).toFixed(8)),latitude:Number((180*s/Math.PI).toFixed(8)),randomDistance:a}}(r),{data:o,stats:s}=Ce(n,i),l=new Uint8Array(o);return a.body=l,a.bodyBytes=l,a.rawBody=l,a.headers&&(delete a.headers["Content-Encoding"],delete a.headers["content-encoding"],delete a.headers["Transfer-Encoding"],delete a.headers["transfer-encoding"],a.headers["Content-Length"]=String(l.length)),a.status=200,a.statusCode=200,t.info(`[wloc] 目标坐标: ${i.longitude},${i.latitude} 精度=${i.accuracy} 扰动=${i.randomDistance?.toFixed(1)||0}m patched=${s.locations}`),a}catch(e){return t.error(`[wloc] ${e.message||e}`),a}finally{t.groupEnd()}}const De={longitude:null,latitude:null,accuracy:25,randomRadius:0,logLevel:"info"};function Ze(){const e=globalThis.$argument||{},a=function(){try{const e=o.getItem("wloc_settings");if(e&&"object"==typeof e)return e}catch(e){t.debug(`[settings] 持久化数据读取失败: ${e.message}`)}return null}(),r={...De};if(e.longitude&&(r.longitude=parseFloat(e.longitude)),e.latitude&&(r.latitude=parseFloat(e.latitude)),e.accuracy&&(r.accuracy=parseInt(e.accuracy,10)),void 0!==e.randomRadius&&(r.randomRadius=parseFloat(e.randomRadius)),e.logLevel&&(r.logLevel=e.logLevel),e.LogLevel&&(r.logLevel=e.LogLevel),a)a.longitude&&(r.longitude=parseFloat(a.longitude)),a.latitude&&(r.latitude=parseFloat(a.latitude)),a.accuracy&&(r.accuracy=parseInt(a.accuracy,10)),void 0!==a.randomRadius&&(r.randomRadius=parseFloat(a.randomRadius)),t.info(`[settings] 使用已保存坐标: ${r.longitude},${r.latitude}`);else if(113.94114===r.longitude&&22.544577===r.latitude)return r.longitude=null,r.latitude=null,t.info("[settings] 透传模式:持久化数据为空且为默认参数,不修改定位"),r;return null==r.longitude||null==r.latitude?t.info("[settings] 透传模式:未设置坐标,将不修改定位响应"):t.debug(`[settings] lon=${r.longitude} lat=${r.latitude} acc=${r.accuracy} randomRadius=${r.randomRadius}`),r}let ze;(async()=>{const e=function(){try{return"undefined"!=typeof $response?$response:void 0}catch{return}}();if(!e)return void t.warn("[wloc] 非响应模式,跳过");const a=Ze();t.logLevel=a.logLevel,ze=await Pe($request,e,a)})().catch(e=>t.error(e)).finally(()=>{switch(typeof ze){case"object":ze.headers?.["Content-Encoding"]&&(ze.headers["Content-Encoding"]="identity"),ze.headers?.["content-encoding"]&&(ze.headers["content-encoding"]="identity"),"Quantumult X"===e?(ze.status||(ze.status=200),delete ze.headers?.["Content-Length"],delete ze.headers?.["content-length"],delete ze.headers?.["Transfer-Encoding"],i(ze)):i("Stash"===e?ze:{response:ze});break;case"undefined":i({});break;default:t.error("[wloc] 不合法的 response 类型: "+typeof ze),i({})}});
|