// ==UserScript== // @name 洛谷讨论区显示时间改成具体时间 // @namespace https://www.luogu.com.cn/user/542457 // @description 将原本的“……前”改为具体的时间 // @author cff_0102 // @run-at document-end // @version 1.0.5 // @license MIT // @match https://www.luogu.com.cn/* // @icon https://www.luogu.com.cn/favicon.ico // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 下面这个函数可以关闭广告。不想关的话注释掉就行了。 function closeDivsWithAttributes() { let attributeValue = ''; var divElements = document.getElementsByTagName('div'); for (var i = 0; i < divElements.length; i++) { var div = divElements[i]; if (div.getAttribute('data-v-0a593618') === attributeValue && div.getAttribute('data-v-602e5c62') === attributeValue) { div.remove(); } } } setInterval(closeDivsWithAttributes, 250); 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() { let 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; }); timeElements = document.querySelectorAll('time[data-v-f3aa455a][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); })();