Instagram Time Gate

Hide Instagram except between 17:00 and 20:00

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Instagram Time Gate
// @namespace    https://example.com/instagram-time-gate
// @version      1.0
// @description  Hide Instagram except between 17:00 and 20:00
// @match        https://www.instagram.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const START_HOUR = 17; // 17:00
    const END_HOUR = 20;   // 20:00
    const CHECK_INTERVAL = 60 * 1000; // 1 minute

    let blockerOverlay;

    function isAllowedTime() {
        const now = new Date();
        const hour = now.getHours();
        return hour >= START_HOUR && hour < END_HOUR;
    }

    function getInstagramMounts() {
        return Array.from(document.querySelectorAll('div[id^="mount_"]'));
    }

    function hideInstagram() {
        getInstagramMounts().forEach(el => {
            el.style.display = 'none';
        });

        if (!blockerOverlay) {
            blockerOverlay = document.createElement('div');
            blockerOverlay.style.position = 'fixed';
            blockerOverlay.style.top = '0';
            blockerOverlay.style.left = '0';
            blockerOverlay.style.width = '100vw';
            blockerOverlay.style.height = '100vh';
            blockerOverlay.style.background = '#fff';
            blockerOverlay.style.zIndex = '999999';
            blockerOverlay.style.display = 'flex';
            blockerOverlay.style.alignItems = 'center';
            blockerOverlay.style.justifyContent = 'center';
            blockerOverlay.style.fontFamily = 'sans-serif';
            blockerOverlay.style.fontSize = '24px';
            blockerOverlay.style.color = '#333';
            blockerOverlay.innerText = 'Instagram is blocked until 17:00 🕔';

            document.body.appendChild(blockerOverlay);
        }
    }

    function showInstagram() {
        getInstagramMounts().forEach(el => {
            el.style.display = '';
        });

        if (blockerOverlay) {
            blockerOverlay.remove();
            blockerOverlay = null;
        }
    }

    function enforceRule() {
        if (isAllowedTime()) {
            showInstagram();
        } else {
            hideInstagram();
        }
    }

    // Initial run (wait for DOM)
    const observer = new MutationObserver(() => {
        enforceRule();
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });

    enforceRule();
    setInterval(enforceRule, CHECK_INTERVAL);
})();