Torn ID in profile title

Shows the player ID next to their name in the profile heading for easy copy/pasting (e.g. turns "Sulsay's profile" into "Sulsay [2173590]").

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Torn ID in profile title
// @namespace    https://github.com/sulsay/torn
// @version      1.0
// @description  Shows the player ID next to their name in the profile heading for easy copy/pasting (e.g. turns "Sulsay's profile" into "Sulsay [2173590]").
// @author       Sulsay [2173590]
// @match        https://www.torn.com/profiles.php*
// ==/UserScript==

(function() {
    let originalHeadingTextContent = '';

    const heading = Array.from(document.querySelectorAll('h4')).find(h4 => {
        originalHeadingTextContent = h4.textContent.trim();
        return originalHeadingTextContent.endsWith(' Profile')
    });
    if (heading === undefined) {
        // Profile heading not found or already altered
        return;
    }

    const playerIdMatches = window.location.search.match(/XID=(\d+)/);
    if (playerIdMatches === null) {
        // Viewing profile without the XID query param
        return;
    }

    const apostrophePosition = originalHeadingTextContent.indexOf("'");
    const playerName = originalHeadingTextContent.substr(0, apostrophePosition);
    const playerId = parseInt(playerIdMatches[1], 10);

    heading.textContent = `${playerName} [${playerId}]`;
})();