// ==UserScript== // @name Kemono 更新標示 (動態天數彩色版-原尺寸) // @name:zh-TW Kemono 更新標示 (動態天數彩色版-原尺寸) // @name:zh-CN Kemono 更新标记 (动态天数彩色版-原尺寸) // @namespace https://greasyfork.org/users/1051751-mark-levi // @version 2.2.1 // @description Highlights recent posts on Kemono with different colors based on days. Original recommended size. // @description:zh-TW 根據天數為更新附加不同顏色標示,保持原推薦尺寸。 // @description:zh-CN 根据天数为更新附加不同颜色标记,保持原推荐尺寸。 // @author Mark // @match https://kemono.cr/account/favorites/artists // @grant none // @run-at document-idle // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; const prefix = '[KemonoCR]'; const log = (...args) => console.log(prefix, ...args); // --- 日期處理函式 --- const toYMD = (date) => { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, '0'); const d = String(date.getDate()).padStart(2, '0'); return `${y}-${m}-${d}`; }; const today = new Date(); const todayStr = toYMD(today); // 計算天數差的函式 function getDayDiff(dateStr) { const postDate = new Date(dateStr); // 清除時間部分,只比較日期 const todayNoTime = new Date(todayStr); const postDateNoTime = new Date(dateStr); const diffTime = todayNoTime - postDateNoTime; const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); return diffDays; } log('Dynamic day calculator with color coding initialized'); /** * 添加標記到元素(根據天數顯示不同顏色,原推薦尺寸) * @param {HTMLElement} el - time元素 * @param {string} text - 要顯示的文字 * @param {number} dayDiff - 天數差 */ function appendLabel(el, text, dayDiff) { const labelSpan = document.createElement('span'); labelSpan.textContent = text; labelSpan.style.fontWeight = 'bold'; labelSpan.style.marginLeft = '5px'; // 恢復原推薦尺寸 // 根據天數設定不同顏色 if (dayDiff === 0) { labelSpan.style.color = 'red'; // 今日:紅色 } else if (dayDiff === 1) { labelSpan.style.color = 'orange'; // 1天前:橙色 } else if (dayDiff === 2) { labelSpan.style.color = 'gold'; // 2天前:金色 } else if (dayDiff === 3) { labelSpan.style.color = 'green'; // 3天前:綠色 } else if (dayDiff === 4) { labelSpan.style.color = 'blue'; // 4天前:藍色 } else if (dayDiff === 5) { labelSpan.style.color = 'purple'; // 5天前:紫色 } else { labelSpan.style.color = '#666666'; // 6天以上:深灰色 } el.appendChild(labelSpan); } /** * 處理單一