XVideos Upload Date

Displays the upload date to the right of the video view counter on XVideos video pages.

// ==UserScript==
// @name         XVideos Upload Date
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Displays the upload date to the right of the video view counter on XVideos video pages.
// @author       nereids
// @match        https://www.xvideos.com/video*
// @grant        none
// @license      MIT
// @author       nereids
// @icon         https://icons.duckduckgo.com/ip3/xvideos.com.ico
// ==/UserScript==

(function() {
    'use strict';

    // Configuration
    const FONT_SIZE = '14px'; // Adjust this value to change the font size (e.g., '12px', '16px')

    // Function to extract uploadDate from JSON-LD
    function getUploadDate() {
        const scripts = document.querySelectorAll('script[type="application/ld+json"]');
        for (const script of scripts) {
            try {
                const json = JSON.parse(script.textContent);
                if (json.uploadDate) {
                    // Format the date to a readable string, e.g., "October 9, 2025"
                    return new Date(json.uploadDate).toLocaleDateString('en-US', {
                        year: 'numeric',
                        month: 'long',
                        day: 'numeric'
                    });
                }
            } catch (e) {
                console.error('Error parsing JSON-LD:', e);
            }
        }
        return 'Unknown';
    }

    // Get the upload date
    const uploadDate = getUploadDate();

    // Find the view counter element (assuming ID 'v-views' based on common structure; adjust if needed)
    const viewElement = document.getElementById('v-views') || document.querySelector('.views-var') || document.querySelector('.video-views');

    if (viewElement) {
        // Create a new span element for the upload date
        const dateSpan = document.createElement('span');
        dateSpan.textContent = ` | ${uploadDate}`;
        dateSpan.style.marginLeft = '10px';
        dateSpan.style.color = '#999'; // Optional styling to match the site's aesthetic
        dateSpan.style.fontSize = FONT_SIZE; // Apply the configurable font size

        // Append the date span to the right of the view counter
        viewElement.appendChild(dateSpan);
    } else {
        console.warn('View counter element not found. Selector may need adjustment.');
    }
})();