rotate-screen

旋轉網頁, Ctrl + Alt + 方向鍵

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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           rotate-screen
// @namespace      http://tampermonkey.net/
// @version        1.0.0
// @author         Vanisoul
// @description    旋轉網頁, Ctrl + Alt + 方向鍵
// @match          *://*/*
// @grant          none
// ==/UserScript==

(function () {
    'use strict';

    function rotatePage(degrees) {
        const originalWidth = document.documentElement.clientWidth || window.innerWidth;
        const originalHeight = document.documentElement.clientHeight || window.innerHeight;
        let container = document.querySelector('.rotate-container');
        if (!container) {
            container = document.createElement('div');
            container.classList.add('rotate-container');
            while (document.body.firstChild) {
                container.appendChild(document.body.firstChild);
            }
            document.body.appendChild(container);
        }
        container.style.cssText = "";
        if (degrees === 90 || degrees === -90) {
            container.style.width = `${originalHeight}px`;
            container.style.height = `${originalWidth}px`;
            container.style.maxWidth = '100vh';
            container.style.maxHeight = '100vw';
            container.style.overflow = 'auto';
            container.style.position = 'absolute';
            container.style.top = '50%';
            container.style.left = '50%';
            container.style.transform = `translate(-50%, -50%) rotate(${degrees}deg)`;
        }
        else if (degrees === 180 || degrees === -180) {
            container.style.width = `${originalWidth}px`;
            container.style.height = `${originalHeight}px`;
            container.style.overflow = 'auto';
            container.style.position = 'absolute';
            container.style.top = '50%';
            container.style.left = '50%';
            container.style.transform = `translate(-50%, -50%) rotate(${degrees}deg)`;
        }
    }
    document.addEventListener('keydown', function (event) {
        const controlKey = event.ctrlKey;
        const altKey = event.altKey;
        const touchKey = controlKey && altKey;
        if (touchKey) {
            switch (event.key) {
                case "ArrowUp":
                    rotatePage(180);
                    break;
                case "ArrowDown":
                    rotatePage(0);
                    break;
                case "ArrowLeft":
                    rotatePage(90);
                    break;
                case "ArrowRight":
                    rotatePage(-90);
                    break;
            }
        }
    });

})();