Show Torn Bazaar in Title

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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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;
                }
            }
        }
    }
})();