|
| 1 | +// ==UserScript== |
| 2 | +// @name [PS] Add Rating |
| 3 | +// @namespace https://github.com/ikelax/userscripts |
| 4 | +// @match https://play.pokemonshowdown.com/* |
| 5 | +// @grant none |
| 6 | +// @version 0.1.0 |
| 7 | +// @author Alexander Ikonomou |
| 8 | +// @description Adds in battles, the rating of the player below its sprite. |
| 9 | +// @license MIT |
| 10 | +// @supportURL https://github.com/ikelax/userscripts/issues |
| 11 | +// @updateURL https://raw.githubusercontent.com/ikelax/userscripts/refs/heads/master/userscripts/ps-add-rating.user.js |
| 12 | +// @downloadURL https://raw.githubusercontent.com/ikelax/userscripts/refs/heads/master/userscripts/ps-add-rating.user.js |
| 13 | +// @copyright 2025, Alexander Ikonomou (https://github.com/ikelax) |
| 14 | +// @homepageURL https://github.com/ikelax/userscripts |
| 15 | +// @homepage https://github.com/ikelax/userscripts |
| 16 | +// @contributionURL https://github.com/ikelax/userscripts |
| 17 | +// @collaborator ikelax |
| 18 | +// @icon https://www.google.com/s2/favicons?sz=64&domain=pokemonshowdown.com |
| 19 | +// ==/UserScript== |
| 20 | + |
| 21 | +(function () { |
| 22 | + "use strict"; |
| 23 | + |
| 24 | + function addRating(trainer) { |
| 25 | + let trainersprite = trainer.querySelector(`div.trainersprite`); |
| 26 | + let rating = document.createElement("strong"); |
| 27 | + rating.innerText = trainersprite.title || "Rating: None"; |
| 28 | + rating.id = "rating"; |
| 29 | + trainersprite.parentNode.insertBefore(rating, trainersprite.nextSibling); |
| 30 | + } |
| 31 | + |
| 32 | + function watchForElement(selector, onAppear) { |
| 33 | + const observer = new MutationObserver(() => { |
| 34 | + const element = document.querySelector(selector); |
| 35 | + |
| 36 | + if (!document.querySelector(`${selector} > strong#rating`)) { |
| 37 | + onAppear(element); |
| 38 | + } |
| 39 | + }); |
| 40 | + |
| 41 | + observer.observe(document.body, { |
| 42 | + childList: true, |
| 43 | + subtree: true, |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + watchForElement("div.trainer-far", (trainer) => addRating(trainer)); |
| 48 | + |
| 49 | + watchForElement("div.trainer-near", (trainer) => addRating(trainer)); |
| 50 | +})(); |
0 commit comments