mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-11 02:43:50 +02:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([,,,,function(e,t,r){r(5),e.exports=r(6)},function(e,t){CefSharp.BindObjectAsync("VRCX","VRCXStorage","SQLite").then((function(){VRCXStorage.GetBool=function(e){return"true"===this.Get(e)},VRCXStorage.SetBool=function(e,t){this.Set(e,t?"true":"false")},VRCXStorage.GetInt=function(e){return parseInt(this.Get(e),10)||0},VRCXStorage.SetInt=function(e,t){this.Set(e,String(t))},VRCXStorage.GetFloat=function(e){return parseFloat(this.Get(e),10)||0},VRCXStorage.SetFloat=function(e,t){this.Set(e,String(t))},VRCXStorage.GetArray=function(e){try{var t=JSON.parse(this.Get(e));if(Array.isArray(t))return t}catch(e){console.error(e)}return[]},VRCXStorage.SetArray=function(e,t){this.Set(e,JSON.stringify(t))},VRCXStorage.GetObject=function(e){try{var t=JSON.parse(this.Get(e));if(t===Object(t))return t}catch(e){console.error(e)}return{}},VRCXStorage.SetObject=function(e,t){this.Set(e,JSON.stringify(t))},Noty.overrideDefaults({animation:{open:"animated fadeIn",close:"animated zoomOut"},layout:"topCenter",theme:"relax",timeout:6e3});var e=e=>String(e).replace(/["&'<>]/gu,e=>`&#${e.charCodeAt(0)};`);Vue.filter("escapeTag",e);Vue.filter("commaNumber",e=>String(Number(e)||0).replace(/(\d)(?=(\d{3})+(?!\d))/gu,"$1,"));Vue.filter("formatDate",(t,r)=>{var n=new Date(t);if(isNaN(n))return e(t);var a=n.getHours(),i={YYYY:String(1e4+n.getFullYear()).substr(-4),MM:String(101+n.getMonth()).substr(-2),DD:String(100+n.getDate()).substr(-2),HH24:String(100+a).substr(-2),HH:String(100+(a>12?a-12:a)).substr(-2),MI:String(100+n.getMinutes()).substr(-2),SS:String(100+n.getSeconds()).substr(-2),AMPM:a>=12?"PM":"AM"};return r.replace(/YYYY|MM|DD|HH24|HH|MI|SS|AMPM/gu,e=>i[e]||e)});Vue.filter("textToHex",e=>String(e).split("").map(e=>e.charCodeAt(0).toString(16)).join(" "));Vue.filter("timeToText",t=>{var r=Number(t);if(isNaN(r))return e(t);var n=[];return(r=Math.floor(r/1e3))<0&&(r=-r),r>=86400&&(n.push(`${Math.floor(r/86400)}d`),r%=86400),r>=3600&&(n.push(`${Math.floor(r/3600)}h`),r%=3600),r>=60&&(n.push(`${Math.floor(r/60)}m`),r%=60),!r&&n.length||n.push(`${r}s`),n.join(" ")}),ELEMENT.locale(ELEMENT.lang.en);var t={};t.eventHandlers=new Map,t.$emit=function(e,...t){var r=this.eventHandlers.get(e);if(void 0!==r)try{for(var n of r)n.apply(this,t)}catch(e){console.error(e)}},t.$on=function(e,t){var r=this.eventHandlers.get(e);void 0===r&&(r=[],this.eventHandlers.set(e,r)),r.push(t)},t.$off=function(e,t){var r=this.eventHandlers.get(e);if(void 0!==r)for(var{length:n}=r,a=0;a<n;++a)if(r[a]===t){n>1?r.splice(a,1):this.eventHandlers.delete(e);break}},t.pendingGetRequests=new Map,t.call=function(t,r){var n=`https://api.vrchat.cloud/api/1/${t}`,a={method:"GET",mode:"cors",credentials:"include",cache:"no-cache",redirect:"follow",referrerPolicy:"no-referrer",...r},{params:i}=a,s="GET"===a.method;if(s){if(i===Object(i)){var o=new URL(n),{searchParams:d}=o;for(var c in i)d.set(c,i[c]);n=o.toString()}if(void 0!==(u=this.pendingGetRequests.get(n)))return u}else a.headers={"Content-Type":"application/json;charset=utf-8",...a.headers},a.body=i===Object(i)?JSON.stringify(i):"{}";var u=fetch(n,a).catch(e=>{this.$throw(0,e)}).then(t=>t.json().catch(()=>{t.ok&&this.$throw(0,"Invalid JSON response"),this.$throw(t.status)}).then(r=>t.ok?(r.success===Object(r.success)&&new Noty({type:"success",text:e(r.success.message)}).show(),r):(r===Object(r)&&(r.error===Object(r.error)?this.$throw(r.error.status_code||t.status,r.error.message,r.error.data):"string"==typeof r.error&&this.$throw(r.status_code||t.status,r.error)),this.$throw(t.status,r),r)));return s&&(u.finally(()=>{this.pendingGetRequests.delete(n)}),this.pendingGetRequests.set(n,u)),u},t.statusCodes={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",303:"See Other",304:"Not Modified",305:"Use Proxy",306:"Switch Proxy",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:"Payload 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",520:"Web server returns an unknown error",521:"Web server is down",522:"Connection timed out",523:"Origin is unreachable",524:"A timeout occurred",525:"SSL handshake failed",526:"Invalid SSL certificate",527:"Railgun Listener to origin error"},t.$throw=function(t,r){var n=[];if(t>0){var a=this.statusCodes[t];void 0===a?n.push(`${t}`):n.push(`${t} ${a}`)}throw void 0!==r&&n.push(JSON.stringify(r)),(n=n.map(t=>e(t)).join("<br>")).length&&new Noty({type:"error",text:n}).show(),new Error(n)},t.cachedConfig={},t.$on("CONFIG",(function(e){e.ref=this.applyConfig(e.json)})),t.applyConfig=function(e){var t={clientApiKey:"",...e};return this.cachedConfig=t,t},t.getConfig=function(){return this.call("config",{method:"GET"}).then(e=>{var t={ref:null,json:e};return this.$emit("CONFIG",t),t})},t.parseLocation=function(e){var t={tag:e=String(e||""),isOffline:!1,isPrivate:!1,worldId:"",instanceId:"",instanceName:"",accessType:"",userId:null,hiddenId:null,privateId:null,friendsId:null,canRequestInvite:!1};if("offline"===e)t.isOffline=!0;else if("private"===e)t.isPrivate=!0;else if(!1===e.startsWith("local")){var r=e.indexOf(":");r>=0?(t.worldId=e.substr(0,r),t.instanceId=e.substr(r+1),t.instanceId.split("~").forEach((e,r)=>{if(r){var n=e.indexOf("("),a=n>=0?e.lastIndexOf(")"):-1,i=a>=0?e.substr(0,n):e,s=n<a?e.substr(n+1,a-n-1):"";"hidden"===i?t.hiddenId=s:"private"===i?t.privateId=s:"friends"===i?t.friendsId=s:"canRequestInvite"===i&&(t.canRequestInvite=!0)}else t.instanceName=e}),t.accessType="public",null!==t.privateId?(t.canRequestInvite?t.accessType="invite+":t.accessType="invite",t.userId=t.privateId):null!==t.friendsId?(t.accessType="friends",t.userId=t.friendsId):null!==t.hiddenId&&(t.accessType="friends+",t.userId=t.hiddenId)):t.worldId=e}return t},Vue.component("location",{template:"<span>{{ text }}<slot></slot></span>",props:{location:String},data(){return{text:this.location}},methods:{parse(){var e=t.parseLocation(this.location);if(e.isOffline)this.text="Offline";else if(e.isPrivate)this.text="Private";else if(e.worldId){var r=t.cachedWorlds.get(e.worldId);void 0===r?t.getWorld({worldId:e.worldId}).then(t=>(e.tag===this.location&&(e.instanceId?this.text=`${t.json.name} #${e.instanceName} ${e.accessType}`:this.text=t.json.name),t)):e.instanceId?this.text=`${r.name} #${e.instanceName} ${e.accessType}`:this.text=r.name}}},watch:{location(){this.parse()}},created(){this.parse()}}),t.cachedWorlds=new Map,t.$on("WORLD",(function(e){e.ref=this.applyWorld(e.json)})),t.applyWorld=function(e){var t=this.cachedWorlds.get(e.id);return void 0===t?(t={id:"",name:"",description:"",authorId:"",authorName:"",capacity:0,tags:[],releaseStatus:"",imageUrl:"",thumbnailImageUrl:"",assetUrl:"",assetUrlObject:{},pluginUrl:"",pluginUrlObject:{},unityPackageUrl:"",unityPackageUrlObject:{},unityPackages:[],version:0,favorites:0,created_at:"",updated_at:"",publicationDate:"",labsPublicationDate:"",visits:0,popularity:0,heat:0,publicOccupants:0,privateOccupants:0,occupants:0,instances:[],$isLabs:!1,...e},this.cachedWorlds.set(t.id,t)):Object.assign(t,e),t.$isLabs=t.tags.includes("system_labs"),t},t.getWorld=function(e){return this.call(`worlds/${e.worldId}`,{method:"GET"}).then(t=>{var r={ref:null,json:t,params:e};return this.$emit("WORLD",r),r})};var r={data:{API:t,VRCX:VRCX,appType:location.href.substr(-1),currentTime:(new Date).toJSON(),cpuUsage:0,feeds:[],devices:[]},computed:{},methods:{},watch:{},el:"#x-app",mounted(){t.getConfig().catch(e=>{throw e}).then(e=>(setInterval(()=>this.update(),1e3),this.update(),this.$nextTick((function(){"1"===this.appType&&(this.$el.style.display="")})),e))}};r.methods.update=function(){this.currentTime=(new Date).toJSON(),this.currentUser=VRCXStorage.GetObject("currentUser")||{},VRCX.CpuUsage().then(e=>{this.cpuUsage=e.toFixed(2)}),VRCX.GetVRDevices().then(e=>{e.forEach(e=>{e[2]=parseInt(e[2],10)}),this.devices=e}),this.updateSharedFeed()},r.methods.updateSharedFeed=function(){var e=this.feeds;if(this.feeds=VRCXStorage.GetArray("sharedFeeds"),"2"===this.appType){var t={};if(e.forEach(e=>{e.isFavorite&&("OnPlayerJoined"===e.type||"OnPlayerLeft"===e.type?(!t[e.data]||t[e.data]<e.created_at)&&(t[e.data]=e.created_at):"Online"!==e.type&&"Offline"!==e.type||(!t[e.displayName]||t[e.displayName]<e.created_at)&&(t[e.displayName]=e.created_at))}),"busy"===this.currentUser.status)return;var r=[];this.feeds.forEach(e=>{e.isFavorite&&("Online"===e.type||"Offline"===e.type?(!t[e.displayName]||t[e.displayName]<e.created_at)&&(t[e.displayName]=e.created_at,r.push(e)):"OnPlayerJoined"!==e.type&&"OnPlayerLeft"!==e.type||(!t[e.data]||t[e.data]<e.created_at)&&(t[e.data]=e.created_at,r.push(e)))});var n=new Date(Date.now()-6e4).toJSON();r.forEach(e=>{e.created_at>n&&("OnPlayerJoined"===e.type?new Noty({type:"alert",text:`<strong>${e.data}</strong> has joined`}).show():"OnPlayerLeft"===e.type?new Noty({type:"alert",text:`<strong>${e.data}</strong> has left`}).show():"Online"===e.type?new Noty({type:"alert",text:`<strong>${e.displayName}</strong> has logged in`}).show():"Offline"===e.type&&new Noty({type:"alert",text:`<strong>${e.displayName}</strong> has logged out`}).show())})}},r.methods.userStatusClass=function(e){var t={};return e&&("offline"===e.location?t.offline=!0:"active"===e.status?t.active=!0:"join me"===e.status?t.joinme=!0:"busy"===e.status&&(t.busy=!0)),t},r=new Vue(r),window.$app=r}))},function(e,t,r){}]); |