auto-champion-select 1.4.0 → 1.6.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/dist/index.js +60 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,67 @@
|
|
|
1
|
-
(function(){"use strict";try{if(typeof document<"u"){var
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.appendChild(document.createTextNode(".dropdown-champions-default{position:inherit;width:-webkit-fill-available}.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-menu),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-content),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-options){top:auto;bottom:100%;transform-origin:bottom}.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(o)}}catch(d){console.error("vite-plugin-css-injected-by-js",d)}})();
|
|
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.
|
|
7
|
+
* @version 1.6.0
|
|
8
8
|
* @license GPL-3.0-or-later
|
|
9
9
|
*/
|
|
10
|
-
import{sleep as u,request as a,linkEndpoint as C}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const F={enabled:!1},T={enabled:!1,force:!1,champions:[21,21]},$={enabled:!1,force:!1,champions:[21,21]},p={controladoAutoAccept:F,controladoPick:T,controladoBan:$};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 u(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")||p.controladoPick,t=DataStore.get("controladoBan")||p.controladoBan;if(!e.enabled&&!t.enabled)return;const o=this.getLocalPlayerSubActions();if(o.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const s of o){const c=s.type==="pick"?e:t;if(c.enabled)for(const i of c.champions){if(this.allBans.some(r=>r==i)){console.debug(`auto-champion-select: Banning ${i} but it's already banned, skipping...`);continue}if(s.type==="ban"&&this.teamIntents.some(r=>r==i))if(c.force===!0)console.debug(`auto-champion-select: Banning ${i} but it's already picked, forcing...`);else{console.debug(`auto-champion-select: Banning ${i} but it's already picked, skipping...`);continue}if(s.type==="pick"&&this.allPicks.some(r=>r.championId==i))if(c.force===!0)console.debug(`auto-champion-select: Picking ${i} but it's already picked, forcing...`);else{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)break;return}}}getLocalPlayerSubActions(){return this.actions.flat().filter(e=>e.actorCellId===this.localPlayerCellId&&e.completed===!1).sort((e,t)=>{const o=e.type==="pick"?0:1,s=t.type==="pick"?0:1;return o-s})}selectChampion(e,t){const o=`/lol-champ-select/v1/session/actions/${e}`;return a("PATCH",o,{body:{championId:t,completed:!0}})}}class m{constructor(e,t,o,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=o,this.championsFunction=s,this.champions=null}async setup(){this.champions=await this.championsFunction(),this.config=DataStore.get(this.configKey)||p[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 o=this.getNewOption(t);this.element.appendChild(o)}if(!this.element.shadowRoot.querySelector("#controlado-placeholder")){const t=this.element.shadowRoot.querySelector(".ui-dropdown-current");t.style="display: flex; justify-content: space-between;";const o=this.getNewPlaceholder();t.appendChild(o)}}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);const o=this.element.shadowRoot.querySelector("#controlado-search");o&&(o.value="",this.filterOptions(""))}),this.config.champions[this.configIndex]===e.id&&t.setAttribute("selected","true"),t.innerText=e.name,t}getNewPlaceholder(){const e=document.createElement("div");e.classList.add("ui-dropdown-current-content"),e.style="writing-mode: tb-rl;",e.id="controlado-placeholder";const t=document.createElement("input");return t.id="controlado-search",t.type="text",t.placeholder=this.text,t.style="color: inherit; background: transparent; border: none; text-align: right; outline: none; font-family: inherit; font-size: inherit; font-weight: inherit;",t.addEventListener("input",o=>this.filterOptions(o.target.value)),e.appendChild(t),e}filterOptions(e){this.element.querySelectorAll("lol-uikit-dropdown-option").forEach(o=>{o.innerText.toLowerCase().includes(e.toLowerCase())?o.style.display="":o.style.display="none"})}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)||p[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 R{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 o=new Event("post-render");this.element.dispatchEvent(o),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 l="Balaclava: Auto Champion Select";class y{constructor(e,t,o,s,c,i,k){this.id=e,this.name=t,this.legend=o,this.tags=s,this.group=c,this.perform=this.perform.bind(this),this.callback=i,this.toasts=k}perform(){if(typeof this.callback.then=="function")return Toast.promise(this.callback,{loading:this.toasts.loading,success:this.toasts.success,error:this.toasts.error});try{const e=this.callback();Toast.success(this.toasts.success||(e?this.toasts.on:this.toasts.off))}catch(e){Toast.error(this.toasts.error),console.error(e)}}}class x extends y{constructor(e,t,o){super(`${t}Switch`,()=>{var s;return`Auto ${e} [${(s=DataStore.get(t))!=null&&s.enabled?"ON":"OFF"}]`},()=>{var s;return(s=DataStore.get(t))!=null&&s.enabled?"Turn OFF":"Turn ON"},[l,t,"switch"],l,o,{on:`Auto ${e} is ON!`,off:`Auto ${e} is OFF!`,error:`Failed to toggle Auto ${e}. Check console.`})}}class D extends y{constructor(e,t){super(`${t}ForceSwitch`,()=>{var o;return`Force ${e} [${(o=DataStore.get(t))!=null&&o.force?"ON":"OFF"}]`},()=>`Ignore team intent and force ${e} the selected champion`,[l,t,"force","switch"],l,()=>this.switchDataStore(t),{on:`Force ${e} is ON!`,off:`Force ${e} is OFF!`,error:`Failed to toggle Force ${e}. Check console.`})}switchDataStore(e){const t=DataStore.get(e);return t.force=!t.force,DataStore.set(e,t),t.force}}class L extends y{constructor(e){super("RefreshDropdowns",()=>"Refresh Dropdowns",()=>"Normally dropdowns refresh automatically...",[l,"refresh"],l,()=>this.refreshDropdowns(e),{success:"Refreshed Dropdowns!",error:"Failed to refresh Dropdowns. Check console."})}refreshDropdowns(e){for(let t of e)t.refresh()}}class O extends x{constructor(e){super("Pick","controladoPick",e)}}class N extends x{constructor(e){super("Ban","controladoBan",e)}}class q extends D{constructor(){super("Pick","controladoPick")}}class j extends D{constructor(){super("Ban","controladoBan")}}function G(n){for(let e of n)CommandBar.addAction(e)}const K="1.4.0";const S=new I,w=new b("Accept","controladoAutoAccept"),f=new b("Pick","controladoPick"),h=new m("1st pick","controladoPick",0,B),d=new m("2nd pick","controladoPick",1,B),g=new b("Ban","controladoBan"),A=new m("1st ban","controladoBan",0,E),P=new m("2nd ban","controladoBan",1,E);function v(){return document.querySelector(".lol-social-roster")}async function B(){let n=await a("GET","/lol-champions/v1/owned-champions-minimal");for(;!n.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),n=await a("GET","/lol-champions/v1/owned-champions-minimal"),await u(1e3);const e=await n.json();return e.sort((t,o)=>t.name.localeCompare(o.name)),e}async function E(){const e=await(await a("GET","/lol-game-data/assets/v1/champion-summary.json")).json();return e.sort((t,o)=>t.name.localeCompare(o.name)),e}async function H(){w.config.enabled===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await u(2e3),await M())}async function M(){const n=await a("POST","/lol-matchmaking/v1/ready-check/accept");n.ok?console.debug("auto-champion-select(auto-accept): Accepted ready check"):console.error("auto-champion-select(auto-accept): Failed to accept ready check",n)}window.addEventListener("load",async()=>{let n=v();for(;!n;)await u(200),n=v();Promise.all([w.setup(),f.setup(),g.setup(),h.setup(),d.setup(),A.setup(),P.setup()]),G([new O(()=>f.toggle()),new N(()=>g.toggle()),new q,new j,new L([h,d])]),C("/lol-inventory/v1/wallet",s=>{s.eventType==="Update"&&(console.debug("auto-champion-select(wallet): Refreshing dropdowns..."),Promise.all([h.refresh(),d.refresh()]))}),C("/lol-gameflow/v1/gameflow-phase",s=>{s.data==="ReadyCheck"&&H(),s.data==="ChampSelect"?S.mount():S.unmount()});const e=document.createElement("div"),t=document.createElement("div");t.classList.add("auto-select-checkboxes-div"),t.append(w.element,f.element,g.element),e.append(h.element,d.element),e.append(A.element,P.element);const o=new R("Auto champion select",e,t);n.append(o.element,t,e),console.debug(`auto-champion-select(${K}): Report bugs to Balaclava#1912`)});
|
|
10
|
+
import{sleep as u,request as c,linkEndpoint as S}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const T={enabled:!1},B={enabled:!1,force:!1,champions:[21,21]},F={enabled:!1,force:!1,champions:[21,21]},p={controladoAutoAccept:T,controladoPick:B,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 u(300)}async updateProperties(){const e=await c("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")||p.controladoPick,t=DataStore.get("controladoBan")||p.controladoBan;if(!e.enabled&&!t.enabled)return;const o=this.getLocalPlayerSubActions();if(o.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const n of o){const i=n.type==="pick"?e:t;if(i.enabled)for(const a of i.champions){if(this.allBans.some(l=>l==a)){console.debug(`auto-champion-select: Banning ${a} but it's already banned, skipping...`);continue}if(n.type==="ban"&&this.teamIntents.some(l=>l==a))if(i.force===!0)console.debug(`auto-champion-select: Banning ${a} but it's already picked, forcing...`);else{console.debug(`auto-champion-select: Banning ${a} but it's already picked, skipping...`);continue}if(n.type==="pick"&&this.allPicks.some(l=>l.championId==a))if(i.force===!0)console.debug(`auto-champion-select: Picking ${a} but it's already picked, forcing...`);else{console.debug(`auto-champion-select: Picking ${a} but it's already picked, skipping...`);continue}if(console.debug(`auto-champion-select: Trying to ${n.type} ${a}...`),(await this.selectChampion(n.id,a)).ok)break;return}}}getLocalPlayerSubActions(){return this.actions.flat().filter(e=>e.actorCellId===this.localPlayerCellId&&e.completed===!1).sort((e,t)=>{const o=e.type==="pick"?0:1,n=t.type==="pick"?0:1;return o-n})}selectChampion(e,t){const o=`/lol-champ-select/v1/session/actions/${e}`;return c("PATCH",o,{body:{championId:t,completed:!0}})}}class m{constructor(e,t,o,n){this.element=document.createElement("lol-uikit-framed-dropdown"),this.element.classList.add("dropdown-champions-default"),this.element.classList.add("dropdown-drop-up"),this.text=e,this.config=null,this.configKey=t,this.configIndex=o,this.championsFunction=n,this.champions=null}async setup(){this.champions=await this.championsFunction(),this.config=DataStore.get(this.configKey)||p[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 o=this.getNewOption(t);this.element.appendChild(o)}this.shadowRoot(t=>{if(!t.querySelector("#controlado-placeholder")){const o=t.querySelector(".ui-dropdown-current");o.style="display: flex; justify-content: space-between;";const n=this.getNewPlaceholder();o.appendChild(n)}}),this.applyShadowStyles()}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),console.debug(this.configKey,DataStore.get(this.configKey)),this.shadowRoot(o=>{const n=o.querySelector("#controlado-search");n&&(n.value="",this.filterOptions(""));const i=o.querySelector(".controlado-filter-icon--trash");i&&i.classList.remove("controlado-filter-icon--trash")})}),this.config.champions[this.configIndex]===e.id&&t.setAttribute("selected","true"),t.innerText=e.name,t}getNewPlaceholder(){const e=document.createElement("div");e.classList.add("controlado-tag","controlado-tag--search"),e.id="controlado-placeholder";const t=document.createElement("input");t.classList.add("controlado-filter-input"),t.id="controlado-search",t.type="text",t.placeholder=this.text;const o=document.createElement("span");return o.classList.add("controlado-filter-icon"),o.addEventListener("click",n=>{o.classList.contains("controlado-filter-icon--trash")&&(t.value="",this.filterOptions(""),o.classList.toggle("controlado-filter-icon--trash",!1))}),t.addEventListener("input",n=>{this.ensureIsOpened(),this.filterOptions(n.target.value),o.classList.toggle("controlado-filter-icon--trash",!!n.target.value)}),["pointerdown","click"].forEach(n=>{e.addEventListener(n,i=>i.stopPropagation()),o.addEventListener(n,i=>i.stopPropagation())}),["pointerdown","focusin"].forEach(n=>{t.addEventListener(n,i=>i.stopPropagation(),!0)}),e.appendChild(o),e.appendChild(t),e}filterOptions(e){this.element.querySelectorAll("lol-uikit-dropdown-option").forEach(o=>{o.innerText.toLowerCase().includes(e.toLowerCase())?o.style.display="":o.style.display="none"})}refresh(){this.element.innerHTML="",this.setup()}isOpen(){return this.element.classList.contains("active")}ensureIsOpened(){this.isOpen()||this.shadowRoot(e=>{const t=e.querySelector(".ui-dropdown-current");t&&t.click()})}shadowRoot(e){const t=this.element.shadowRoot;t&&e(t)}applyShadowStyles(){this.shadowRoot(e=>{this.injectTagStyles(e);const t=e.querySelector(".ui-dropdown-current");t&&(t.style.paddingRight="28px");const o=e.querySelector(".ui-dropdown-options-container");o&&(o.style.top="auto",o.style.bottom="100%",o.style.transformOrigin="bottom",o.style.transform="translateY(0)");const n=e.querySelector("lol-uikit-scrollable");n&&(n.style.maxHeight="250px")})}injectTagStyles(e){const t=document.createElement("style");t.dataset.controlado="dropdown-tags",t.textContent=`
|
|
11
|
+
.controlado-filter-icon {
|
|
12
|
+
cursor: default;
|
|
13
|
+
display: inline-block;
|
|
14
|
+
width: 18px;
|
|
15
|
+
height: 18px;
|
|
16
|
+
background-color: #c8aa6e;
|
|
17
|
+
-webkit-mask-image: url('/fe/lol-social/search_mask.png');
|
|
18
|
+
-webkit-mask-repeat: no-repeat;
|
|
19
|
+
-webkit-mask-position: center;
|
|
20
|
+
-webkit-mask-size: 18px 18px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.controlado-filter-icon--trash {
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
background-color: #c86e6e;
|
|
26
|
+
-webkit-mask-image: url('/fe/lol-uikit/images/icon_delete.png');
|
|
27
|
+
-webkit-mask-size: 12px 12px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.controlado-filter-input {
|
|
31
|
+
color: inherit;
|
|
32
|
+
background: transparent;
|
|
33
|
+
border: none;
|
|
34
|
+
text-align: center;
|
|
35
|
+
outline: none;
|
|
36
|
+
font-family: inherit;
|
|
37
|
+
font-size: inherit;
|
|
38
|
+
font-weight: inherit;
|
|
39
|
+
width: 40px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.controlado-tag {
|
|
43
|
+
cursor: default;
|
|
44
|
+
display: inline-flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
gap: 4px;
|
|
47
|
+
padding: 2px 10px;
|
|
48
|
+
border-radius: 999px;
|
|
49
|
+
border: 1px solid #c8aa6e;
|
|
50
|
+
background: linear-gradient(145deg, #0f1b2d, #0a121a);
|
|
51
|
+
color: #f3d7a5;
|
|
52
|
+
font-size: 11px;
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
letter-spacing: 0.4px;
|
|
55
|
+
text-transform: uppercase;
|
|
56
|
+
white-space: nowrap;
|
|
57
|
+
box-shadow: inset 0 0 8px rgba(15, 30, 45, 0.6);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.controlado-tag--search {
|
|
61
|
+
border-color: #d7b46a;
|
|
62
|
+
color: #f6e1b2;
|
|
63
|
+
background: linear-gradient(145deg, #1a232f, #0f1722);
|
|
64
|
+
text-transform: none;
|
|
65
|
+
font-weight: 500;
|
|
66
|
+
}
|
|
67
|
+
`,e.appendChild(t)}}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)||p[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 o=new Event("post-render");this.element.dispatchEvent(o),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 r="Balaclava: Auto Champion Select";class k{constructor(e,t,o,n,i,a,y){this.id=e,this.name=t,this.legend=o,this.tags=n,this.group=i,this.perform=this.perform.bind(this),this.callback=a,this.toasts=y}perform(){if(typeof this.callback.then=="function")return Toast.promise(this.callback,{loading:this.toasts.loading,success:this.toasts.success,error:this.toasts.error});try{const e=this.callback();Toast.success(this.toasts.success||(e?this.toasts.on:this.toasts.off))}catch(e){Toast.error(this.toasts.error),console.error(e)}}}class v extends k{constructor(e,t,o){super(`${t}Switch`,()=>{var n;return`Auto ${e} [${(n=DataStore.get(t))!=null&&n.enabled?"ON":"OFF"}]`},()=>{var n;return(n=DataStore.get(t))!=null&&n.enabled?"Turn OFF":"Turn ON"},[r,t,"switch"],r,o,{on:`Auto ${e} is ON!`,off:`Auto ${e} is OFF!`,error:`Failed to toggle Auto ${e}. Check console.`})}}class E extends k{constructor(e,t){super(`${t}ForceSwitch`,()=>{var o;return`Force ${e} [${(o=DataStore.get(t))!=null&&o.force?"ON":"OFF"}]`},()=>`Ignore team intent and force ${e} the selected champion`,[r,t,"force","switch"],r,()=>this.switchDataStore(t),{on:`Force ${e} is ON!`,off:`Force ${e} is OFF!`,error:`Failed to toggle Force ${e}. Check console.`})}switchDataStore(e){const t=DataStore.get(e);return t.force=!t.force,DataStore.set(e,t),t.force}}class R extends k{constructor(e){super("RefreshDropdowns",()=>"Refresh Dropdowns",()=>"Normally dropdowns refresh automatically...",[r,"refresh"],r,()=>this.refreshDropdowns(e),{success:"Refreshed Dropdowns!",error:"Failed to refresh Dropdowns. Check console."})}refreshDropdowns(e){for(let t of e)t.refresh()}}class $ extends v{constructor(e){super("Pick","controladoPick",e)}}class q extends v{constructor(e){super("Ban","controladoBan",e)}}class N extends E{constructor(){super("Pick","controladoPick")}}class j extends E{constructor(){super("Ban","controladoBan")}}function G(s){for(let e of s)CommandBar.addAction(e)}const K="1.6.0";const x=new I,w=new b("Accept","controladoAutoAccept"),f=new b("Pick","controladoPick"),d=new m("1st pick","controladoPick",0,D),h=new m("2nd pick","controladoPick",1,D),g=new b("Ban","controladoBan"),C=new m("1st ban","controladoBan",0,L),P=new m("2nd ban","controladoBan",1,L);function A(){return document.querySelector(".lol-social-roster")}async function D(){let s=await c("GET","/lol-champions/v1/owned-champions-minimal");for(;!s.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),s=await c("GET","/lol-champions/v1/owned-champions-minimal"),await u(1e3);const e=await s.json();return e.sort((t,o)=>t.name.localeCompare(o.name)),e}async function L(){const e=await(await c("GET","/lol-game-data/assets/v1/champion-summary.json")).json();return e.sort((t,o)=>t.name.localeCompare(o.name)),e}async function z(){w.config.enabled===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await u(2e3),await _())}async function _(){const s=await c("POST","/lol-matchmaking/v1/ready-check/accept");s.ok?console.debug("auto-champion-select(auto-accept): Accepted ready check"):console.error("auto-champion-select(auto-accept): Failed to accept ready check",s)}window.addEventListener("load",async()=>{let s=A();for(;!s;)await u(200),s=A();Promise.all([w.setup(),f.setup(),g.setup(),d.setup(),h.setup(),C.setup(),P.setup()]),G([new $(()=>f.toggle()),new q(()=>g.toggle()),new N,new j,new R([d,h])]),S("/lol-inventory/v1/wallet",n=>{n.eventType==="Update"&&(console.debug("auto-champion-select(wallet): Refreshing dropdowns..."),Promise.all([d.refresh(),h.refresh()]))}),S("/lol-gameflow/v1/gameflow-phase",n=>{n.data==="ReadyCheck"&&z(),n.data==="ChampSelect"?x.mount():x.unmount()});const e=document.createElement("div"),t=document.createElement("div");t.classList.add("auto-select-checkboxes-div"),t.append(w.element,f.element,g.element),e.append(d.element,h.element),e.append(C.element,P.element);const o=new O("Auto champion select",e,t);s.append(o.element,t,e),console.debug(`auto-champion-select(${K}): Report bugs to Balaclava#1912`)});
|