Skip to content

Commit b72d7df

Browse files
authored
[PS] Add Rating (#67)
See pull request: #67
1 parent 053cee1 commit b72d7df

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ them add functionality to pages of the Saarland University.
3232
| [CMS Navbar Materials][cnm-docs] | [install][cnm-raw] | [GF][cnm-gf] [OU][cnm-ou] |
3333
| [YouTube Five Videos in Row][yt-docs] | [install][yt-raw] | [GF][yt-gf] [OU][yt-ou] |
3434
| [GitHub Link Dashboard Avatar][glda-docs] | [install][glda-raw] | [GF][glda-gf] [OU][glda-ou] |
35+
| [\[PS\] Add Rating][psr-docs] | [install][psr-raw] | [GF][psr-gf] [OU][psr-ou] |
3536

3637
[mnc-docs]: docs/Mensaar_Navbar_Canteens.md
3738
[msnd-docs]: docs/Mensaar_Show_Next_Day.md
3839
[cnm-docs]: docs/CMS_Navbar_Materials.md
3940
[yt-docs]: docs/YouTube_Five_Videos_in_Row.md
4041
[glda-docs]: docs/GitHub_Link_Dashboard_Avatar.md
42+
[psr-docs]: docs/PS_Add_Rating.md
4143
[mnc-raw]: https://github.com/ikelax/userscripts/raw/refs/heads/master/userscripts/mensaar-add-uds-htw.user.js
4244
[msnd-raw]: https://github.com/ikelax/userscripts/raw/refs/heads/master/userscripts/mensaar-show-next-day-when-closed.user.js
4345
[cnm-raw]: https://github.com/ikelax/userscripts/raw/refs/heads/master/userscripts/uds-cms-add-materials.user.js
4446
[yt-raw]: https://github.com/ikelax/userscripts/raw/refs/heads/master/userscripts/youtube-five-videos-in-row.user.js
4547
[glda-raw]: https://github.com/ikelax/userscripts/raw/refs/heads/master/userscripts/github-link-dashboard-avatar.user.js
48+
[psr-raw]: https://github.com/ikelax/userscripts/raw/refs/heads/master/userscripts/ps-add-rating.user.js
4649
[mnc-gf]: https://greasyfork.org/en/scripts/533937-mensaar-navbar-uds-htw
4750
[msnd-gf]: https://greasyfork.org/en/scripts/533989-mensaar-show-next-day
4851
[cnm-gf]: https://greasyfork.org/en/scripts/533938-cms-navbar-materials

docs/PS_Add_Rating.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# [PS] Add Rating
2+
3+
This is a userscript for [Pokémon Showdown][ps]. It adds in
4+
battles, the rating of the player below its sprite.
5+
6+
## Screenshot
7+
8+
![Trainer with sprite and rating](../images/psr.png)
9+
10+
[ps]: https://play.pokemonshowdown.com/

images/psr.png

40.9 KB
Loading

userscripts/ps-add-rating.user.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)