UNPKG

@steambrew/api

Version:
1 lines 5.14 kB
var millennium_api_components=function(e){"use strict";const n="steamloopback.host"===window.location.hostname;window.MILLENNIUM_BACKEND_IPC={postMessage:(e,n)=>new Promise((o=>{const t={id:e,iteration:window.CURRENT_IPC_CALL_COUNT++,data:n},c=e=>{let r;try{r=JSON.parse(e.data)}catch{return void console.error("Failed to parse JSON from backend IPC",e.data,n)}r.id===t.iteration&&(o(r),window.MILLENNIUM_IPC_SOCKET.removeEventListener("message",c))};window.MILLENNIUM_IPC_SOCKET.addEventListener("message",c),window.MILLENNIUM_IPC_SOCKET.send(JSON.stringify(t))}))},window.Millennium={callServerMethod:(e,n,o)=>new Promise(((t,c)=>{const r={pluginName:e,methodName:n,...o&&{argumentList:o}};window.MILLENNIUM_BACKEND_IPC.postMessage(0,r).then((o=>{if(o?.failedRequest)return c(`IPC call failed [plugin: ${e}, method: ${n}] -> ${o.failMessage}`);t("string"==typeof o.returnValue?atob(o.returnValue):o.returnValue)}))})),findElement:(e,n,o)=>new Promise(((t,c)=>{const r=e.querySelectorAll(n);if(r.length)return t(r);const l=new MutationObserver((()=>{const o=e.querySelectorAll(n);o.length&&(l.disconnect(),a&&clearTimeout(a),t(o))}));l.observe(e.body,{childList:!0,subtree:!0});const a=o&&setTimeout((()=>{l.disconnect(),c()}),o)})),...n?{exposeObj:function(e,n){for(const o in n)e[o]=n[o]},AddWindowCreateHook:e=>{g_PopupManager.AddPopupCreatedCallback((n=>{e(n)}))}}:{}};const o=n?undefined:void 0,t=window.Millennium;return e.Millennium=t,e.callable=(e,n)=>(...o)=>e(n,...o),e.pluginSelf=o,e},millennium_components=function(){"use strict";const e="background: #8a16a2; color: white;",n="steamloopback.host"===window.location.hostname?"@steambrew/client":"@steambrew/webkit";const o=new class{constructor(e){this.name=e,this.name=e}log(...o){((o,...t)=>{console.log(`%c ${n} %c ${o} %c`,e,"background: #b11cce; color: white;","background: transparent;",...t)})(this.name,...o)}debug(...o){((o,...t)=>{console.debug(`%c ${n} %c ${o} %c`,e,"background: #1abc9c; color: white;","color: blue;",...t)})(this.name,...o)}warn(...o){((o,...t)=>{console.warn(`%c ${n} %c ${o} %c`,e,"background: #ffbb00; color: white;","color: blue;",...t)})(this.name,...o)}error(...o){((o,...t)=>{console.error(`%c ${n} %c ${o} %c`,e,"background: #FF0000;","background: transparent;",...t)})(this.name,...o)}group(...o){((o,...t)=>{console.group(`%c ${n} %c ${o} %c`,e,"background: #b11cce; color: white;","background: transparent;",...t)})(this.name,...o)}groupEnd(...o){((o,...t)=>{console.groupEnd(),t?.length>0&&console.log(`^ %c ${n} %c ${o} %c`,e,"background: #b11cce; color: white;","background: transparent;",...t)})(this.name,...o)}}("Core"),t="steamloopback.host"===window.location.hostname,c=e=>new Promise(((n,o)=>{e.readyState===WebSocket.OPEN?n():(e.addEventListener("open",(()=>n())),e.addEventListener("error",(()=>o())))})),r=()=>new Promise((e=>{const n=n=>{n?.length>=5&&((async()=>{window.MILLENNIUM_API={...window.MILLENNIUM_API,...millennium_api_components({}),...steam_client_components({},window.SP_REACT)}})(),clearInterval(o),e())},o=setInterval((()=>n(window?.webpackChunksteamui)),100)})),l=async()=>{const e=JSON.parse(await Millennium.callServerMethod("core","_webkit_accent_color"));((e,n,o)=>{e.querySelectorAll(`style[id='${o}']`).length||(e.head.appendChild(Object.assign(e.createElement("style"),{id:o})).innerText=n)})(document,`\n\t:root {\n --SystemAccentColor: ${e.accent}; \n --SystemAccentColor-RGB: ${e.accentRgb}; \n --SystemAccentColorLight1: ${e.light1}; \n --SystemAccentColorLight1-RGB: ${e.light1Rgb}; \n --SystemAccentColorLight2: ${e.light2}; \n --SystemAccentColorLight2-RGB: ${e.light2Rgb}; \n --SystemAccentColorLight3: ${e.light3};\n --SystemAccentColorLight3-RGB: ${e.light3Rgb};\n --SystemAccentColorDark1: ${e.dark1};\n --SystemAccentColorDark1-RGB: ${e.dark1Rgb};\n --SystemAccentColorDark2: ${e.dark2};\n --SystemAccentColorDark2-RGB: ${e.dark2Rgb};\n --SystemAccentColorDark3: ${e.dark3};\n --SystemAccentColorDark3-RGB: ${e.dark3Rgb};\n }`,"SystemAccentColorInject")};return(e,n)=>{var a;window.MILLENNIUM_IPC_PORT=e,o.log(`Successfully bound to ${t?"client":"webkit"} DOM...`),(a="ws://localhost:"+e,new Promise((e=>{try{let n=new WebSocket(a);n.addEventListener("open",(()=>{o.log("Successfully connected to IPC server."),e(n)})),n.addEventListener("error",(()=>{console.log("Failed to connect to IPC server:",a),window.location.reload()})),n.addEventListener("close",(()=>{console.log("IPC server closed connection:",a)}))}catch(e){console.warn("Failed to connect to IPC server:",e)}}))).then((async e=>{window.MILLENNIUM_IPC_SOCKET=e,window.CURRENT_IPC_CALL_COUNT=0,await Promise.all([c(e),...t?[r()]:[]]),o.log("Ready to inject shims..."),t||(window.MILLENNIUM_API=millennium_api_components({}),l()),n?.forEach((e=>{!document.querySelectorAll(`script[src='${e}'][type='module']`).length&&document.head.appendChild(Object.assign(document.createElement("script"),{src:e,type:"module",id:"millennium-injected"}))}))})).catch((e=>console.error("Initial WebSocket connection failed:",e)))}}();