Replace Reddit Content and Time Since Installation

Replaces Reddit content and shows time difference from the userscript installation date

当前为 2025-05-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Replace Reddit Content and Time Since Installation
// @namespace    Me
// @version      1.2
// @description  Replaces Reddit content and shows time difference from the userscript installation date
// @author       GoogleMaster662
// @match        https://www.reddit.com/*
// @match        https://old.reddit.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to calculate the time difference from the installation date
    function calculateTimeDifference(installDate) {
        const currentDate = new Date();
        
        // Calculate the difference in milliseconds
        const timeDifference = currentDate - installDate;
        
        // Convert milliseconds to days, hours, and minutes
        const totalDays = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
        const totalHours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        const totalMinutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));

        return `${totalDays} days, ${totalHours} hours, and ${totalMinutes} minutes ago.`;
    }

    // Function to check and save the installation date
    function getInstallDate() {
        let installDate = localStorage.getItem('userscriptInstallDate');

        if (!installDate) {
            // If the installation date is not saved yet, save it
            installDate = new Date();
            localStorage.setItem('userscriptInstallDate', installDate.toString());
        } else {
            installDate = new Date(installDate);
        }

        return installDate;
    }

    // Replace the content of the Reddit page
    function replaceRedditContent() {
        const installDate = getInstallDate(); // Get the install date from localStorage
        const timeDifference = calculateTimeDifference(installDate); // Calculate time since installation

        // Replace the entire body content of the Reddit page
        document.body.innerHTML = `
            <div style="text-align: center; padding: 20px;">
                <h1>Reddit is replaced!</h1>
                <p>This userscript was installed on: ${new Date(installDate).toLocaleDateString()}</p>
                <p>The userscript was installed ${timeDifference}.</p>
                <p>This page is now completely replaced.</p>
            </div>
        `;
    }

    // Call the function to replace content when the page loads
    replaceRedditContent();

})();