GeoGuessr is User Banned

Show whether a player is banned or not on their profile page

  1. // ==UserScript==
  2. // @name GeoGuessr is User Banned
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.2
  5. // @description Show whether a player is banned or not on their profile page
  6. // @author sp4ghet
  7. // @match https://www.geoguessr.com/user/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
  9. // @grant none
  10. // @license MIT
  11. // @namespace https://greasyfork.org/en/users/1273557-sp4ghet
  12. // ==/UserScript==
  13.  
  14. function checkURL() {
  15. if (location.pathname.includes("/user") || location.pathname.includes("/me/profile")) return 1;
  16. return 0;
  17. }
  18.  
  19. function insertAfter(newNode, existingNode) {
  20. existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
  21. }
  22.  
  23. async function checkUser(profileId) {
  24. return fetch(location.origin + "/api/v3/users/" + profileId)
  25. .then(out => out.json())
  26. .catch(err => { console.log(err); return null; });
  27. }
  28.  
  29. let observer = new MutationObserver((mutations) => {
  30. if (checkURL() == 1) {
  31. const profileLink = (location.pathname.includes("/me/profile")) ? document.querySelector('[name="copy-link"]').value : location.href;
  32. const profileId = profileLink.substr(profileLink.lastIndexOf("/") + 1);
  33. checkUser(profileId).then(user => {
  34. if (user.isBanned === false && user.suspendedUntil === null) {
  35. return;
  36. }
  37. if (document.getElementById("isBanned") == null) {
  38. let proDiv = document.querySelector("[class*='profile-header_proBadgeWrapper__']");
  39. let baseDiv = (proDiv) ? proDiv.firstChild : document.querySelector("[data-qa='user-card-title']");
  40. let bannedDiv = document.createElement("div");
  41. bannedDiv.innerHTML = `<div id="isBanned"></div>`;
  42. if (proDiv) {
  43. baseDiv.style = "display: inline-block; margin-right: 10px";
  44. bannedDiv.style.display = "inline-block";
  45. }
  46. insertAfter(bannedDiv, baseDiv);
  47. let banText = user.isBanned ? `User is banned.` : "";
  48. let suspensionText = "";
  49. if (user.suspendedUntil !== null) {
  50. let suspensionDate = new Date(user.suspendedUntil);
  51. suspensionText = "User " +
  52. (Date.now() < suspensionDate ? "is" : "was last") +
  53. " suspended until " + suspensionDate.toLocaleString() + ".";
  54. }
  55. document.getElementById("isBanned").innerText = banText + (banText && suspensionText ? " " : "") + suspensionText;
  56. }
  57. });
  58. }
  59. })
  60.  
  61. observer.observe(document.body, { subtree: true, childList: true });