auto-champion-select 1.1.2 → 1.1.4

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.
Files changed (2) hide show
  1. package/dist/index.js +2 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * @name auto-champion-select
5
5
  * @link https://github.com/controlado/auto-champion-select#readme
6
6
  * @description Pick or ban automatically! 🐧
7
- * @version 1.1.2
7
+ * @version 1.1.4
8
8
  * @license GPL-3.0-or-later
9
9
  */
10
- import{sleep as m,request as a,linkEndpoint as u}from"https://cdn.skypack.dev/balaclava-utils@latest";const P={status:!1,champions:[21,21]},S={status:!1,champions:[21,21]},l={controladoPick:P,controladoBan:S};class x{constructor(){this.session=null,this.actions=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.update(),await this.task()),await m(300)}async update(){const e=await a("GET","/lol-champ-select/v1/session");this.session=await e.json(),this.actions=this.session.actions,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")||l.controladoPick,t=DataStore.get("controladoBan")||l.controladoBan;for(const n of this.actions)for(const o of n)if(o.completed===!1||o.actorCellId===this.session.localPlayerCellId){const p=o.type==="pick"?e:t;if(!p.status)continue;for(const c of p.champions){if(this.allBans.some(i=>i==c)||o.type==="ban"&&this.teamIntents.some(i=>i==c)||o.type==="pick"&&this.allPicks.some(i=>i.championId==c))continue;if((await this.selectChampion(o.id,c)).ok){console.debug("auto-champion-select: OK!");return}}}}selectChampion(e,t){const n=`/lol-champ-select/v1/session/actions/${e}`;return a("PATCH",n,{body:{championId:t,completed:!0}})}}class r{constructor(e,t,n,o){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=o,this.champions=null}async setup(){this.champions=await this.championsFunction(),this.config=DataStore.get(this.configKey)||l[this.configKey],this.champions.some(e=>this.config.champions[this.configIndex]===e.id)||(this.config.champions[this.configIndex]=this.champions[0].id,DataStore.set(this.configKey,this.config));for(const e of this.champions){const t=this.getNewOption(e);this.element.appendChild(t)}if(!this.element.shadowRoot.querySelector("#controlado-placeholder")){const e=this.element.shadowRoot.querySelector(".ui-dropdown-current"),t=this.getNewPlaceholder();e.appendChild(t)}}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.overflow="visible",e.id="controlado-placeholder",e.innerText=this.text,e}refresh(){this.element.innerHTML="",this.setup()}}class C{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)||l[this.configKey],this.config.status&&this.element.setAttribute("selected","true"),this.element.addEventListener("click",()=>{this.config.status=!this.config.status,DataStore.set(this.configKey,this.config),this.element.toggleAttribute("selected")})}}class T{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")}}async function v(){let s=await a("GET","/lol-champions/v1/owned-champions-minimal");for(;!s.ok;)console.debug("auto-champion-select(owned-champions-minimal): retrying..."),s=await a("GET","/lol-champions/v1/owned-champions-minimal"),await m(1e3);const e=await s.json();return e.sort((t,n)=>t.name.localeCompare(n.name)),e}async function E(){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}function f(){return document.querySelector("lol-social-roster.roster")}const g=new x,w=new C("Pick","controladoPick"),h=new r("1st pick option","controladoPick",0,v),d=new r("2st pick option","controladoPick",1,v),y=new C("Ban","controladoBan"),k=new r("1st ban option","controladoBan",0,E),b=new r("2st ban option","controladoBan",1,E);window.addEventListener("load",async()=>{let s=f();for(;!s;)await m(200),s=f();Promise.all([w.setup(),y.setup(),h.setup(),d.setup(),k.setup(),b.setup()]),u("/lol-inventory/v1/wallet",o=>{o.eventType==="Update"&&(h.refresh(),d.refresh())}),u("/lol-gameflow/v1/gameflow-phase",o=>{o.data==="ChampSelect"?g.mount():g.unmount()});const e=document.createElement("div"),t=document.createElement("div");t.classList.add("auto-select-checkboxes-div"),t.append(w.element,y.element),e.append(h.element,d.element),e.append(k.element,b.element);const n=new T("Auto champion select",e,t);s.append(n.element,t,e),console.debug("auto-champion-select: Report bugs to Balaclava#1912")});
10
+ import{sleep as m,request as a,linkEndpoint as u}from"https://cdn.skypack.dev/balaclava-utils@latest";const E={status:!1,champions:[21,21]},S={status:!1,champions:[21,21]},l={controladoPick:E,controladoBan:S};class x{constructor(){this.session=null,this.actions=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.update(),await this.task()),await m(300)}async update(){const e=await a("GET","/lol-champ-select/v1/session");this.session=await e.json(),this.actions=this.session.actions,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")||l.controladoPick,t=DataStore.get("controladoBan")||l.controladoBan;for(const n of this.actions)for(const o of n)if(o.completed===!1||o.actorCellId===this.session.localPlayerCellId){const p=o.type==="pick"?e:t;if(!p.status)continue;for(const c of p.champions){if(this.allBans.some(i=>i==c)||o.type==="ban"&&this.teamIntents.some(i=>i==c)||o.type==="pick"&&this.allPicks.some(i=>i.championId==c))continue;if((await this.selectChampion(o.id,c)).ok){console.debug("auto-champion-select: OK!");return}}}}selectChampion(e,t){const n=`/lol-champ-select/v1/session/actions/${e}`;return a("PATCH",n,{body:{championId:t,completed:!0}})}}class r{constructor(e,t,n,o){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=o,this.champions=null}async setup(){this.champions=await this.championsFunction(),this.config=DataStore.get(this.configKey)||l[this.configKey],this.champions.some(e=>this.config.champions[this.configIndex]===e.id)||(this.config.champions[this.configIndex]=this.champions[0].id,DataStore.set(this.configKey,this.config));for(const e of this.champions){const t=this.getNewOption(e);this.element.appendChild(t)}if(!this.element.shadowRoot.querySelector("#controlado-placeholder")){const e=this.element.shadowRoot.querySelector(".ui-dropdown-current"),t=this.getNewPlaceholder();e.appendChild(t)}}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.overflow="visible",e.id="controlado-placeholder",e.innerText=this.text,e}refresh(){this.element.innerHTML="",this.setup()}}class C{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)||l[this.configKey],this.config.status&&this.element.setAttribute("selected","true"),this.element.addEventListener("click",()=>{this.config.status=!this.config.status,DataStore.set(this.configKey,this.config),this.element.toggleAttribute("selected")})}}class T{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 B="1.1.4";const f=new x,g=new C("Pick","controladoPick"),h=new r("1st pick option","controladoPick",0,v),d=new r("2nd pick option","controladoPick",1,v),w=new C("Ban","controladoBan"),y=new r("1st ban option","controladoBan",0,P),b=new r("2nd ban option","controladoBan",1,P);function k(){return document.querySelector("lol-social-roster.roster")}async function v(){let s=await a("GET","/lol-champions/v1/owned-champions-minimal");for(;!s.ok;)console.debug("auto-champion-select(owned-champions-minimal): retrying..."),s=await a("GET","/lol-champions/v1/owned-champions-minimal"),await m(1e3);const e=await s.json();return e.sort((t,n)=>t.name.localeCompare(n.name)),e}async function P(){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}window.addEventListener("load",async()=>{let s=k();for(;!s;)await m(200),s=k();Promise.all([g.setup(),w.setup(),h.setup(),d.setup(),y.setup(),b.setup()]),u("/lol-inventory/v1/wallet",o=>{o.eventType==="Update"&&(console.debug("auto-champion-select(wallet): refreshing dropdowns..."),Promise.all([h.refresh(),d.refresh()]))}),u("/lol-gameflow/v1/gameflow-phase",o=>{o.data==="ChampSelect"?f.mount():f.unmount()});const e=document.createElement("div"),t=document.createElement("div");t.classList.add("auto-select-checkboxes-div"),t.append(g.element,w.element),e.append(h.element,d.element),e.append(y.element,b.element);const n=new T("Auto champion select",e,t);s.append(n.element,t,e),console.debug(`auto-champion-select(${B}): report bugs to Balaclava#1912`)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-champion-select",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Pick or ban automatically! 🐧",
5
5
  "author": "balaclava",
6
6
  "repository": {