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]").

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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}]`;
})();