Twitch Add Timer

Adds a watch timer next to the follow icon so you can see how long you are watching the stream. Resets automatically on page changes.

スクリプトをインストールするには、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         Twitch Add Timer
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Adds a watch timer next to the follow icon so you can see how long you are watching the stream. Resets automatically on page changes.
// @author       RichardG
// @match        https://www.twitch.tv/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=twitch.tv
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const timerElement = document.createElement("div");
    timerElement.style.cssText = "position:absolute; bottom: 5px; left: -20px";
    timerElement.innerHTML = "<p>00:00:00</p>";

    let seconds = 0;
    let minutes = 0;
    let hours = 0;
    let lastHref = window.location.href;

    function updateTimer() {
        if(lastHref != window.location.href) {
            seconds = 0;
            minutes = 0;
            hours = 0;
            lastHref = window.location.href;
        }
        seconds++;
        if (seconds === 60) {
            seconds = 0;
            minutes++;
            if (minutes === 60) {
                minutes = 0;
                hours++;
            }
        }

        // Format the time to always show two digits
        const formattedTime =
              String(hours).padStart(2, '0') + ':' +
              String(minutes).padStart(2, '0') + ':' +
              String(seconds).padStart(2, '0');

        timerElement.textContent = formattedTime;
    }

    setInterval(() => {
        try {
            document.querySelector('[data-target="channel-header-right"]').childNodes[0].appendChild(timerElement);
        }
        catch(e) {
        }
    }, 3000);

    // Update the timer every 1000 milliseconds (1 second)
    setInterval(updateTimer, 1000);

})();