Fake Date

Set a fake date in your browser globally using Tampermonkey

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Fake Date
// @namespace    fake-date-script
// @version      1.2
// @description  Set a fake date in your browser globally using Tampermonkey
// @match        http://*/*
// @match        https://*/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const fakeDateValue = '2025-04-10T00:00:00.000Z';
    const fakeDate = new Date(fakeDateValue);
    const fakeTimestamp = fakeDate.getTime();
    const baseTime = Date.now(); // Capture the real time when script loads
    const timeDifference = fakeTimestamp - baseTime;
    const OriginalDate = Date;

    function FakeDate(...args) {
        if (args.length === 0) {
            // Return current fake date when no args provided
            return new OriginalDate(OriginalDate.now() + timeDifference);
        }
        return new OriginalDate(...args);
    }

    // Ensure all static methods are properly copied
    FakeDate.now = function() {
        return OriginalDate.now() + timeDifference;
    };

    FakeDate.parse = OriginalDate.parse;
    FakeDate.UTC = OriginalDate.UTC;

    // Properly copy prototype chain
    FakeDate.prototype = OriginalDate.prototype;
    FakeDate.toString = function() { return OriginalDate.toString(); };
    FakeDate[Symbol.species] = OriginalDate;

    // Override Date
    window.Date = FakeDate;

    // Override performance.now() to align with fake date
    if (window.performance && window.performance.now) {
        const originalNow = window.performance.now.bind(window.performance);
        const perfTimeOrigin = performance.timeOrigin || 0;

        window.performance.now = function() {
            return originalNow() + (timeDifference);
        };

        // Update timeOrigin if it exists
        if ('timeOrigin' in window.performance) {
            Object.defineProperty(window.performance, 'timeOrigin', {
                get: function() {
                    return perfTimeOrigin + timeDifference;
                }
            });
        }
    }

    console.log('Fake Date script loaded. Current fake date:', new Date().toISOString());
})();