CircleFTP PC Games File Date Display

Add File Upload Date For Pc Games

// ==UserScript==
// @name         CircleFTP PC Games File Date Display
// @namespace    http://tampermonkey.net/
// @match        *://*.circleftp.net/*
// @version      1.1
// @description  Add File Upload Date For Pc Games
// @author       BlazeFTL
// @license MIT
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function () {
    'use strict';

    // Helper to show the date beside link
    function showDate(link, text) {
        const span = document.createElement('span');
        span.textContent = ` 📅 ${text}`;
        span.style.fontSize = "0.9em";
        span.style.color = "#4caf50";
        span.style.marginLeft = "8px";
        link.insertAdjacentElement('afterend', span);
    }

    // Format date as "9 October, 2025"
    function formatDate(dateObj) {
        const day = dateObj.getDate();
        const year = dateObj.getFullYear();
        const months = [
            "January", "February", "March", "April", "May", "June",
            "July", "August", "September", "October", "November", "December"
        ];
        const monthName = months[dateObj.getMonth()];
        return `${day} ${monthName}, ${year}`;
    }

    // Function to check links (can be re-run later)
    function processLinks() {
        document.querySelectorAll('a[href*=".circleftp.net/"][href$=".rar"]:not([data-date-shown])').forEach(link => {
            link.dataset.dateShown = "true"; // mark processed
            const fileUrl = link.href;

            GM_xmlhttpRequest({
                method: "HEAD",
                url: fileUrl,
                onload: function (response) {
                    const lastModified = response.responseHeaders.match(/Last-Modified:\s*(.*)/i);
                    if (lastModified && lastModified[1]) {
                        const dateObj = new Date(lastModified[1]);
                        const formattedDate = formatDate(dateObj);
                        showDate(link, formattedDate);
                    } else {
                        showDate(link, "No date header");
                    }
                },
                onerror: function () {
                    showDate(link, "Error");
                }
            });
        });
    }

    // Run initially
    processLinks();

    // Watch for dynamically added download buttons (used in new.circleftp.net)
    const observer = new MutationObserver(() => processLinks());
    observer.observe(document.body, { childList: true, subtree: true });
})();