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.
@@ -6,7 +6,7 @@
6
6
  [![discord](https://img.shields.io/badge/Discord-%235865F2.svg?style=flat&logo=discord&logoColor=white&color=blue)](https://discordapp.com/users/854886148455399436) <br>
7
7
  ![languages](https://img.shields.io/badge/Documentation-gray)
8
8
  [![english](https://img.shields.io/badge/-English-blue)](README.md)
9
- [![português](https://img.shields.io/badge/-Português%20Brasileiro-blue)](README.BR.md)
9
+ [![português](https://img.shields.io/badge/-Português%20Brasileiro-blue)](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
  [![discord](https://img.shields.io/badge/Discord-%235865F2.svg?style=flat&logo=discord&logoColor=white&color=blue)](https://discordapp.com/users/854886148455399436) <br>
7
7
  ![languages](https://img.shields.io/badge/Documentation-gray)
8
8
  [![english](https://img.shields.io/badge/-English-blue)](README.md)
9
- [![português](https://img.shields.io/badge/-Português%20Brasileiro-blue)](README.BR.md)
9
+ [![português](https://img.shields.io/badge/-Português%20Brasileiro-blue)](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.0.0
7
+ * @version 1.1.1
7
8
  * @license GPL-3.0-or-later
8
9
  */
9
- import{request as b,linkEndpoint as k,addRoutines as y,sleep as S}from"https://cdn.skypack.dev/balaclava-utils@latest";async function w(t,e,n=!0){const o=`/lol-champ-select/v1/session/actions/${t}`;return(await b("PATCH",o,{body:{completed:n,championId:e}})).ok}async function x(){return(await b("GET","/lol-champ-select/v1/session")).json()}async function D(){return(await b("GET","/lol-gameflow/v1/gameflow-phase")).json()}async function v(){const e=await(await b("GET","/lol-game-data/assets/v1/champion-summary.json")).json();return e.sort((n,o)=>n.name.localeCompare(o.name)),e}function A(t){const e=document.createElement("lol-uikit-framed-dropdown");return e.setAttribute("style","margin-bottom: 1.2px;"),e.id=t,e}function E(t){const e=document.createElement("lol-uikit-dropdown-option");return e.setAttribute("slot","lol-uikit-dropdown-option"),e.textContent=t,e}function T(t,e){const n=document.createElement("lol-uikit-radio-input-option");return n.setAttribute("style","margin-left: 16px; font-family: Arial;"),n.setAttribute("selected",e?"true":"false"),n.textContent=t,n}let h=null;const I={enabled:!1,champions:[429,136]},q={enabled:!1,force:!1,champions:[350,221]},B=async t=>{if(t.data==="ChampSelect")for(;await D()==="ChampSelect";){const e=await x();if(await P(e),e.timer.phase==="FINALIZATION")return;await S(200)}},P=async t=>{const{localPlayerCellId:e,actions:n,bans:o,myTeam:c,theirTeam:l}=t,p=[...o.myTeamBans,...o.theirTeamBans],m=[...c,...l],u=DataStore.get("pickChampion"),d=DataStore.get("banChampion");for(const a of n)for(const s of a)if(!(s.completed||s.actorCellId!=e)){if(s.type==="pick"&&u.enabled){for(const i of u.champions)if(!p.some(r=>r==i)&&!m.some(r=>r.championId==i)&&await w(s.id,i))return}if(s.type==="ban"&&d.enabled){for(const i of d.champions)if(!p.some(r=>r==i)&&!(!d.force&&c.some(r=>r.championPickIntent==i))){if(await w(s.id,i))return;break}}}};class f{constructor(e,n,o,c,l=!1){this.index=e,this.id=n,this.champions=o,this.selectedChampion=null,this.config=DataStore.get(this.id),this.element=A(this.id);for(const p of this.champions){const m=this.getOption(p);this.element.append(m)}l&&(this.element.style.filter="brightness(0.7)"),this.hoverText=this.element.shadowRoot.querySelector("div > dt > div"),this.element.onmouseenter=()=>{this.hoverText.textContent=c},this.element.onmouseleave=()=>{this.hoverText.textContent=this.selectedChampion}}getOption(e){const n=E(e.name);return n.onclick=()=>{this.config.champions[this.index]=e.id,this.selectedChampion=e.name,DataStore.set(this.id,this.config)},this.config.champions[this.index]==e.id&&(this.selectedChampion=e.name,n.setAttribute("selected","true")),n}}class C{constructor(e){this.element=document.createElement("div"),this.element.id=e}}class j{constructor(e){this.element=document.createElement("div"),this.element.className="alpha-version-panel",this.element.id=e}}class g{constructor(e,n){this.configKey=n,this.config=DataStore.get(this.configKey),this.element=T(e,this.config.enabled),this.element.onclick=()=>{this.config.enabled=!this.config.enabled,DataStore.set(this.configKey,this.config),this.config.enabled?this.element.setAttribute("selected","true"):this.element.removeAttribute("selected")}}}const G=()=>{const t=document.querySelector(".lol-social-lower-pane-container");if(!t||document.querySelector("#checkbox-container")||document.querySelector("#pick-dropdown-container")||document.querySelector("#ban-dropdown-container"))return;const e=new j("checkbox-container"),n=new C("pick-dropdown-container"),o=new C("ban-dropdown-container"),c=new g("Auto pick","pickChampion"),l=new g("Auto ban","banChampion"),p=new f(0,"pickChampion",h,"First pick option"),m=new f(1,"pickChampion",h,"Second pick option"),u=new f(0,"banChampion",h,"First ban option",!0),d=new f(1,"banChampion",h,"Second ban option",!0);e.element.append(c.element,l.element),n.element.append(p.element,m.element),o.element.append(u.element,d.element);const a=document.createElement("lol-social-roster-group");a.classList.add("group","group-label"),a.addEventListener("click",()=>{const i=a.nextElementSibling;i.style.display=i.style.display==="none"?"block":"none",a.querySelector(".arrow").toggleAttribute("open")});const s=document.createElement("div");s.append(e.element,n.element,o.element),t.append(a,s),a.querySelector("span").textContent="Auto pick/ban",a.querySelector(".group-header").removeAttribute("draggable")};window.addEventListener("load",async()=>{h=await v(),DataStore.has("pickChampion")||DataStore.set("pickChampion",I),DataStore.has("banChampion")||DataStore.set("banChampion",q),k("/lol-gameflow/v1/gameflow-phase",B),y(G),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:!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.0.0",
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
  }