auto-champion-select-fork 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @name auto-champion-select-fork
|
|
5
5
|
* @link https://github.com/controlado/auto-champion-select#readme
|
|
6
6
|
* @description Pick or ban automatically! 🐧
|
|
7
|
-
* @version 0.0.
|
|
7
|
+
* @version 0.0.2
|
|
8
8
|
* @license GPL-3.0-or-later
|
|
9
9
|
*/
|
|
10
|
-
import{
|
|
10
|
+
import{sleep as u,request as a,linkEndpoint as P}from"https://cdn.jsdelivr.net/npm/balaclava-utils@1.2.1/src/controladoUtils.min.js";const T={enabled:!1},E={enabled:!1,force:!1,champions:[21,21]},$={enabled:!1,force:!1,champions:[21,21]},p={controladoAutoAccept:T,controladoPick:E,controladoBan:$};class I{constructor(){this.session=null,this.actions=null,this.localPlayerCellId=null,this.teamIntents=null,this.allPicks=null,this.allBans=null,this.mounted=!1,this.watch()}mount(){this.mounted=!0}unmount(){this.mounted=!1}async watch(){for(;;)this.mounted&&(await this.updateProperties(),await this.task()),await u(300)}async updateProperties(){const e=await a("GET","/lol-champ-select/v1/session");this.session=await e.json(),this.actions=this.session.actions,this.localPlayerCellId=this.session.localPlayerCellId,this.allPicks=[...this.session.myTeam,...this.session.theirTeam],this.allBans=[...this.session.bans.myTeamBans,...this.session.bans.theirTeamBans],this.teamIntents=this.session.myTeam.map(t=>t.championPickIntent)}async task(){const e=DataStore.get("controladoPick")||p.controladoPick,t=DataStore.get("controladoBan")||p.controladoBan;if(!e.enabled&&!t.enabled)return;const n=this.getLocalPlayerSubActions();if(n.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const s of n){const c=s.type==="pick"?e:t;if(c.enabled)for(const i of c.champions){if(this.allBans.some(r=>r==i)){console.debug(`auto-champion-select: Banning ${i} but it's already banned, skipping...`);continue}if(s.type==="ban"&&this.teamIntents.some(r=>r==i))if(c.force===!0)console.debug(`auto-champion-select: Banning ${i} but it's already picked, forcing...`);else{console.debug(`auto-champion-select: Banning ${i} but it's already picked, skipping...`);continue}if(s.type==="pick"&&this.allPicks.some(r=>r.championId==i))if(c.force===!0)console.debug(`auto-champion-select: Picking ${i} but it's already picked, forcing...`);else{console.debug(`auto-champion-select: Picking ${i} but it's already picked, skipping...`);continue}if(console.debug(`auto-champion-select: Trying to ${s.type} ${i}...`),(await this.selectChampion(s.id,i)).ok)break;return}}}getLocalPlayerSubActions(){return this.actions.flat().filter(e=>e.actorCellId===this.localPlayerCellId&&e.completed===!1).sort((e,t)=>{const n=e.type==="pick"?0:1,s=t.type==="pick"?0:1;return n-s})}selectChampion(e,t){const n=`/lol-champ-select/v1/session/actions/${e}`;return a("PATCH",n,{body:{championId:t,completed:!0}})}}class m{constructor(e,t,n,s){this.element=document.createElement("lol-uikit-framed-dropdown"),this.element.classList.add("dropdown-champions-default"),this.text=e,this.config=null,this.configKey=t,this.configIndex=n,this.championsFunction=s,this.champions=null}async setup(){this.champions=await this.championsFunction(),this.config=DataStore.get(this.configKey)||p[this.configKey],this.champions.some(t=>this.config.champions[this.configIndex]===t.id)||(this.config.champions[this.configIndex]=this.champions[0].id,DataStore.set(this.configKey,this.config));const e=[];for(const t of this.champions){if(e.includes(t.name))continue;e.push(t.name);const n=this.getNewOption(t);this.element.appendChild(n)}if(!this.element.shadowRoot.querySelector("#controlado-placeholder")){const t=this.element.shadowRoot.querySelector(".ui-dropdown-current");t.style="display: flex; justify-content: space-between;";const n=this.getNewPlaceholder();t.appendChild(n)}}getNewOption(e){const t=document.createElement("lol-uikit-dropdown-option");return t.setAttribute("slot","lol-uikit-dropdown-option"),t.addEventListener("click",()=>{this.config.champions[this.configIndex]=e.id,DataStore.set(this.configKey,this.config)}),this.config.champions[this.configIndex]===e.id&&t.setAttribute("selected","true"),t.innerText=e.name,t}getNewPlaceholder(){const e=document.createElement("div");return e.classList.add("ui-dropdown-current-content"),e.style="width: unset; overflow: visible;",e.id="controlado-placeholder",e.innerText=this.text,e}refresh(){this.element.innerHTML="",this.setup()}}class b{constructor(e,t){this.element=document.createElement("lol-uikit-radio-input-option"),this.element.classList.add("lol-settings-voice-input-mode-option","auto-select-checkbox"),this.element.innerText=e,this.config=null,this.configKey=t}setup(){this.config=DataStore.get(this.configKey)||p[this.configKey],this.config.enabled&&this.element.setAttribute("selected","true"),this.element.addEventListener("click",()=>this.toggle())}toggle(){return console.debug("auto-champion-select: Toggling",this.configKey),this.config.enabled=!this.config.enabled,DataStore.set(this.configKey,this.config),this.element.toggleAttribute("selected"),this.config.enabled}}class R{constructor(e,...t){this.element=document.createElement("lol-social-roster-group"),this.element.addEventListener("post-render",()=>this.onPostRender()),this.element.addEventListener("click",()=>this.onClick()),this.label=e,this.hiddableElements=t,this.waitRender()}waitRender(){new MutationObserver((e,t)=>{if(this.element.querySelector("span")){const n=new Event("post-render");this.element.dispatchEvent(n),t.disconnect()}}).observe(this.element,{childList:!0})}onPostRender(){this.element.querySelector("span").innerText=this.label,this.element.querySelector(".group-header").removeAttribute("graggable")}onClick(){this.hiddableElements.forEach(e=>e.classList.toggle("hidden")),this.element.querySelector(".arrow").toggleAttribute("open")}}const l="Balaclava: Auto Champion Select";class k{constructor(e,t,n,s,c,i,y){this.id=e,this.name=t,this.legend=n,this.tags=s,this.group=c,this.perform=this.perform.bind(this),this.callback=i,this.toasts=y}perform(){if(typeof this.callback.then=="function")return Toast.promise(this.callback,{loading:this.toasts.loading,success:this.toasts.success,error:this.toasts.error});try{const e=this.callback();Toast.success(this.toasts.success||(e?this.toasts.on:this.toasts.off))}catch(e){Toast.error(this.toasts.error),console.error(e)}}}class D extends k{constructor(e,t,n){super(`${t}Switch`,()=>`Auto ${e} [${DataStore.get(t)?.enabled?"ON":"OFF"}]`,()=>DataStore.get(t)?.enabled?"Turn OFF":"Turn ON",[l,t,"switch"],l,n,{on:`Auto ${e} is ON!`,off:`Auto ${e} is OFF!`,error:`Failed to toggle Auto ${e}. Check console.`})}}class x extends k{constructor(e,t){super(`${t}ForceSwitch`,()=>`Force ${e} [${DataStore.get(t)?.force?"ON":"OFF"}]`,()=>`Ignore team intent and force ${e} the selected champion`,[l,t,"force","switch"],l,()=>this.switchDataStore(t),{on:`Force ${e} is ON!`,off:`Force ${e} is OFF!`,error:`Failed to toggle Force ${e}. Check console.`})}switchDataStore(e){const t=DataStore.get(e);return t.force=!t.force,DataStore.set(e,t),t.force}}class L extends k{constructor(e){super("RefreshDropdowns",()=>"Refresh Dropdowns",()=>"Normally dropdowns refresh automatically...",[l,"refresh"],l,()=>this.refreshDropdowns(e),{success:"Refreshed Dropdowns!",error:"Failed to refresh Dropdowns. Check console."})}refreshDropdowns(e){for(let t of e)t.refresh()}}class O extends D{constructor(e){super("Pick","controladoPick",e)}}class N extends D{constructor(e){super("Ban","controladoBan",e)}}class q extends x{constructor(){super("Pick","controladoPick")}}class j extends x{constructor(){super("Ban","controladoBan")}}function G(o){for(let e of o)CommandBar.addAction(e)}const K="0.0.2",S=new I,w=new b("Accept","controladoAutoAccept"),f=new b("Pick","controladoPick"),h=new m("1st pick","controladoPick",0,F),d=new m("2nd pick","controladoPick",1,F),g=new b("Ban","controladoBan"),C=new m("1st ban","controladoBan",0,B),A=new m("2nd ban","controladoBan",1,B);function v(){return document.querySelector(".lol-social-roster")}async function F(){let o=await a("GET","/lol-champions/v1/owned-champions-minimal");for(;!o.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),o=await a("GET","/lol-champions/v1/owned-champions-minimal"),await u(1e3);const e=await o.json();return e.sort((t,n)=>t.name.localeCompare(n.name)),e}async function B(){const e=await(await a("GET","/lol-game-data/assets/v1/champion-summary.json")).json();return e.sort((t,n)=>t.name.localeCompare(n.name)),e}async function H(){w.config.enabled===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await u(2e3),await M())}async function M(){const o=await a("POST","/lol-matchmaking/v1/ready-check/accept");o.ok?console.debug("auto-champion-select(auto-accept): Accepted ready check"):console.error("auto-champion-select(auto-accept): Failed to accept ready check",o)}window.addEventListener("load",async()=>{let o=v();for(;!o;)await u(200),o=v();Promise.all([w.setup(),f.setup(),g.setup(),h.setup(),d.setup(),C.setup(),A.setup()]),G([new O(()=>f.toggle()),new N(()=>g.toggle()),new q,new j,new L([h,d])]),P("/lol-inventory/v1/wallet",s=>{s.eventType==="Update"&&(console.debug("auto-champion-select(wallet): Refreshing dropdowns..."),Promise.all([h.refresh(),d.refresh()]))}),P("/lol-gameflow/v1/gameflow-phase",s=>{s.data==="ReadyCheck"&&H(),s.data==="ChampSelect"?S.mount():S.unmount()});const e=document.createElement("div"),t=document.createElement("div");t.classList.add("auto-select-checkboxes-div"),t.append(w.element,f.element,g.element),e.append(h.element,d.element),e.append(C.element,A.element);const n=new R("Auto champion select",e,t);o.append(n.element,t,e),console.debug(`auto-champion-select(${K}): Report bugs to Balaclava#1912`)});
|