您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
convert mentions of dates/times in tweet to local
当前为
// ==UserScript== // @name twitter localize dates // @namespace http://tampermonkey.net/ // @version 2024-04-04-2 // @description convert mentions of dates/times in tweet to local // @author You // @match https://twitter.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com // @grant none // @license MIT // ==/UserScript== // https://www.ge.com/digital/documentation/workflow/r_wf_time_zone_abbreviations_for_date_and_time_functions.html const timeZoneMap = { ET: "EST", PT: "PST" } /** * @param {string} str */ function parseTime(str) { const timeStrMatch = str.match(/(?<time>[0-9][0-9]?(:[0-9][0-9])?)(?<offset>(a|p|A|P)(m|M))? +(?<timezone>[a-zA-Z]*)/) let timeStr = timeStrMatch?.groups?.time let timeZone = timeStrMatch?.groups?.timezone if(timeStr && timeZone) { const today = new Date().toISOString().split("T")[0] if(!timeStr.includes(":")) { timeStr += ":00" } timeZone = timeZoneMap[timeZone.toUpperCase()] ?? timeZone return new Date(`${today} ${timeStr} ${timeStrMatch?.groups.offset ?? ''} ${timeZone}`) } return null } window.addEventListener("mousemove", e => { if(e.target instanceof HTMLElement) { const tweet = e.target.closest('[data-testid="cellInnerDiv"]') if(tweet && tweet instanceof HTMLElement) { const text = tweet.querySelector('[data-testid="tweetText"]')?.textContent.trim(); if(text) { const parseddate = parseTime(text) if(parseddate && !isNaN(+parseddate)) { tweet.title = parseddate.toLocaleTimeString() } } } } })