Greasy Fork

Greasy Fork is available in English.

洛谷讨论区显示时间改成具体时间

将原本的“……前”改为具体的时间

当前为 2023-09-14 提交的版本,查看 最新版本

// ==UserScript==
// @name          洛谷讨论区显示时间改成具体时间
// @namespace     https://www.luogu.com.cn/user/542457
// @description   将原本的“……前”改为具体的时间
// @author        cff_0102
// @run-at        document-end
// @version       1.0.3
// @license       MIT
// @match         https://www.luogu.com.cn/*
// @icon          https://cdn.luogu.com.cn/upload/usericon/542457.png
// ==/UserScript==
 
(function() {
    'use strict';
 
    function formatTime(isoDatetime) {
        const date = new Date(isoDatetime);
        const year = date.getFullYear();
        const month = (date.getMonth() + 1).toString().padStart(2, '0'); 
        const day = date.getDate().toString().padStart(2, '0');
        const hours = date.getHours().toString().padStart(2, '0');
        const minutes = date.getMinutes().toString().padStart(2, '0');
        const seconds = date.getSeconds().toString().padStart(2, '0');
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    }
 
 
    // 更改时间显示
    function changeTimeText() {
        const timeElements = document.querySelectorAll('time[data-v-2701c2d5][data-v-f9624136][datetime]');
        timeElements.forEach((timeElement) => {
            const datetime = timeElement.getAttribute('datetime');
            const formattedTime = formatTime(datetime);
            timeElement.textContent = formattedTime;
        });
    }
 
    setInterval(changeTimeText, 500);
 
    function extractTimeText(element) {
        const timeElement = element.querySelector('.time');
        return timeElement ? timeElement.getAttribute('title') : null;
    }
 
    // 更新时间文本
    function updateLastReplyText() {
        const elements = document.querySelectorAll('div[data-v-b0d342de][data-v-f9624136].row.row-space-between.bottom');
        elements.forEach((element) => {
            const linkElement = element.querySelector('a.row.content-left.title.link.color-default');
            const linkElement1 = linkElement.querySelector('div.time');
            const timeText = linkElement1.title;
            if (timeText) {
                const titleText = `最后回复于 ${timeText}`;
                if (linkElement1) {
                    linkElement1.textContent = titleText;
                }
            }
        });
        elements.forEach((element) => {
            const linkElement = element.querySelector('div.row.content-left');
            const linkElement1 = linkElement.querySelector('div.time');
            const timeText = linkElement1.title;
            if (timeText) {
                const titleText = `发表于 ${timeText}`;
                if (linkElement1) {
                    linkElement1.textContent = titleText;
                }
            }
        });
    }
 
    setInterval(updateLastReplyText, 500);
})();