UNPKG

random-champion

Version:

Pick and ban a random champion in champion select! 🐧

11 lines (10 loc) 3.14 kB
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".reroll-champion-button{background-color:#69655e;max-height:-webkit-fill-available;-webkit-mask:url(data:image/webp;base64,UklGRk4BAABXRUJQVlA4TEIBAAAvR8AREA4HkSQpkn+pKeNg+/fmmfm/8sWGAgAAIedtRX/6T7bN5mZH/2/L93k2khdXbW/JbLZtBm4bKUq3x7C8e/eEx4WTkPh1WXblw79HR5Z0y5EArw9ig3//UY6UkdcDmgF/z5XyBoBYA3zu/HfJGmo5gOFopxxWB3XPfpkHLUXhuUTSlVD6XoTzwgeA2U6xdQoggoLBkrIeA08dAimuml5NklQntNVhLCCbImM4YKUOT2E7RoYp4LoORtNznMFG4AK+hhurNwA5KggBD0MDqN4gybAGTA0tsnoDIWMoILreHpAz2BbYWsHz0OKTbK3Gdh7WUms1jrNg5dFr7NfdbIhpPASr6nBp5+Wl3fItvlZjuW7tiWOtBrUyuGnlROut98Kt7WOueSQ3045P6L0zgvo+kPDkNzNtm+Pxztnvz8AD) no-repeat center;-webkit-mask-size:28px}.reroll-champion-button:hover{background-color:#f0e6d2}.filter-icons{display:flex;height:20px;justify-content:space-between;margin-right:8px;margin-top:8px;width:auto!important}.filter-icons .filter:first-child{margin-block:-4px}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})(); /** * @author balaclava * @name random-champion * @link https://github.com/controlado/random-champion#readme * @description Pick and ban a random champion in champion select! 🐧 * @version 1.1.3 * @license GPL-3.0-or-later */ import{addRoutines as d,request as l,layerManager as r}from"https://cdn.skypack.dev/balaclava-utils@latest";const p="1.1.3";async function m(o,n){const e=document.querySelector(o);!e||e.hasAttribute(n)||(e.setAttribute(n,"true"),e.insertBefore(u(),e.firstChild))}function u(){const o=document.createElement("div");return o.classList.add("filter","reroll-champion-button"),o.onclick=async()=>{const n=f(),t=await(await l("GET","/lol-champ-select/v1/session")).json();for(const c of t.actions)for(const i of c)if(i.completed===!1&&i.actorCellId===t.localPlayerCellId){const s={championId:n[Math.floor(Math.random()*n.length)]};if((await l("PATCH",`/lol-champ-select/v1/session/actions/${i.id}`,{body:s})).ok)return}},h(o,"top","Select random champion in selected role."),o}function h(o,n,e){const t=document.createElement("div");t.setAttribute("id","lol-uikit-tooltip-root"),t.classList.add("tooltip","tooltip-random-champion");const c=document.createElement("lol-uikit-tooltip");c.setAttribute("data-tooltip-position",n),c.setAttribute("type","system");const i=document.createElement("lol-uikit-content-block");i.setAttribute("type","tooltip-system");const s=document.createElement("p");s.innerText=e,i.appendChild(s),c.appendChild(i),t.appendChild(c),o.onmouseenter=()=>{const a=o.getBoundingClientRect();t.style.top=`${a.top-48}px`,t.style.left=`${a.left-116}px`,r.appendChild(t)},o.onmouseleave=()=>{r.removeChild(t)}}function f(){const o=document.querySelectorAll(".champion-container > div > div > div > div"),n=[];for(const e of o){if(e.parentNode.style.display||e.hasAttribute("disabled"))continue;const t=e.getAttribute("data-id");t!=="-2"&&n.push(t)}return n}window.addEventListener("load",()=>{d(()=>m(".filter-icons","random-champion-setup")),console.debug(`random-champion(${p}): Report bugs to Balaclava#1912`)});