Show profile details

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

当前为 2023-01-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         Show profile details
// @version      0.4.0
// @description  Display the country code and account creation date under the name in profile pages
// @author       victheturtle#5159
// @license      MIT
// @match        https://www.geoguessr.com/*
// @icon         https://www.svgrepo.com/show/256769/pl.svg
// @grant        none
// @namespace    https://greasyfork.org/users/967692-victheturtle
// ==/UserScript==

function checkURL() {
    if (location.pathname.startsWith("/user") || location.pathname.startsWith("/me/profile")) return 1;
    return 0;
}

function insertAfter(newNode, existingNode) {
    existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}

async function checkUser(profileLink) {
    return fetch(profileLink)
    .then(out => out.text())
    .then(str => {
        console.log("Checking: "+profileLink);
        let parser = new DOMParser();
        let html = parser.parseFromString(str, "text/html");
        let dataHTML = html.getElementById("__NEXT_DATA__");
        let dataJson = JSON.parse(dataHTML.innerHTML);
        if (profileLink.includes("/user/")) return dataJson.props.pageProps.user;
        else return dataJson.props.middlewareResults[1].account.user;
    }).catch(err => {console.log(err); return null;});
}

let observer = new MutationObserver((mutations) => {
    if (checkURL() == 1) {
        if (document.getElementById("countryCode") == null) {
            let proDiv = document.querySelector("[class*='profile-header_proBadgeWrapper__']")
            let baseDiv = (proDiv) ? proDiv.firstChild : document.querySelector("[data-qa='user-card-title']");
            let countryCodeDiv = document.createElement("div");
            countryCodeDiv.className = 'rating_divisionName__mgZFv';
            countryCodeDiv.innerHTML = `<div id="countryCode"></div>`;
            if (proDiv) {
                baseDiv.style = "display: inline-block; margin-right: 10px"
                countryCodeDiv.style.display = "inline-block"
            }
            insertAfter(countryCodeDiv, baseDiv)
            checkUser(location.href).then(user => { document.getElementById("countryCode").innerText =
                `[${user.countryCode}] [${user.created.slice(0, 16).replace("T"," ")}]`;
            });
        }
    }
})

observer.observe(document.body, {
  characterDataOldValue: false,
  subtree: true,
  childList: true,
  characterData: false
});