Display Faction ID

Display faction ID in faction page title

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Display Faction ID
// @namespace    heartflower.torn
// @version      1.1.1
// @description  Display faction ID in faction page title
// @author       Heartflower [2626587]
// @match        https://www.torn.com/factions.php?*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function findYourFactionId() {
        let forumThread = document.body.querySelector('.forum-thread');
        if (!forumThread) {
            setTimeout(findYourFactionId, 100);
            return;
        }

        let href = forumThread.getAttribute('href');
        let factionId = href.replace('/forums.php#!p=forums&f=999&b=1&a=','');

        displayFactionId(factionId);
    }

    function findOtherFactionId() {
        let factionId;

        if (window.location.href.includes('profile&ID=')) {
            factionId = window.location.href.replace('https://www.torn.com/factions.php?step=profile&ID=', '');
            factionId = factionId.split('&')[0];
        } else {
            let viewWars = document.body.querySelector('.view-wars');
            if (!viewWars) {
                setTimeout(findOtherFactionId, 100);
                return;
            }

            let href = viewWars.getAttribute('href');
            factionId = href.replace('/page.php?sid=factionWarfare#/ranked/','');
        }

        displayFactionId(factionId);
    }

    function displayFactionId(factionId) {
        let title = document.getElementById('skip-to-content');
        if (!title) {
            setTimeout(() => displayFactionId(factionId), 100);
            return;
        }

        let currentText = title.textContent;
        title.textContent = currentText += ` [${factionId.trim()}]`;
    }

    if (window.location.href.includes('your')) {
        findYourFactionId();
    } else {
        findOtherFactionId();
    }
})();