Telegram Web K(A) Full Date Enabler

Replaces time in all posts with full lowercase date and optionally hides floating "Today"/"Yesterday" date bubble

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Telegram Web K(A) Full Date Enabler
// @namespace    https://violentmonkey.github.io/
// @version      1.1
// @description  Replaces time in all posts with full lowercase date and optionally hides floating "Today"/"Yesterday" date bubble
// @author       Streampunk
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAGI0lEQVR4nO1bW2xURRg+8q6A92eC9MwWKGJE4hW5vHhJeJBEJaSJiQnBFxPffKkS0whRLiaiJOKLIEHFIu7MbukFLakFuZZSWrrdtmzphZbednfmnO1efvOfugvt3s5t97TJfsmfNHtm5+z3zT//zPzzV5JKKKGEEkooPFb+EXqKMGWTzPgumfE9hIrDhPFjmlFxGD/DZ9gG20oLHlWwSKbKFpmKQ4TyDsIEGDGZ8ZuEim9REOxLWihYzoJPEMZ3y1T0GyWdVQzKA4Tyz1ecDj4uzVesck8uJVTskykP20U8gxBhwvhXFTUTS6R5A4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442vgvXBlK3+Pnw+kBawHQ8GEIMVOcYP6lqz0cmtvvT4Mfz7XDqcZm+KXxPHh9o4YE2NNhLQDKVByUjIJYOBAlbf/FwZQAx/++rAmAVtPYDEdah3ULUHneWgCUmXjNkZTYtrMTGvmWDr9GOinAwfpr8CwLwSdXI3nTYLhYYvbIPHmTKTEElqVYEQBPiQ03euF0a2+K/IH6a7DGE0q1efcfFUbV7HuCvrC1ACgzUSU5mRavvjAExy7NCHCgoXUW+aRtaFS0s34msEHzAdByWhyBNTlWBNhYF4QfznfD/vpWqGDp5JO2tlbAmeH0+YDH7aLs/nKVwRAqBq2I8EbtGKz2hPO2czEB3/mi2rxPYrvJHaDMxJBtt8TELXZYEcCo7boUgd/6Y9YSIB7xni3kkyCU/1xMEawYFm5JdmNZ3fhiLEhaAOS7cNpKhQD5U31mvlyVZ7HRFV5VlgoJmfH1hawGNT3yuFy7+QtSMVDO+POEipH5Q16MYfVaUcgngcWJWJDkOHnGu8o8apnkBMpOwcOE8uOOCUDF7/OicNrFxHbceBSR+KDt67wdyyQmUwtbUsODuL0t2DJnB/AAhWUpeAy1cZ7fxlOdyzv5qLRgUAWL8EYWixNkKm4Yc3GewO9gJkdLZiykf5nJBkxKuqiyEdPThPFqvHzBG6gZw4sYXo3PUDTDCcwSSiihhBIkU/gPl+NAtPTy4YcAAAAASUVORK5CYII=
// @match        https://web.telegram.org/k/*
// @match        https://web.telegram.org/a/*
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // ========================= CONFIGURATION =========================
    const HIDE_FLOATING_DATE_BUBBLE = true;     // false = show floating date
    const ENABLE_FULL_DATE_REPLACEMENT = true;  // false = disable full date
    // =================================================================

    // 1. Hide floating date bubble (Today/Yesterday while scrolling)
    if (HIDE_FLOATING_DATE_BUBBLE) {
        const hideCss = `
            .bubble.service.is-date,
            .bubble.service.is-date.is-fake,
            .bubble.service[class*="is-date"] {
                display: none !important;
            }
        `;
        const style = document.createElement('style');
        style.textContent = hideCss;
        document.head.appendChild(style);
    }

    if (!ENABLE_FULL_DATE_REPLACEMENT) {
        console.log('Full-date replacement is disabled');
        return;
    }

    // Lowercase first letter of month (e.g. "November" → "november")
    function lowercaseMonth(str) {
        return str.replace(/^(\d{1,2}\s+)([A-Za-zÀ-ÖØ-öø-ÿ]+)/g, 
            (m, day, month) => day + month[0].toLowerCase() + month.slice(1));
    }

    // Remove seconds from "HH:MM:SS" → "HH:MM"
    function removeSeconds(timeStr) {
        return timeStr.replace(/:\d{2}$/, ''); // removes last ":SS"
    }

    function processTimeElements() {
        document.querySelectorAll('.time-inner[title]:not([data-full-date])').forEach(el => {
            let title = el.getAttribute('title') || '';
            if (!title) return;

            // Split title into lines: current time and possibly "Original: ..."
            const lines = title.trim().split('\n').map(l => l.trim());

            // Process each line (current + original if edited)
            const processedLines = lines.map(line => {
                if (line.includes('Original:')) {
                    // Keep "Original: " prefix, then format the date
                    const datePart = line.replace('Original: ', '');
                    return 'Original: ' + lowercaseMonth(removeSeconds(datePart));
                } else {
                    // Regular current time
                    return lowercaseMonth(removeSeconds(line));
                }
            });

            // Update title attribute (optional, for hover)
            el.setAttribute('title', processedLines.join('\n'));

            // Update visible text
            const visibleSpan = el.querySelector('.i18n[dir="auto"]');
            if (visibleSpan) {
                // Format visible text exactly like title but joined with newline
                visibleSpan.textContent = processedLines.join('\n');
            }

            // Mark as processed to avoid re-running
            el.dataset.fullDate = '1';
        });
    }

    // Observer for new messages, edits, replies, scrolling
    const observer = new MutationObserver(processTimeElements);
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial run + safety
    processTimeElements();
    const safety = setInterval(processTimeElements, 1000);
    setTimeout(() => clearInterval(safety), 12000);

    // Re-process on scroll (old messages load)
    window.addEventListener('scroll', () => setTimeout(processTimeElements, 200), { passive: true });

    // console.log('Telegram Web full date and floating date hider enabled');
})();