Webpage Fullscreen Toggle

Adds a button to toggle fullscreen mode for any webpage

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Webpage Fullscreen Toggle
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a button to toggle fullscreen mode for any webpage
// @author       ill13
// @match        *://*/*
// @grant        none
// @license
// ==/UserScript==

(function() {
    'use strict';

    // Create the fullscreen toggle button
    const fullscreenButton = document.createElement('button');
    fullscreenButton.textContent = '⛶';
    fullscreenButton.title = 'Toggle Fullscreen';
    fullscreenButton.style.position = 'fixed';
    fullscreenButton.style.bottom = '32px';
    fullscreenButton.style.right = '32px';
    fullscreenButton.style.zIndex = '9999';
    fullscreenButton.style.fontSize = '16px';
    fullscreenButton.style.background = 'none';
    fullscreenButton.style.border = 'none';
    fullscreenButton.style.cursor = 'pointer';
    fullscreenButton.style.color = '#666666';

    // Add hover effect
    fullscreenButton.addEventListener('mouseover', function() {
        this.style.opacity = '0.8';
    });

    fullscreenButton.addEventListener('mouseout', function() {
        this.style.opacity = '1';
    });

    // Function to toggle fullscreen
    function toggleFullScreen() {
        if (!document.fullscreenElement) {
            // If not in fullscreen mode, enter fullscreen
            if (document.documentElement.requestFullscreen) {
                document.documentElement.requestFullscreen();
                fullscreenButton.textContent = '⏹';
            } else if (document.documentElement.mozRequestFullScreen) { // Firefox
                document.documentElement.mozRequestFullScreen();
                fullscreenButton.textContent = '⏹';
            } else if (document.documentElement.webkitRequestFullscreen) { // Chrome, Safari
                document.documentElement.webkitRequestFullscreen();
                fullscreenButton.textContent = '⏹';
            } else if (document.documentElement.msRequestFullscreen) { // IE/Edge
                document.documentElement.msRequestFullscreen();
                fullscreenButton.textContent = '⏹';
            }
        } else {
            // If in fullscreen mode, exit fullscreen
            if (document.exitFullscreen) {
                document.exitFullscreen();
                fullscreenButton.textContent = '⛶';
            } else if (document.mozCancelFullScreen) { // Firefox
                document.mozCancelFullScreen();
                fullscreenButton.textContent = '⛶';
            } else if (document.webkitExitFullscreen) { // Chrome, Safari
                document.webkitExitFullscreen();
                fullscreenButton.textContent = '⛶';
            } else if (document.msExitFullscreen) { // IE/Edge
                document.msExitFullscreen();
                fullscreenButton.textContent = '⛶';
            }
        }
    }

    // Add click event to the button
    fullscreenButton.addEventListener('click', toggleFullScreen);

    // Listen for fullscreenchange event to update button appearance
    document.addEventListener('fullscreenchange', function() {
        if (document.fullscreenElement) {
            fullscreenButton.textContent = '⏹';
        } else {
            fullscreenButton.textContent = '⛶';
        }
    });

    // Also handle browser-specific events
    document.addEventListener('mozfullscreenchange', function() {
        if (document.mozFullScreenElement) {
            fullscreenButton.textContent = '⏹';
        } else {
            fullscreenButton.textContent = '⛶';
        }
    });

    document.addEventListener('webkitfullscreenchange', function() {
        if (document.webkitFullscreenElement) {
            fullscreenButton.textContent = '⏹';
        } else {
            fullscreenButton.textContent = '⛶';
        }
    });

    document.addEventListener('MSFullscreenChange', function() {
        if (document.msFullscreenElement) {
            fullscreenButton.textContent = '⏹';
        } else {
            fullscreenButton.textContent = '⛶';
        }
    });

    // Add the button to the page
    document.body.appendChild(fullscreenButton);

    // Key shortcut (Alt+F) to toggle fullscreen
    document.addEventListener('keydown', function(e) {
        if (e.altKey && e.key === 'f') {
            toggleFullScreen();
        }
    });
})();