auto-champion-select 1.7.5 → 1.7.6

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.
Files changed (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@
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.5
7
+ * @version 1.7.6
8
8
  * @license GPL-3.0-or-later
9
9
  */
10
- import{sleep as h,request as d,linkEndpoint as T}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const G={enabled:!1},j={enabled:!1,force:!1,champions:[21,21]},z={enabled:!1,force:!1,champions:[21,21]},k={controladoAutoAccept:G,controladoPick:j,controladoBan:z};class H{constructor(){this.session=null,this.actions=null,this.localPlayerCellId=null,this.teamIntents=null,this.allPicks=null,this.allBans=null,this.mounted=!1,this.watchTask=null,this.watchVersion=0}mount(){this.mounted||(this.mounted=!0,this.watchVersion+=1,this.watchTask||(this.watchTask=this.watch()))}unmount(){this.mounted&&(this.mounted=!1,this.watchVersion+=1)}async watch(){try{for(;this.mounted;){const t=this.watchVersion;let e=!1;try{await this.updateProperties(),e=!0}catch(o){console.debug("auto-champion-select: Failed to update champion select",o)}if(!e||!this.mounted||t!==this.watchVersion){this.mounted&&t===this.watchVersion&&await h(300);continue}try{await this.task()}catch(o){console.debug("auto-champion-select: Failed to run champion select task",o)}this.mounted&&t===this.watchVersion&&await h(300)}}finally{this.watchTask=null}}async updateProperties(){const t=await d("GET","/lol-champ-select/v1/session");if(!t.ok)throw new Error(`Session request failed with status ${t.status}`);this.session=await t.json(),this.actions=this.session.actions;const e=this.actions.flat().filter(o=>o.type==="ban"&&o.completed===!0&&o.championId>0).map(o=>o.championId);this.localPlayerCellId=this.session.localPlayerCellId,this.allPicks=[...this.session.myTeam,...this.session.theirTeam],this.allBans=[...this.session.bans.myTeamBans,...this.session.bans.theirTeamBans,...e],this.teamIntents=this.session.myTeam.map(o=>o.championPickIntent)}async task(){const t=DataStore.get("controladoPick")||k.controladoPick,e=DataStore.get("controladoBan")||k.controladoBan;if(!t.enabled&&!e.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){if(n.type!=="pick"&&n.isInProgress!==!0)continue;const i=n.type==="pick"?t:e;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){console.debug(`auto-champion-select: Failed to ${n.type} ${a}, trying next...`);continue}break}}}getLocalPlayerSubActions(){return this.actions.flat().filter(t=>t.actorCellId===this.localPlayerCellId&&t.completed===!1).sort((t,e)=>{const o=t.type==="pick"?0:1,n=e.type==="pick"?0:1;return o-n})}selectChampion(t,e){const o=`/lol-champ-select/v1/session/actions/${t}`;return d("PATCH",o,{body:{championId:e,completed:!0}})}}class S{constructor(t,e,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=t,this.config=null,this.configKey=e,this.configIndex=o,this.championsFunction=n,this.champions=null,this.setupInFlight=null,this.setupPending=!1}async setup(){return this.setupPending=!0,this.setupInFlight||(this.setupInFlight=this.runSetupLoop()),this.setupInFlight}async runSetupLoop(){try{for(;this.setupPending;)this.setupPending=!1,await this.performSetup()}finally{this.setupInFlight=null}if(this.setupPending)return this.setup()}async performSetup(){this.champions=await this.championsFunction(),this.config=DataStore.get(this.configKey)||k[this.configKey],this.champions.some(o=>this.config.champions[this.configIndex]===o.id)||(this.config.champions[this.configIndex]=this.champions[0].id,DataStore.set(this.configKey,this.config)),this.element.replaceChildren();const t=new Set;for(const o of this.champions){if(t.has(o.name))continue;const n=this.getNewOption(o);this.element.appendChild(n),t.add(o.name)}const e=await this.waitForDropdownRender();e&&(this.ensureSearchPlaceholder(e),this.applyShadowStyles())}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),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]===t.id&&e.setAttribute("selected","true"),e.innerText=t.name,e}getNewPlaceholder(){const t=document.createElement("div");t.classList.add("controlado-tag","controlado-tag--search"),t.id="controlado-placeholder";const e=document.createElement("input");e.classList.add("controlado-filter-input"),e.id="controlado-search",e.type="text",e.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")&&(e.value="",this.filterOptions(""),o.classList.toggle("controlado-filter-icon--trash",!1))}),e.addEventListener("input",n=>{this.ensureIsOpened(),this.filterOptions(n.target.value),o.classList.toggle("controlado-filter-icon--trash",!!n.target.value)}),["pointerdown","click"].forEach(n=>{t.addEventListener(n,i=>i.stopPropagation()),o.addEventListener(n,i=>i.stopPropagation())}),["pointerdown","focusin"].forEach(n=>{e.addEventListener(n,i=>i.stopPropagation(),!0)}),t.appendChild(o),t.appendChild(e),t}async waitForDropdownRender(){for(let t=0;t<50;t++){const e=this.element.shadowRoot;if(this.element.isConnected&&(e!=null&&e.querySelector(".ui-dropdown-current")))return e;await h(100)}return null}ensureSearchPlaceholder(t){if(t.querySelector("#controlado-placeholder"))return;const e=t.querySelector(".ui-dropdown-current");e&&(e.style="display: flex; justify-content: space-between;",e.appendChild(this.getNewPlaceholder()))}filterOptions(t){const e=t.toLowerCase();this.element.querySelectorAll("lol-uikit-dropdown-option").forEach(n=>{(n.textContent??"").toLowerCase().includes(e)?n.style.display="":n.style.display="none"})}refresh(){return this.setup()}isOpen(){return this.element.classList.contains("active")}ensureIsOpened(){this.isOpen()||this.shadowRoot(t=>{const e=t.querySelector(".ui-dropdown-current");e&&e.click()})}shadowRoot(t){const e=this.element.shadowRoot;e&&t(e)}applyShadowStyles(){this.shadowRoot(t=>{this.injectTagStyles(t);const e=t.querySelector(".ui-dropdown-current");e&&(e.style.paddingRight="28px");const o=t.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=t.querySelector("lol-uikit-scrollable");n&&(n.style.maxHeight="250px")})}injectTagStyles(t){if(t.querySelector("style[data-controlado='dropdown-tags']"))return;const e=document.createElement("style");e.dataset.controlado="dropdown-tags",e.textContent=`
10
+ import{sleep as d,request as p,linkEndpoint as T}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const G={enabled:!1},j={enabled:!1,force:!1,champions:[21,21]},z={enabled:!1,force:!1,champions:[21,21]},k={controladoAutoAccept:G,controladoPick:j,controladoBan:z};class H{constructor(){this.session=null,this.actions=null,this.localPlayerCellId=null,this.teamIntents=null,this.allPicks=null,this.allBans=null,this.mounted=!1,this.watchTask=null,this.watchVersion=0}mount(){this.mounted||(this.mounted=!0,this.watchVersion+=1,this.watchTask||(this.watchTask=this.watch()))}unmount(){this.mounted&&(this.mounted=!1,this.watchVersion+=1)}async watch(){try{for(;this.mounted;){const t=this.watchVersion;let e=!1;try{await this.updateProperties(),e=!0}catch(o){console.debug("auto-champion-select: Failed to update champion select",o)}if(!e||!this.mounted||t!==this.watchVersion){this.mounted&&t===this.watchVersion&&await d(300);continue}try{await this.task()}catch(o){console.debug("auto-champion-select: Failed to run champion select task",o)}this.mounted&&t===this.watchVersion&&await d(300)}}finally{this.watchTask=null}}async updateProperties(){const t=await p("GET","/lol-champ-select/v1/session");if(!t.ok)throw new Error(`Session request failed with status ${t.status}`);this.session=await t.json(),this.actions=this.session.actions;const e=this.actions.flat().filter(o=>o.type==="ban"&&o.completed===!0&&o.championId>0).map(o=>o.championId);this.localPlayerCellId=this.session.localPlayerCellId,this.allPicks=[...this.session.myTeam,...this.session.theirTeam],this.allBans=[...this.session.bans.myTeamBans,...this.session.bans.theirTeamBans,...e],this.teamIntents=this.session.myTeam.map(o=>o.championPickIntent)}async task(){const t=DataStore.get("controladoPick")||k.controladoPick,e=DataStore.get("controladoBan")||k.controladoBan;if(!t.enabled&&!e.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){if(n.type!=="pick"&&n.isInProgress!==!0)continue;const i=n.type==="pick"?t:e;if(i.enabled)for(const a of i.champions){if(this.shouldSkipChampion(n,a,i))continue;if(console.debug(`auto-champion-select: Trying to ${n.type} ${a}...`),!(await this.selectChampion(n.id,a)).ok){console.debug(`auto-champion-select: Failed to ${n.type} ${a}, refreshing champ select state...`);try{await this.updateProperties()}catch(r){console.debug("auto-champion-select: Failed to refresh champion select after select failure",r);return}const h=this.actions.flat().find(r=>r.id===n.id&&r.actorCellId===n.actorCellId&&r.type===n.type&&r.completed===!1);if(!h||h.type!=="pick"&&h.isInProgress!==!0||!this.shouldSkipChampion(h,a,i))return;console.debug(`auto-champion-select: ${a} is unavailable after refresh, trying next ${n.type}...`);continue}break}}}shouldSkipChampion(t,e,o){if(this.allBans.some(n=>n==e))return console.debug(`auto-champion-select: Banning ${e} but it's already banned, skipping...`),!0;if(t.type==="ban"&&this.teamIntents.some(n=>n==e))if(o.force===!0)console.debug(`auto-champion-select: Banning ${e} but it's already picked, forcing...`);else return console.debug(`auto-champion-select: Banning ${e} but it's already picked, skipping...`),!0;if(t.type==="pick"&&this.allPicks.some(n=>n.championId==e))if(o.force===!0)console.debug(`auto-champion-select: Picking ${e} but it's already picked, forcing...`);else return console.debug(`auto-champion-select: Picking ${e} but it's already picked, skipping...`),!0;return!1}getLocalPlayerSubActions(){return this.actions.flat().filter(t=>t.actorCellId===this.localPlayerCellId&&t.completed===!1).sort((t,e)=>{const o=t.type==="pick"?0:1,n=e.type==="pick"?0:1;return o-n})}selectChampion(t,e){const o=`/lol-champ-select/v1/session/actions/${t}`;return p("PATCH",o,{body:{championId:e,completed:!0}})}}class S{constructor(t,e,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=t,this.config=null,this.configKey=e,this.configIndex=o,this.championsFunction=n,this.champions=null,this.setupInFlight=null,this.setupPending=!1}async setup(){return this.setupPending=!0,this.setupInFlight||(this.setupInFlight=this.runSetupLoop()),this.setupInFlight}async runSetupLoop(){try{for(;this.setupPending;)this.setupPending=!1,await this.performSetup()}finally{this.setupInFlight=null}if(this.setupPending)return this.setup()}async performSetup(){this.champions=await this.championsFunction(),this.config=DataStore.get(this.configKey)||k[this.configKey],this.champions.some(o=>this.config.champions[this.configIndex]===o.id)||(this.config.champions[this.configIndex]=this.champions[0].id,DataStore.set(this.configKey,this.config)),this.element.replaceChildren();const t=new Set;for(const o of this.champions){if(t.has(o.name))continue;const n=this.getNewOption(o);this.element.appendChild(n),t.add(o.name)}const e=await this.waitForDropdownRender();e&&(this.ensureSearchPlaceholder(e),this.applyShadowStyles())}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),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]===t.id&&e.setAttribute("selected","true"),e.innerText=t.name,e}getNewPlaceholder(){const t=document.createElement("div");t.classList.add("controlado-tag","controlado-tag--search"),t.id="controlado-placeholder";const e=document.createElement("input");e.classList.add("controlado-filter-input"),e.id="controlado-search",e.type="text",e.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")&&(e.value="",this.filterOptions(""),o.classList.toggle("controlado-filter-icon--trash",!1))}),e.addEventListener("input",n=>{this.ensureIsOpened(),this.filterOptions(n.target.value),o.classList.toggle("controlado-filter-icon--trash",!!n.target.value)}),["pointerdown","click"].forEach(n=>{t.addEventListener(n,i=>i.stopPropagation()),o.addEventListener(n,i=>i.stopPropagation())}),["pointerdown","focusin"].forEach(n=>{e.addEventListener(n,i=>i.stopPropagation(),!0)}),t.appendChild(o),t.appendChild(e),t}async waitForDropdownRender(){for(let t=0;t<50;t++){const e=this.element.shadowRoot;if(this.element.isConnected&&(e!=null&&e.querySelector(".ui-dropdown-current")))return e;await d(100)}return null}ensureSearchPlaceholder(t){if(t.querySelector("#controlado-placeholder"))return;const e=t.querySelector(".ui-dropdown-current");e&&(e.style="display: flex; justify-content: space-between;",e.appendChild(this.getNewPlaceholder()))}filterOptions(t){const e=t.toLowerCase();this.element.querySelectorAll("lol-uikit-dropdown-option").forEach(n=>{(n.textContent??"").toLowerCase().includes(e)?n.style.display="":n.style.display="none"})}refresh(){return this.setup()}isOpen(){return this.element.classList.contains("active")}ensureIsOpened(){this.isOpen()||this.shadowRoot(t=>{const e=t.querySelector(".ui-dropdown-current");e&&e.click()})}shadowRoot(t){const e=this.element.shadowRoot;e&&t(e)}applyShadowStyles(){this.shadowRoot(t=>{this.injectTagStyles(t);const e=t.querySelector(".ui-dropdown-current");e&&(e.style.paddingRight="28px");const o=t.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=t.querySelector("lol-uikit-scrollable");n&&(n.style.maxHeight="250px")})}injectTagStyles(t){if(t.querySelector("style[data-controlado='dropdown-tags']"))return;const e=document.createElement("style");e.dataset.controlado="dropdown-tags",e.textContent=`
11
11
  .controlado-filter-icon {
12
12
  cursor: default;
13
13
  display: inline-block;
@@ -64,4 +64,4 @@ import{sleep as h,request as d,linkEndpoint as T}from"https://cdn.jsdelivr.net/n
64
64
  text-transform: none;
65
65
  font-weight: 500;
66
66
  }
67
- `,t.appendChild(e)}}class E{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)||k[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 K{constructor(t,e,...o){this.element=document.createElement("div"),this.element.classList.add("auto-select-champ-select-menu","auto-select-champ-select-menu--collapsed"),this.buttonWrapper=document.createElement("div"),this.buttonWrapper.classList.add("auto-select-champ-select-menu-button-wrapper"),this.headerElement=document.createElement("button"),this.headerElement.classList.add("auto-select-champ-select-menu__header"),this.headerElement.type="button",this.headerElement.setAttribute("aria-label",t),this.headerElement.setAttribute("aria-expanded","false"),this.headerElement.addEventListener("click",()=>this.toggle()),this.contentElement=document.createElement("div"),this.contentElement.classList.add("auto-select-champ-select-menu__content"),this.titleElement=document.createElement("div"),this.titleElement.classList.add("auto-select-champ-select-menu__title"),this.titleElement.textContent=t,this.buttonWrapper.append(this.headerElement,this.element),this.contentElement.appendChild(this.titleElement),this.element.appendChild(this.contentElement),this.restoreControls=e,this.controlElements=o,this.boundCloseOnOutsideInteraction=n=>this.closeOnOutsideInteraction(n),this.buttonObserver=null,this.buttonMountFrame=null,this.buttonMountTask=null,this.hiddenStates=new WeakMap,this.mounted=!1}async mount(){return this.mounted?this.mountButton():(this.mounted=!0,this.controlElements.forEach(t=>{this.hiddenStates.set(t,t.classList.contains("hidden")),t.classList.remove("hidden"),this.contentElement.appendChild(t)}),this.observeButtonContainer(),document.addEventListener("pointerdown",this.boundCloseOnOutsideInteraction,!0),this.mountButton())}unmount(){var t;return this.mounted?(this.mounted=!1,(t=this.buttonObserver)==null||t.disconnect(),this.buttonObserver=null,this.buttonMountFrame!==null&&(cancelAnimationFrame(this.buttonMountFrame),this.buttonMountFrame=null),this.buttonMountTask=null,document.removeEventListener("pointerdown",this.boundCloseOnOutsideInteraction,!0),this.setOpen(!1),this.buttonWrapper.remove(),this.restoreHiddenStates(),this.restoreControls()):this.restoreControls()}isOpen(){return!this.element.classList.contains("auto-select-champ-select-menu--collapsed")}setOpen(t){this.element.classList.toggle("auto-select-champ-select-menu--collapsed",!t),this.buttonWrapper.classList.toggle("auto-select-champ-select-menu-button-wrapper--open",t),this.headerElement.setAttribute("aria-expanded",String(t))}toggle(){this.setOpen(!this.isOpen())}closeOnOutsideInteraction(t){if(!this.isOpen())return;(typeof t.composedPath=="function"?t.composedPath():[]).includes(this.buttonWrapper)||this.buttonWrapper.contains(t.target)||this.setOpen(!1)}observeButtonContainer(){this.buttonObserver=new MutationObserver(()=>this.scheduleMountButton()),this.buttonObserver.observe(document.body,{childList:!0,subtree:!0})}scheduleMountButton(){this.buttonMountFrame===null&&(this.buttonMountFrame=requestAnimationFrame(()=>{this.buttonMountFrame=null,this.mountButton()}))}mountButton(){return this.buttonMountTask||(this.buttonMountTask=this.appendButtonToContainer().finally(()=>{this.buttonMountTask=null})),this.buttonMountTask}async appendButtonToContainer(){let t=document.querySelector(".bottom-right-buttons");for(;this.mounted&&!t;)await h(200),t=document.querySelector(".bottom-right-buttons");if(!this.mounted||!t)return;const e=t.querySelector("lol-social-chat-toggle-button, .missions-tracker-button-component, .champ-select-voice-button-wrapper");this.buttonWrapper.parentNode===t&&this.buttonWrapper.nextSibling===e||t.insertBefore(this.buttonWrapper,e)}restoreHiddenStates(){this.controlElements.forEach(t=>{t.classList.toggle("hidden",this.hiddenStates.get(t)===!0),this.hiddenStates.delete(t)})}}class Q{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 o=new Event("post-render");this.element.dispatchEvent(o),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.closest(".auto-select-champ-select-menu")||t.classList.toggle("hidden")}),this.element.querySelector(".arrow").toggleAttribute("open")}}const f="Balaclava: Auto Champion Select";class x{constructor(t,e,o,n,i,a,u){this.id=t,this.name=e,this.legend=o,this.tags=n,this.group=i,this.perform=this.perform.bind(this),this.callback=a,this.toasts=u}perform(){try{const t=this.callback();if(typeof(t==null?void 0:t.then)=="function")return Toast.promise(t,{loading:this.toasts.loading,success:this.toasts.success,error:this.toasts.error});Toast.success(this.toasts.success||(t?this.toasts.on:this.toasts.off))}catch(t){Toast.error(this.toasts.error),console.error(t)}}}class R extends x{constructor(t,e,o){super(`${e}Switch`,()=>{var n;return`Auto ${t} [${(n=DataStore.get(e))!=null&&n.enabled?"ON":"OFF"}]`},()=>{var n;return(n=DataStore.get(e))!=null&&n.enabled?"Turn OFF":"Turn ON"},[f,e,"switch"],f,o,{on:`Auto ${t} is ON!`,off:`Auto ${t} is OFF!`,error:`Failed to toggle Auto ${t}. Check console.`})}}class $ extends x{constructor(t,e){super(`${e}ForceSwitch`,()=>{var o;return`Force ${t} [${(o=DataStore.get(e))!=null&&o.force?"ON":"OFF"}]`},()=>`Ignore team intent and force ${t} the selected champion`,[f,e,"force","switch"],f,()=>this.switchDataStore(e),{on:`Force ${t} is ON!`,off:`Force ${t} is OFF!`,error:`Failed to toggle Force ${t}. Check console.`})}switchDataStore(t){const e=DataStore.get(t);return e.force=!e.force,DataStore.set(t,e),e.force}}class U extends x{constructor(t){super("RefreshDropdowns",()=>"Refresh Dropdowns",()=>"Normally dropdowns refresh automatically...",[f,"refresh"],f,()=>this.refreshDropdowns(t),{success:"Refreshed Dropdowns!",error:"Failed to refresh Dropdowns. Check console."})}refreshDropdowns(t){return Promise.all(t.map(e=>e.refresh()))}}class Y extends R{constructor(t){super("Pick","controladoPick",t)}}class J extends R{constructor(t){super("Ban","controladoBan",t)}}class X extends ${constructor(){super("Pick","controladoPick")}}class Z extends ${constructor(){super("Ban","controladoBan")}}function tt(s){for(let t of s)CommandBar.addAction(t)}const et="1.7.5";const ot=new H,P=new E("Accept","controladoAutoAccept"),C=new E("Pick","controladoPick"),g=new S("1st pick","controladoPick",0,M),w=new S("2nd pick","controladoPick",1,M),v=new E("Ban","controladoBan"),L=new S("1st ban","controladoBan",0,N),B=new S("2nd ban","controladoBan",1,N);function I(){return document.querySelector(".lol-social-roster")}let b=null,y=null;function M(){return b||(b=nt().finally(()=>{b=null})),b}async function nt(){let s=await d("GET","/lol-champions/v1/owned-champions-minimal");for(;!s.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),s=await d("GET","/lol-champions/v1/owned-champions-minimal"),await h(1e3);const t=await s.json();return t.sort((e,o)=>e.name.localeCompare(o.name)),t}function N(){return y||(y=st().finally(()=>{y=null})),y}async function st(){const t=await(await d("GET","/lol-game-data/assets/v1/champion-summary.json")).json();return t.sort((e,o)=>e.name.localeCompare(o.name)),t}async function it(){var s;((s=P.config)==null?void 0:s.enabled)===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await h(2e3),await at())}async function at(){const s=await d("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)}function rt({championSelect:s,championSelectMenu:t,setupDropdowns:e}){let o=0;return function(u){const l=++o;n(u,l).catch(p=>console.error("auto-champion-select: Failed to handle gameflow phase",p))};async function n(a,u){a==="ReadyCheck"&&it(),await i(a),u===o&&await e()}async function i(a){a==="ChampSelect"?(s.mount(),await t.mount()):(s.unmount(),await t.unmount())}}async function ct(){const s=document.createElement("div"),t=document.createElement("div");t.classList.add("auto-select-checkboxes-div"),t.append(P.element,C.element,v.element),s.append(g.element,w.element),s.append(L.element,B.element);const e=new Q("Auto champion select",s,t),o=[g,w,L,B];let n,i=null,a=0;async function u(c){let r=I();for(;!r;){if(n.mounted||c!==a)return;await h(200),r=I()}n.mounted||c!==a||r.append(e.element,t,s)}function l(){if(i)return i;const c=++a;return i=u(c).catch(r=>console.error("auto-champion-select: Failed to restore controls",r)).finally(()=>{i=null}),i}n=new K("Auto Champion Select",l,t,s),P.setup(),C.setup(),v.setup();const p=rt({championSelect:ot,championSelectMenu:n,setupDropdowns:V});T("/lol-gameflow/v1/gameflow-phase",c=>{p(c.data)});const A=await d("GET","/lol-gameflow/v1/gameflow-phase");A.ok?p(await A.json()):p(null),_(),tt([new Y(()=>C.toggle()),new J(()=>v.toggle()),new X,new Z,new U([g,w])]),T("/lol-inventory/v1/wallet",async c=>{c.eventType==="Update"&&(console.debug("auto-champion-select(wallet): Refreshing dropdowns..."),await Promise.all([g.refresh(),w.refresh()]))}),console.debug(`auto-champion-select(${et}): Report bugs to Balaclava#1912`);function V(){return Promise.all(o.map(c=>c.setup()))}function _(){let r=null,m=null;function F(){m==null||m.disconnect(),m=null,r!==null&&(cancelAnimationFrame(r),r=null)}const W=setTimeout(()=>{F()},6e4);function O(){if(!(document.querySelector(".bottom-right-buttons")!==null))return;clearTimeout(W),F(),document.querySelector(".auto-select-champ-select-menu__header")!==null||p("ChampSelect")}m=new MutationObserver(()=>{r===null&&(r=requestAnimationFrame(()=>{r=null,O()}))}),m.observe(document.body,{childList:!0,subtree:!0}),O()}}let D=!1;function q(){D||(D=!0,ct().catch(s=>console.error("auto-champion-select: Failed to initialize",s)))}document.readyState==="loading"?window.addEventListener("load",q,{once:!0}):q();export{q as load};
67
+ `,t.appendChild(e)}}class E{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)||k[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 K{constructor(t,e,...o){this.element=document.createElement("div"),this.element.classList.add("auto-select-champ-select-menu","auto-select-champ-select-menu--collapsed"),this.buttonWrapper=document.createElement("div"),this.buttonWrapper.classList.add("auto-select-champ-select-menu-button-wrapper"),this.headerElement=document.createElement("button"),this.headerElement.classList.add("auto-select-champ-select-menu__header"),this.headerElement.type="button",this.headerElement.setAttribute("aria-label",t),this.headerElement.setAttribute("aria-expanded","false"),this.headerElement.addEventListener("click",()=>this.toggle()),this.contentElement=document.createElement("div"),this.contentElement.classList.add("auto-select-champ-select-menu__content"),this.titleElement=document.createElement("div"),this.titleElement.classList.add("auto-select-champ-select-menu__title"),this.titleElement.textContent=t,this.buttonWrapper.append(this.headerElement,this.element),this.contentElement.appendChild(this.titleElement),this.element.appendChild(this.contentElement),this.restoreControls=e,this.controlElements=o,this.boundCloseOnOutsideInteraction=n=>this.closeOnOutsideInteraction(n),this.buttonObserver=null,this.buttonMountFrame=null,this.buttonMountTask=null,this.hiddenStates=new WeakMap,this.mounted=!1}async mount(){return this.mounted?this.mountButton():(this.mounted=!0,this.controlElements.forEach(t=>{this.hiddenStates.set(t,t.classList.contains("hidden")),t.classList.remove("hidden"),this.contentElement.appendChild(t)}),this.observeButtonContainer(),document.addEventListener("pointerdown",this.boundCloseOnOutsideInteraction,!0),this.mountButton())}unmount(){var t;return this.mounted?(this.mounted=!1,(t=this.buttonObserver)==null||t.disconnect(),this.buttonObserver=null,this.buttonMountFrame!==null&&(cancelAnimationFrame(this.buttonMountFrame),this.buttonMountFrame=null),this.buttonMountTask=null,document.removeEventListener("pointerdown",this.boundCloseOnOutsideInteraction,!0),this.setOpen(!1),this.buttonWrapper.remove(),this.restoreHiddenStates(),this.restoreControls()):this.restoreControls()}isOpen(){return!this.element.classList.contains("auto-select-champ-select-menu--collapsed")}setOpen(t){this.element.classList.toggle("auto-select-champ-select-menu--collapsed",!t),this.buttonWrapper.classList.toggle("auto-select-champ-select-menu-button-wrapper--open",t),this.headerElement.setAttribute("aria-expanded",String(t))}toggle(){this.setOpen(!this.isOpen())}closeOnOutsideInteraction(t){if(!this.isOpen())return;(typeof t.composedPath=="function"?t.composedPath():[]).includes(this.buttonWrapper)||this.buttonWrapper.contains(t.target)||this.setOpen(!1)}observeButtonContainer(){this.buttonObserver=new MutationObserver(()=>this.scheduleMountButton()),this.buttonObserver.observe(document.body,{childList:!0,subtree:!0})}scheduleMountButton(){this.buttonMountFrame===null&&(this.buttonMountFrame=requestAnimationFrame(()=>{this.buttonMountFrame=null,this.mountButton()}))}mountButton(){return this.buttonMountTask||(this.buttonMountTask=this.appendButtonToContainer().finally(()=>{this.buttonMountTask=null})),this.buttonMountTask}async appendButtonToContainer(){let t=document.querySelector(".bottom-right-buttons");for(;this.mounted&&!t;)await d(200),t=document.querySelector(".bottom-right-buttons");if(!this.mounted||!t)return;const e=t.querySelector("lol-social-chat-toggle-button, .missions-tracker-button-component, .champ-select-voice-button-wrapper");this.buttonWrapper.parentNode===t&&this.buttonWrapper.nextSibling===e||t.insertBefore(this.buttonWrapper,e)}restoreHiddenStates(){this.controlElements.forEach(t=>{t.classList.toggle("hidden",this.hiddenStates.get(t)===!0),this.hiddenStates.delete(t)})}}class Q{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 o=new Event("post-render");this.element.dispatchEvent(o),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.closest(".auto-select-champ-select-menu")||t.classList.toggle("hidden")}),this.element.querySelector(".arrow").toggleAttribute("open")}}const f="Balaclava: Auto Champion Select";class x{constructor(t,e,o,n,i,a,u){this.id=t,this.name=e,this.legend=o,this.tags=n,this.group=i,this.perform=this.perform.bind(this),this.callback=a,this.toasts=u}perform(){try{const t=this.callback();if(typeof(t==null?void 0:t.then)=="function")return Toast.promise(t,{loading:this.toasts.loading,success:this.toasts.success,error:this.toasts.error});Toast.success(this.toasts.success||(t?this.toasts.on:this.toasts.off))}catch(t){Toast.error(this.toasts.error),console.error(t)}}}class q extends x{constructor(t,e,o){super(`${e}Switch`,()=>{var n;return`Auto ${t} [${(n=DataStore.get(e))!=null&&n.enabled?"ON":"OFF"}]`},()=>{var n;return(n=DataStore.get(e))!=null&&n.enabled?"Turn OFF":"Turn ON"},[f,e,"switch"],f,o,{on:`Auto ${t} is ON!`,off:`Auto ${t} is OFF!`,error:`Failed to toggle Auto ${t}. Check console.`})}}class R extends x{constructor(t,e){super(`${e}ForceSwitch`,()=>{var o;return`Force ${t} [${(o=DataStore.get(e))!=null&&o.force?"ON":"OFF"}]`},()=>`Ignore team intent and force ${t} the selected champion`,[f,e,"force","switch"],f,()=>this.switchDataStore(e),{on:`Force ${t} is ON!`,off:`Force ${t} is OFF!`,error:`Failed to toggle Force ${t}. Check console.`})}switchDataStore(t){const e=DataStore.get(t);return e.force=!e.force,DataStore.set(t,e),e.force}}class U extends x{constructor(t){super("RefreshDropdowns",()=>"Refresh Dropdowns",()=>"Normally dropdowns refresh automatically...",[f,"refresh"],f,()=>this.refreshDropdowns(t),{success:"Refreshed Dropdowns!",error:"Failed to refresh Dropdowns. Check console."})}refreshDropdowns(t){return Promise.all(t.map(e=>e.refresh()))}}class Y extends q{constructor(t){super("Pick","controladoPick",t)}}class J extends q{constructor(t){super("Ban","controladoBan",t)}}class X extends R{constructor(){super("Pick","controladoPick")}}class Z extends R{constructor(){super("Ban","controladoBan")}}function tt(s){for(let t of s)CommandBar.addAction(t)}const et="1.7.6";const ot=new H,v=new E("Accept","controladoAutoAccept"),C=new E("Pick","controladoPick"),g=new S("1st pick","controladoPick",0,M),w=new S("2nd pick","controladoPick",1,M),P=new E("Ban","controladoBan"),L=new S("1st ban","controladoBan",0,N),B=new S("2nd ban","controladoBan",1,N);function I(){return document.querySelector(".lol-social-roster")}let b=null,y=null;function M(){return b||(b=nt().finally(()=>{b=null})),b}async function nt(){let s=await p("GET","/lol-champions/v1/owned-champions-minimal");for(;!s.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),s=await p("GET","/lol-champions/v1/owned-champions-minimal"),await d(1e3);const t=await s.json();return t.sort((e,o)=>e.name.localeCompare(o.name)),t}function N(){return y||(y=st().finally(()=>{y=null})),y}async function st(){const t=await(await p("GET","/lol-game-data/assets/v1/champion-summary.json")).json();return t.sort((e,o)=>e.name.localeCompare(o.name)),t}async function it(){var s;((s=v.config)==null?void 0:s.enabled)===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await d(2e3),await at())}async function at(){const s=await p("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)}function rt({championSelect:s,championSelectMenu:t,setupDropdowns:e}){let o=0;return function(u){const h=++o;n(u,h).catch(r=>console.error("auto-champion-select: Failed to handle gameflow phase",r))};async function n(a,u){a==="ReadyCheck"&&it(),await i(a),u===o&&await e()}async function i(a){a==="ChampSelect"?(s.mount(),await t.mount()):(s.unmount(),await t.unmount())}}async function ct(){const s=document.createElement("div"),t=document.createElement("div");t.classList.add("auto-select-checkboxes-div"),t.append(v.element,C.element,P.element),s.append(g.element,w.element),s.append(L.element,B.element);const e=new Q("Auto champion select",s,t),o=[g,w,L,B];let n,i=null,a=0;async function u(l){let c=I();for(;!c;){if(n.mounted||l!==a)return;await d(200),c=I()}n.mounted||l!==a||c.append(e.element,t,s)}function h(){if(i)return i;const l=++a;return i=u(l).catch(c=>console.error("auto-champion-select: Failed to restore controls",c)).finally(()=>{i=null}),i}n=new K("Auto Champion Select",h,t,s),v.setup(),C.setup(),P.setup();const r=rt({championSelect:ot,championSelectMenu:n,setupDropdowns:V});T("/lol-gameflow/v1/gameflow-phase",l=>{r(l.data)});const A=await p("GET","/lol-gameflow/v1/gameflow-phase");A.ok?r(await A.json()):r(null),_(),tt([new Y(()=>C.toggle()),new J(()=>P.toggle()),new X,new Z,new U([g,w])]),T("/lol-inventory/v1/wallet",async l=>{l.eventType==="Update"&&(console.debug("auto-champion-select(wallet): Refreshing dropdowns..."),await Promise.all([g.refresh(),w.refresh()]))}),console.debug(`auto-champion-select(${et}): Report bugs to Balaclava#1912`);function V(){return Promise.all(o.map(l=>l.setup()))}function _(){let c=null,m=null;function F(){m==null||m.disconnect(),m=null,c!==null&&(cancelAnimationFrame(c),c=null)}const W=setTimeout(()=>{F()},6e4);function O(){if(!(document.querySelector(".bottom-right-buttons")!==null))return;clearTimeout(W),F(),document.querySelector(".auto-select-champ-select-menu__header")!==null||r("ChampSelect")}m=new MutationObserver(()=>{c===null&&(c=requestAnimationFrame(()=>{c=null,O()}))}),m.observe(document.body,{childList:!0,subtree:!0}),O()}}let D=!1;function $(){D||(D=!0,ct().catch(s=>console.error("auto-champion-select: Failed to initialize",s)))}document.readyState==="loading"?window.addEventListener("load",$,{once:!0}):$();export{$ as load};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-champion-select",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "description": "Pick or ban automatically! 🐧",
5
5
  "author": "balaclava",
6
6
  "repository": {