您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
Override JavaScript's Date object to always use Beijing time (UTC+8)
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/493489/1366339/MT%20Override%20Date%20to%20Beijing%20Time.js
// ==UserScript== // @name MT Override Date to Beijing Time // @namespace http://tampermonkey.net/ // @version 0.1 // @description Override JavaScript's Date object to always use Beijing time (UTC+8) // @author tttsc, GPT4 // @match https://*.m-team.cc/* // @match https://*.m-team.io/* // @match https://test2.m-team.cc/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; const originalDate = Date; // Function to adjust the local time to Beijing time function toBeijingTime(original) { const localTime = new originalDate(original); const localTimeMs = localTime.getTime(); const localOffset = localTime.getTimezoneOffset() * 60000; // Offset in milliseconds const beijingOffset = 8 * 3600 * 1000; // Beijing is UTC+8 return new originalDate(localTimeMs + localOffset + beijingOffset); } // Override the Date object Date = function () { if (arguments.length === 0) { return toBeijingTime(originalDate.now()); } else if (arguments.length === 1) { return new originalDate(arguments[0]); } else { return new originalDate(...arguments); } }; Date.prototype = originalDate.prototype; Date.now = function() { return toBeijingTime(originalDate.now()).getTime(); }; Date.parse = originalDate.parse; Date.UTC = originalDate.UTC; Object.defineProperty(Date, 'prototype', { writable: false }); })();