您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
显示推特中的日期时间为 yy-mm-dd hh:ii:ss 格式。
// ==UserScript== // @name 推特|Twitter|X日期时间格式化 // @namespace https://greasyfork.org/ // @author usdf0380808 // @version 1.0 // @license MIT // @description 显示推特中的日期时间为 yy-mm-dd hh:ii:ss 格式。 // @match https://twitter.com/* // @match https://mobile.twitter.com/* // @match https://x.com/* // @match https://mobile.x.com/* // @grant none // @run-at document-body // ==/UserScript== (function () { 'use strict'; // 格式化日期和时间为 YY-MM-DD HH:II:SS function fmtDate(date) { const pad = (num) => String(num).padStart(2, '0'); const year = date.getFullYear().toString().slice(-2); const month = pad(date.getMonth() + 1); const day = pad(date.getDate()); const hours = pad(date.getHours()); const minutes = pad(date.getMinutes()); const seconds = pad(date.getSeconds()); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } // 替换推文中的日期时间 function replaceDatetime() { document.querySelectorAll('time[datetime]').forEach(function (timeElement) { const datetime = timeElement.getAttribute('datetime'); const formatted = fmtDate(new Date(datetime)); if (!timeElement.dataset.formatted) { timeElement.textContent = formatted; timeElement.dataset.formatted = true; // 防止重复格式化 } }); } // 观察 DOM 变化 const observer = new MutationObserver(replaceDatetime); observer.observe(document.body, { childList: true, subtree: true }); // 初始替换 replaceDatetime(); })();