auto-champion-select 1.2.1 → 1.3.0

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/README.br.md CHANGED
@@ -8,14 +8,19 @@
8
8
  [![english](https://img.shields.io/badge/-English-blue)](README.md)
9
9
  [![português](https://img.shields.io/badge/-Português%20Brasileiro-blue)](README.br.md)
10
10
 
11
- Selecione e bana os campeões automaticamente. <br>
11
+ Aceite a fila, selecione e bana os campeões automaticamente. <br>
12
12
  Esse é o meu primeiro projeto utilizando JavaScript :)
13
13
 
14
- <img src="https://i.imgur.com/dVbUcBp.png" width="700" alt="Plugin preview">
14
+ <img src="https://i.imgur.com/Ovy1gGw.png" width="700" alt="Plugin preview">
15
15
 
16
16
  </div>
17
17
  <br>
18
18
 
19
+ ## 📍 Novidades
20
+
21
+ - Accept: aceita, automaticamente, as partidas
22
+ - CommandBar: use `CTRL + K` para desligar/ligar o auto pick/ban
23
+
19
24
  ## Dependências
20
25
 
21
26
  [Pengu Loader 1.0.5](https://github.com/PenguLoader/PenguLoader) (ou qualquer versão superior) <br>
package/README.md CHANGED
@@ -8,14 +8,19 @@
8
8
  [![english](https://img.shields.io/badge/-English-blue)](README.md)
9
9
  [![português](https://img.shields.io/badge/-Português%20Brasileiro-blue)](README.br.md)
10
10
 
11
- Pick and ban champions automatically. <br>
11
+ Accept queue, pick and ban champions automatically. <br>
12
12
  This is my first project using JavaScript :)
13
13
 
14
- <img src="https://i.imgur.com/dVbUcBp.png" width="700" alt="Plugin preview">
14
+ <img src="https://i.imgur.com/Ovy1gGw.png" width="700" alt="Plugin preview">
15
15
 
16
16
  </div>
17
17
  <br>
18
18
 
19
+ ## 📍 What's new
20
+
21
+ - Accept: automatically accepts matches (ready check)
22
+ - CommandBar: use `CTRL + K` to turn auto pick/ban off/on
23
+
19
24
  ## Dependencies
20
25
 
21
26
  [Pengu Loader 1.0.5](https://github.com/PenguLoader/PenguLoader) (or any higher version) <br>
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.2.1
7
+ * @version 1.3.0
8
8
  * @license GPL-3.0-or-later
9
9
  */
10
- import{sleep as d,request as c,linkEndpoint as b}from"https://cdn.skypack.dev/balaclava-utils@latest";const T={status:!1},x={status:!1,champions:[21,21]},F={status:!1,champions:[21,21]},r={controladoAutoAccept:T,controladoPick:x,controladoBan:F};class O{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 d(300)}async update(){const t=await c("GET","/lol-champ-select/v1/session");this.session=await t.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(e=>e.championPickIntent)}async task(){const t=DataStore.get("controladoPick")||r.controladoPick,e=DataStore.get("controladoBan")||r.controladoBan;for(const s of this.actions)for(const n of s)if(n.completed===!1||n.actorCellId===this.session.localPlayerCellId){const l=n.type==="pick"?t:e;if(!l.status)continue;for(const i of l.champions){if(this.allBans.some(a=>a==i)||n.type==="ban"&&this.teamIntents.some(a=>a==i)||n.type==="pick"&&this.allPicks.some(a=>a.championId==i))continue;if((await this.selectChampion(n.id,i)).ok){console.debug("auto-champion-select: OK!");return}}}}selectChampion(t,e){const s=`/lol-champ-select/v1/session/actions/${t}`;return c("PATCH",s,{body:{championId:e,completed:!0}})}}class p{constructor(t,e,s,n){this.element=document.createElement("lol-uikit-framed-dropdown"),this.element.classList.add("dropdown-champions-default"),this.text=t,this.config=null,this.configKey=e,this.configIndex=s,this.championsFunction=n,this.champions=null}async setup(){this.champions=await this.championsFunction(),this.config=DataStore.get(this.configKey)||r[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));for(const t of this.champions){const e=this.getNewOption(t);this.element.appendChild(e)}if(!this.element.shadowRoot.querySelector("#controlado-placeholder")){const t=this.element.shadowRoot.querySelector(".ui-dropdown-current"),e=this.getNewPlaceholder();t.appendChild(e)}}getNewOption(t){const e=document.createElement("lol-uikit-dropdown-option");return e.setAttribute("slot","lol-uikit-dropdown-option"),e.addEventListener("click",()=>{this.config.champions[this.configIndex]=t.id,DataStore.set(this.configKey,this.config)}),this.config.champions[this.configIndex]===t.id&&e.setAttribute("selected","true"),e.innerText=t.name,e}getNewPlaceholder(){const t=document.createElement("div");return t.classList.add("ui-dropdown-current-content"),t.style.overflow="visible",t.id="controlado-placeholder",t.innerText=this.text,t}refresh(){this.element.innerHTML="",this.setup()}}class k{constructor(t,e){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=t,this.config=null,this.configKey=e}setup(){this.config=DataStore.get(this.configKey)||r[this.configKey],this.config.status&&this.element.setAttribute("selected","true"),this.element.addEventListener("click",()=>this.toggle())}toggle(){return console.debug("auto-champion-select: Toggling",this.configKey),this.config.status=!this.config.status,DataStore.set(this.configKey,this.config),this.element.toggleAttribute("selected"),this.config.status}}class D{constructor(t,...e){this.element=document.createElement("lol-social-roster-group"),this.element.addEventListener("post-render",()=>this.onPostRender()),this.element.addEventListener("click",()=>this.onClick()),this.label=t,this.hiddableElements=e,this.waitRender()}waitRender(){new MutationObserver((t,e)=>{if(this.element.querySelector("span")){const s=new Event("post-render");this.element.dispatchEvent(s),e.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(t=>t.classList.toggle("hidden")),this.element.querySelector(".arrow").toggleAttribute("open")}}const h="Balaclava: Auto Champion Select";class S{constructor(t,e,s,n,l,i,y){this.id=t,this.name=e,this.legend=s,this.tags=n,this.group=l,this.perform=this.perform.bind(this),this.callback=i,this.toasts=y}perform(){try{const t=this.callback();Toast.success(t?this.toasts.on:this.toasts.off)}catch(t){Toast.error(this.toasts.error),console.error(t)}}}class I extends S{constructor(t){super("controladoPickSwitch","Auto Pick [ON/OFF]","Turn the auto pick ON/OFF",[h,"pick","switch"],h,t,{on:"Auto Pick is ON",off:"Auto Pick is OFF",error:"Failed to toggle Auto Pick. Check console."})}}class R extends S{constructor(t){super("controladoBanSwitch","Auto Ban [ON/OFF]","Turn the auto ban ON/OFF",[h,"ban","switch"],h,t,{on:"Auto Ban is ON",off:"Auto Ban is OFF",error:"Failed to toggle Auto Ban. Check console."})}}function L(o){for(let t of o)CommandBar.addAction(t)}const K="1.2.1";const A=new O,w=new k("Accept","controladoAutoAccept"),u=new k("Pick","controladoPick"),m=new p("1st pick option","controladoPick",0,B),f=new p("2nd pick option","controladoPick",1,B),g=new k("Ban","controladoBan"),C=new p("1st ban option","controladoBan",0,E),P=new p("2nd ban option","controladoBan",1,E);function v(){return document.querySelector("lol-social-roster.roster")}async function B(){let o=await c("GET","/lol-champions/v1/owned-champions-minimal");for(;!o.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),o=await c("GET","/lol-champions/v1/owned-champions-minimal"),await d(1e3);const t=await o.json();return t.sort((e,s)=>e.name.localeCompare(s.name)),t}async function E(){const t=await(await c("GET","/lol-game-data/assets/v1/champion-summary.json")).json();return t.sort((e,s)=>e.name.localeCompare(s.name)),t}async function N(){w.config.status===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await d(2e3),await q())}async function q(){(await c("POST","/lol-matchmaking/v1/ready-check/accept")).ok?console.debug("auto-champion-select(auto-accept): Accepted ready check"):console.error("auto-champion-select(auto-accept): Failed to accept ready check")}window.addEventListener("load",async()=>{let o=v();for(;!o;)await d(200),o=v();Promise.all([w.setup(),u.setup(),g.setup(),m.setup(),f.setup(),C.setup(),P.setup()]),L([new I(()=>u.toggle()),new R(()=>g.toggle())]),b("/lol-inventory/v1/wallet",n=>{n.eventType==="Update"&&(console.debug("auto-champion-select(wallet): Refreshing dropdowns..."),Promise.all([m.refresh(),f.refresh()]))}),b("/lol-gameflow/v1/gameflow-phase",n=>{n.data==="ReadyCheck"&&N(),n.data==="ChampSelect"?A.mount():A.unmount()});const t=document.createElement("div"),e=document.createElement("div");e.classList.add("auto-select-checkboxes-div"),e.append(w.element,u.element,g.element),t.append(m.element,f.element),t.append(C.element,P.element);const s=new D("Auto champion select",t,e);o.append(s.element,e,t),console.debug(`auto-champion-select(${K}): Report bugs to Balaclava#1912`)});
10
+ import{sleep as d,request as a,linkEndpoint as y}from"https://cdn.skypack.dev/balaclava-utils@latest";const E={enabled:!1},x={enabled:!1,champions:[21,21]},F={enabled:!1,champions:[21,21]},r={controladoAutoAccept:E,controladoPick:x,controladoBan:F};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 d(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")||r.controladoPick,t=DataStore.get("controladoBan")||r.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 l=s.type==="pick"?e:t;if(l.enabled)for(const i of l.champions){if(this.allBans.some(c=>c==i)){console.debug(`auto-champion-select: Banning ${i} but it's already banned, skipping...`);continue}if(s.type==="ban"&&this.teamIntents.some(c=>c==i)){console.debug(`auto-champion-select: Banning ${i} but it's already picked, skipping...`);continue}if(s.type==="pick"&&this.allPicks.some(c=>c.championId==i)){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){console.debug("auto-champion-select: OK!");return}}}}getLocalPlayerSubActions(){return this.actions.flat().filter(e=>e.actorCellId===this.localPlayerCellId&&e.completed===!1)}selectChampion(e,t){const n=`/lol-champ-select/v1/session/actions/${e}`;return a("PATCH",n,{body:{championId:t,completed:!0}})}}class p{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)||r[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"),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.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)||r[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 O{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 h="Balaclava: Auto Champion Select";class v{constructor(e,t,n,s,l,i,k){this.id=e,this.name=t,this.legend=n,this.tags=s,this.group=l,this.perform=this.perform.bind(this),this.callback=i,this.toasts=k}perform(){try{const e=this.callback();Toast.success(e?this.toasts.on:this.toasts.off)}catch(e){Toast.error(this.toasts.error),console.error(e)}}}class D extends v{constructor(e){super("controladoPickSwitch","Auto Pick [ON/OFF]","Turn the auto pick ON/OFF",[h,"pick","switch"],h,e,{on:"Auto Pick is ON",off:"Auto Pick is OFF",error:"Failed to toggle Auto Pick. Check console."})}}class L extends v{constructor(e){super("controladoBanSwitch","Auto Ban [ON/OFF]","Turn the auto ban ON/OFF",[h,"ban","switch"],h,e,{on:"Auto Ban is ON",off:"Auto Ban is OFF",error:"Failed to toggle Auto Ban. Check console."})}}function R(o){for(let e of o)CommandBar.addAction(e)}const K="1.3.0";const A=new I,w=new b("Accept","controladoAutoAccept"),u=new b("Pick","controladoPick"),m=new p("1st pick option","controladoPick",0,B),g=new p("2nd pick option","controladoPick",1,B),f=new b("Ban","controladoBan"),C=new p("1st ban option","controladoBan",0,T),P=new p("2nd ban option","controladoBan",1,T);function S(){return document.querySelector("lol-social-roster.roster")}async function B(){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 d(1e3);const e=await o.json();return e.sort((t,n)=>t.name.localeCompare(n.name)),e}async function T(){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 N(){w.config.enabled===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await d(2e3),await q())}async function q(){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=S();for(;!o;)await d(200),o=S();Promise.all([w.setup(),u.setup(),f.setup(),m.setup(),g.setup(),C.setup(),P.setup()]),R([new D(()=>u.toggle()),new L(()=>f.toggle())]),y("/lol-inventory/v1/wallet",s=>{s.eventType==="Update"&&(console.debug("auto-champion-select(wallet): Refreshing dropdowns..."),Promise.all([m.refresh(),g.refresh()]))}),y("/lol-gameflow/v1/gameflow-phase",s=>{s.data==="ReadyCheck"&&N(),s.data==="ChampSelect"?A.mount():A.unmount()});const e=document.createElement("div"),t=document.createElement("div");t.classList.add("auto-select-checkboxes-div"),t.append(w.element,u.element,f.element),e.append(m.element,g.element),e.append(C.element,P.element);const n=new O("Auto champion select",e,t);o.append(n.element,t,e),console.debug(`auto-champion-select(${K}): Report bugs to Balaclava#1912`)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-champion-select",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Pick or ban automatically! 🐧",
5
5
  "author": "balaclava",
6
6
  "repository": {