NBA.com Time Zone Converter (ET to CET)

Automatically converts time from Eastern Time (ET) to Central European Time (CET) within the header.

当前为 2024-05-04 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NBA.com Time Zone Converter (ET to CET)
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Automatically converts time from Eastern Time (ET) to Central European Time (CET) within the header.
// @author       Beurreboule
// @match        https://www.nba.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function convertETtoUTCPlus1(timeString) {
        const isDaylightSaving = () => {
            const today = new Date();
            const jan = new Date(today.getFullYear(), 0, 1).getTimezoneOffset();
            const jul = new Date(today.getFullYear(), 6, 1).getTimezoneOffset();
            return Math.max(jan, jul) != today.getTimezoneOffset();
        };

        const offset = isDaylightSaving() ? 5 : 6;
        const match = timeString.match(/(\d{1,2}):(\d{2})\s*([AP]M)\s*ET/i);
        if (!match) return timeString;

        let [_, hours, minutes, meridiem] = match;
        hours = parseInt(hours);
        minutes = parseInt(minutes);

        if (meridiem.toLowerCase() === "pm" && hours < 12) hours += 12;
        if (meridiem.toLowerCase() === "am" && hours === 12) hours = 0;

        hours += offset;
        if (hours >= 24) hours -= 24;

        return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')} (CET)`;
    }

    function getTimeElements() {
        return document.querySelectorAll(".ScoreStripGame_gameInfoText__tlx_V, .ScheduleStatusText_base__Jgvjb, .GameCardMatchupStatusText_gcsText__PcQUX");
    }

    function getBroadcasterElements() {
        return document.querySelectorAll(".ScoreStripGame_broadcasters__NU0f2");
    }

    function applyNewInfo() {
        let elementsTime = getTimeElements();
        elementsTime.forEach(element => {
            const originalTime = element.textContent;
            const newTime = convertETtoUTCPlus1(originalTime);
            element.textContent = newTime;
        });

        let elementsBroadcaster = getBroadcasterElements();
        elementsBroadcaster.forEach(element => {
            element.style.display = 'none';
        });
    }

    window.addEventListener("load", applyNewInfo);
})();