Show Torn Bazaar in Title

Updates the browser tab title from "Bazaar | TORN" to the name of the bazaar owner.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Show Torn Bazaar in Title
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Updates the browser tab title from "Bazaar | TORN" to the name of the bazaar owner.
// @author       Deviyl[3722358]
// @match        https://www.torn.com/bazaar.php*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @run-at       document-idle
// @grant        none
// @license      MIT
// ==/UserScript==


(function() {
    'use strict';
    // check every 500ms on page load until bazaar name found
    const checkInterval = setInterval(updateTitle, 500);

    function updateTitle() {
        // grab all links
        const links = document.getElementsByTagName('a');

        for (let a of links) {
            // look through links until one is a profile link
            // and also has text ends in apostrophe s
            if (a.href.includes('profiles.php?XID=')) {
                const text = a.textContent.trim();
                if (text.endsWith("'s")) {
                    document.title = `${text} Bazaar`; //change page title
                    // stop timer once found and set
                    clearInterval(checkInterval);
                    return;
                }
            }
        }
    }
})();