Created
June 12, 2024 03:11
-
-
Save cosing/605cf4ed95292fd3a600e8a19a6a67ed to your computer and use it in GitHub Desktop.
use your local datetime in github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GitHub datetime replace | |
// @version 1 | |
// @description Replace relative time with datetime on GitHub. | |
// @author cosing | |
// @match https://github.com/* | |
// @match https://gist.github.com/* | |
// @icon https://github.githubassets.com/pinned-octocat.svg | |
// ==/UserScript== | |
const myobserver = new MutationObserver((mutations) => { | |
// console.log(mutations); | |
if (document.documentElement.lang === "en") { | |
console.log("test") | |
document.documentElement.lang = 'zh'; | |
} | |
}); | |
(function () { | |
document.documentElement.lang = 'zh'; | |
var times = document.getElementsByTagName('relative-time'); | |
console.log("test") | |
for (var i = 0; i < times.length; i++) { | |
times[i].update() | |
console.log(i) | |
} | |
// 观察整个文档的根元素(通常是 <html> 元素) | |
myobserver.observe(document.documentElement, { attributes: true, attributeFilter: ['lang'] }); | |
})(); | |
// function formatTime(timeStr) { | |
// return timeStr.slice(0, 19); | |
// } | |
// function funa(mutations) { | |
// // 更新所有已存在的 <relative-time> 元素 | |
// var times = document.getElementsByTagName('relative-time'); | |
// for (var i = 0; i < times.length; i++) { | |
// // var datetime = times[i].getAttribute('datetime'); | |
// // times[i].setAttribute('title', formatTime(datetime)); | |
// times[i].setAttribute('lang', "zh") | |
// } | |
// }; | |
// (function () { | |
// var observer = new MutationObserver(funa); | |
// // 监听 <body> 元素的变化 | |
// observer.observe(document.body, { | |
// childList: true, | |
// subtree: true | |
// }); | |
// })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment