Display Faction ID

Display faction ID in faction page title

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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();
    }
})();