Replace Reddit Content and Time Since Installation

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

目前為 2025-05-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();

})();