KAT: smart full date/time

Today: "1 hour ago", yesterday: "yesterday, 11:44", earlier: "12 days ago, 01 Oct 2015, 10:45"

目前為 2015-10-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name         KAT: smart full date/time
// @description  Today: "1 hour ago", yesterday: "yesterday, 11:44", earlier: "12 days ago, 01 Oct 2015, 10:45"
// @include      https://kat.cr/*
// @version      1.0.1
// @author       wOxxOm
// @namespace    https://gf.qytechs.cn/en/users/2159-woxxom
// @license      MIT License
// @run-at       document-start
// @grant        GM_addStyle
// @require      https://gf.qytechs.cn/scripts/12228/code/setMutationHandler.js
// ==/UserScript==

GM_addStyle('.wOxxOmified {opacity:0.7}');

var today = new Date();
today.setHours(0, 0, 0, 0);

var yesterday = new Date();
yesterday.setDate(today.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);

var year = new Date();
year.setMonth(0, 1);
year.setHours(0, 0, 0, 0);

setMutationHandler(document, 'time', datify, 
				   {characterData: true, attributes: true, attributeFilter: ['title'], subtree: true});
function datify(nodes) {
	nodes.forEach(function(n) {
		var d = new Date(n.getAttribute('datetime') || n.title);
		if (d >= today) {
			// no change
		} else if (d >= yesterday) {
			setContent(n, 'yesterday, ', d, {hour:'2-digit', minute:'2-digit'});
		} else if (d >= year) {
			setContent(n, '', d, {day:'numeric', month:'short', hour:'2-digit', minute:'2-digit'});
		} else {
			setContent(n, '', d, {day:'numeric', month:'short', year:'2-digit', hour:'2-digit', minute:'2-digit'});
		}
	});
	return true;
}
function setContent(n, prefix, d, options) {
	var time = d.toLocaleTimeString(navigator.language, options);
	var text = prefix ? prefix + time : time + ', <span class="wOxxOmified">' + n.innerHTML + '</span>';
	if (n.innerHTML != text)
		n.innerHTML = text;
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址