Show profile details

Display the country code and account creation date under the name in profile pages

  1. // ==UserScript==
  2. // @name Show profile details
  3. // @version 0.4.2
  4. // @description Display the country code and account creation date under the name in profile pages
  5. // @author victheturtle#5159
  6. // @license MIT
  7. // @match https://www.geoguessr.com/*
  8. // @icon https://www.svgrepo.com/show/256769/pl.svg
  9. // @grant none
  10. // @namespace https://greasyfork.org/users/967692-victheturtle
  11. // ==/UserScript==
  12.  
  13. function checkURL() {
  14. if (location.pathname.includes("/user") || location.pathname.includes("/me/profile")) return 1;
  15. return 0;
  16. }
  17.  
  18. function insertAfter(newNode, existingNode) {
  19. existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
  20. }
  21.  
  22. async function checkUser(profileId) {
  23. return fetch(location.origin + "/api/v3/users/" + profileId)
  24. .then(out => out.json())
  25. .catch(err => {console.log(err); return null;});
  26. }
  27.  
  28. let observer = new MutationObserver((mutations) => {
  29. if (checkURL() == 1) {
  30. if (document.getElementById("countryCode") == null) {
  31. let proDiv = document.querySelector("[class*='profile-header_proBadgeWrapper__']");
  32. let baseDiv = (proDiv) ? proDiv.firstChild : document.querySelector("[data-qa='user-card-title']");
  33. let countryCodeDiv = document.createElement("div");
  34. countryCodeDiv.innerHTML = `<div id="countryCode"></div>`;
  35. if (proDiv) {
  36. baseDiv.style = "display: inline-block; margin-right: 10px";
  37. countryCodeDiv.style.display = "inline-block";
  38. }
  39. insertAfter(countryCodeDiv, baseDiv);
  40. const profileLink = (location.pathname.includes("/me/profile")) ? document.querySelector('[name="copy-link"]').value : location.href;
  41. const profileId = profileLink.substr(profileLink.lastIndexOf("/")+1);
  42. checkUser(profileId).then(user => { document.getElementById("countryCode").innerText =
  43. `[${user.countryCode.toUpperCase()}] [${user.created.slice(0, 16).replace("T"," ")}]`;
  44. });
  45. }
  46. }
  47. })
  48.  
  49. observer.observe(document.body, {subtree: true, childList: true});