auto-champion-select 1.0.0 → 1.1.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/{README.BR.md → README.br.md} +1 -1
- package/README.md +1 -1
- package/dist/index.js +3 -2
- package/package.json +3 -2
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://discordapp.com/users/854886148455399436) <br>
|
|
7
7
|

|
|
8
8
|
[](README.md)
|
|
9
|
-
[](README.
|
|
9
|
+
[](README.br.md)
|
|
10
10
|
|
|
11
11
|
Selecione e bana os campeões automaticamente. <br>
|
|
12
12
|
Esse é o meu primeiro projeto utilizando JavaScript :)
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://discordapp.com/users/854886148455399436) <br>
|
|
7
7
|

|
|
8
8
|
[](README.md)
|
|
9
|
-
[](README.
|
|
9
|
+
[](README.br.md)
|
|
10
10
|
|
|
11
11
|
Pick and ban champions automatically. <br>
|
|
12
12
|
This is my first project using JavaScript :)
|
package/dist/index.js
CHANGED
|
@@ -1,9 +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;justify-content:center;border-top:thin solid #1e282d}.auto-select-checkbox{margin:auto}.auto-select-checkbox:last-child{margin-right:42px}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
|
|
1
2
|
/**
|
|
2
3
|
* @author balaclava
|
|
3
4
|
* @name auto-champion-select
|
|
4
5
|
* @link https://github.com/controlado/auto-champion-select#readme
|
|
5
6
|
* @description Pick or ban automatically! 🐧
|
|
6
|
-
* @version 1.
|
|
7
|
+
* @version 1.1.1
|
|
7
8
|
* @license GPL-3.0-or-later
|
|
8
9
|
*/
|
|
9
|
-
import{
|
|
10
|
+
import{sleep as m,request as a,linkEndpoint as u}from"https://cdn.skypack.dev/balaclava-utils@latest";const E={status:!0,champions:[1,1]},S={status:!0,champions:[1,1]},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 s of this.actions)for(const n of s)if(n.completed===!1||n.actorCellId===this.session.localPlayerCellId){const p=n.type==="pick"?e:t;if(!p.status)continue;for(const c of p.champions){if(this.allBans.some(i=>i==c)||n.type==="ban"&&this.teamIntents.some(i=>i==c)||n.type==="pick"&&this.allPicks.some(i=>i.championId==c))continue;if((await this.selectChampion(n.id,c)).ok){console.debug("auto-champion-select: OK!");return}}}}selectChampion(e,t){const s=`/lol-champ-select/v1/session/actions/${e}`;return a("PATCH",s,{body:{championId:t,completed:!0}})}}class r{constructor(e,t,s,n){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=s,this.championsFunction=n,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}async setup(){this.config=DataStore.get(this.configKey)||l[this.configKey],this.config.status&&this.element.setAttribute("selected","true"),this.element.addEventListener("click",()=>{this.element.toggleAttribute("selected"),this.config.status=!this.config.status,DataStore.set(this.configKey,this.config)})}}class T{constructor(e,...t){this.label=e,this.hiddableElements=t,this.element=document.createElement("lol-social-roster-group"),this.element.addEventListener("post-render",()=>this.onPostRender()),this.element.addEventListener("click",()=>this.onClick()),this.waitRender()}waitRender(){new MutationObserver((e,t)=>{this.element.querySelector("span")&&(this.element.dispatchEvent(new Event("post-render")),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 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 m(1e3);const e=await o.json();return e.sort((t,s)=>t.name.localeCompare(s.name)),e}async function P(){const e=await(await a("GET","/lol-game-data/assets/v1/champion-summary.json")).json();return e.sort((t,s)=>t.name.localeCompare(s.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","controladoPick",0,v),d=new r("2st pick","controladoPick",1,v),y=new C("Ban","controladoBan"),k=new r("1st ban","controladoBan",0,P),b=new r("2st ban","controladoBan",1,P);window.addEventListener("load",async()=>{let o=f();for(;!o;)await m(200),o=f();Promise.all([w.setup(),y.setup(),h.setup(),d.setup(),k.setup(),b.setup()]),u("/lol-inventory/v1/wallet",n=>{n.eventType==="Update"&&(h.refresh(),d.refresh())}),u("/lol-gameflow/v1/gameflow-phase",n=>{n.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 s=new T("Auto champion select",e,t);o.append(s.element,t,e),console.debug("auto-champion-select: Report bugs to Balaclava#1912")});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-champion-select",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Pick or ban automatically! 🐧",
|
|
5
5
|
"author": "balaclava",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/controlado/auto-champion-select#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"vite": "^4.4.6"
|
|
32
|
+
"vite": "^4.4.6",
|
|
33
|
+
"vite-plugin-css-injected-by-js": "^3.2.1"
|
|
33
34
|
}
|
|
34
35
|
}
|