HarlockHrk / Silph Trophy Case

// ==UserScript==
// @name         Silph Trophy Case
// @namespace    Violentmonkey Scripts
// @match        https://sil.ph/*
// @match        https://thesilphroad.com/card
// @grant        none
// @version      1.3
// @author       pablopang
// @collaborator HarlockHrk
// @description  This script adds the missing season two badges from a Trainer Card on Silph Arena (properly arranging them all at the same time...)
// @copyright    2020, Paolo Ricciuti
// @license      Apache-2.0
// ==/UserScript==

let cups=document.querySelectorAll("#arenaHistory .cupBadge"),types=[],reg=/https:\/\/silph.gg\/img\/badges\/([\w-]+)\.png/,priority={participation:0,bronze:1,silver:2,gold:3,platinum:4,uranium:5};for(let e=cups.length-1;e>=0;e--){let t=cups[e],r=reg.exec(t.childNodes?t.childNodes[1].firstElementChild.src:""),p=r?r[1]:"",s=t.classList.value.replace("cupBadge ","");if(""!=p){let e=types.find(e=>e.cupType==p);e?e.priority<priority[s]&&(e.medal=s,e.priority=priority[s]):types.push({cupType:p,medal:s,priority:priority[s]})}}let h3Trophy=document.querySelector("#trophyCase > h3");h3Trophy.style.width="100%";let hrTrophy=document.querySelector("#trophyCase > hr");hrTrophy.style.width="100%";let textTrophy=document.querySelector("#trophyCase > p");textTrophy.style.width="100%";let trophyCase=document.querySelector("#trophyCase");trophyCase.style.display="flex",trophyCase.style["flex-wrap"]="wrap",trophyCase.style["align-items"]="center",trophyCase.innerHTML="",trophyCase.appendChild(h3Trophy),trophyCase.appendChild(hrTrophy);for(let e of types){let t=document.createElement("div"),r=document.createElement("img");r.src="https://silph.gg/img/badges/"+e.cupType+".png",t.appendChild(r),t.classList.add("cupBadge"),""!=e.medal&&t.classList.add(e.medal),t.style.margin="1%",trophyCase.appendChild(t)}trophyCase.appendChild(textTrophy);for(var i=0;i<document.styleSheets.length;i++){var cssSheet=document.styleSheets[i];try{if(!cssSheet.rules)continue;let e=cssSheet.rules;for(let t=e.length-1;t>=0;t--)"#trophyCase .cupBadge:nth-child(2n+1)"==e[t].selectorText&&(console.log(t,e[t].selectorText),cssSheet.removeRule(t))}catch(e){if("SecurityError"!==e.name)throw e}}