-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-absolute-time.user.js
More file actions
49 lines (41 loc) · 1.45 KB
/
github-absolute-time.user.js
File metadata and controls
49 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// ==UserScript==
// @name GitHub Absolute Time
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 在 GitHub 上显示绝对时间格式的时间戳
// @author eWloYW8
// @match *://github.com/*
// @run-at document-idle
// @license MIT
// @grant none
// ==/UserScript==
(function() {
'use strict';
function pad2(n) {
return n.toString().padStart(2, '0');
}
function formatDateString(titleText) {
const date = new Date(titleText);
if (isNaN(date)) return titleText;
const year = pad2(date.getFullYear() % 100);
const month = pad2(date.getMonth() + 1);
const day = pad2(date.getDate());
const hours = pad2(date.getHours());
const minutes = pad2(date.getMinutes());
return `${year}/${month}/${day} ${hours}:${minutes}`;
}
function replaceRelativeTimeElements() {
const elements = document.querySelectorAll('relative-time[title]');
elements.forEach(el => {
const titleText = el.getAttribute('title');
const formatted = formatDateString(titleText);
const textNode = document.createTextNode(formatted);
el.replaceWith(textNode);
});
}
replaceRelativeTimeElements();
const observer = new MutationObserver(() => {
replaceRelativeTimeElements();
});
observer.observe(document.body, { childList: true, subtree: true });
})();