Greasy Fork is available in English.
Automatically converts time from Eastern Time (ET) to Central European Time (CET) within the header.
当前为
// ==UserScript==
// @name NBA.com Time Zone Converter (CET to ET)
// @namespace http://tampermonkey.net/
// @version 1.0
// @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);
})();