auto-champion-select 1.1.5 → 1.2.1
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 +3 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".dropdown-champions-default{position:inherit;width:-webkit-fill-available}.auto-select-checkboxes-div{display:flex;
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".dropdown-champions-default{position:inherit;width:-webkit-fill-available}.auto-select-checkboxes-div{display:flex;border-top:thin solid #1e282d}.auto-select-checkbox{margin:auto}.auto-select-checkbox:last-child{margin-right:17px}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
|
|
2
2
|
/**
|
|
3
3
|
* @author balaclava
|
|
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
|
|
7
|
+
* @version 1.2.1
|
|
8
8
|
* @license GPL-3.0-or-later
|
|
9
9
|
*/
|
|
10
|
-
import{sleep as
|
|
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`)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-champion-select",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Pick or ban automatically! 🐧",
|
|
5
5
|
"author": "balaclava",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "vite build",
|
|
25
|
-
"watch": "vite build --watch"
|
|
25
|
+
"watch": "vite build --watch --outDir ."
|
|
26
26
|
},
|
|
27
27
|
"bugs": {
|
|
28
28
|
"url": "https://github.com/controlado/auto-champion-select/issues"
|