RotateImage

Adds a button to rotate images when they are opened in the browser.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         RotateImage
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Adds a button to rotate images when they are opened in the browser.
// @author       idjawoo
// @include      *.jpg
// @include      *.png
// @include      *.gif
// @icon         https://cdn.discordapp.com/attachments/816751871896453120/920381149484822590/unknown.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let button = document.createElement("div")
    button.innerHTML = `<img width="100%" height="100%" margin="0px" padding="0px" src="https://cdn.discordapp.com/attachments/816751871896453120/920388895462547476/rotation.png"></img>`
    let body = document.evaluate("/html/body", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue

    button.style.cursor = "pointer"
    button.style.position = "absolute"
    button.style.margin = "20px"
    button.style.width = "40px"
    button.style.height = "40px"
    button.style.background = "#fff"
    button.style.padding = "5px"
    button.style.borderRadius = "10px"
    button.style.transition = "0.2s ease-in-out"
    button.style.boxShadow = "inset 0 0 4px rgba(0, 0, 0, 0.5)"

    button.onmouseenter = () => {button.style.boxShadow = "inset 0 0 8px rgba(0, 0, 0, 1)"}
    button.onmouseleave = () => {button.style.boxShadow = "inset 0 0 4px rgba(0, 0, 0, 0.8)"}

    let image = document.evaluate("html[1]/body[1]/img[1]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
    let degrees = 0

    function applyStyle() {
        image.style.transform = String(`rotate(${String(degrees)}deg)`)
    }

    button.addEventListener ("click", () => {
        degrees += 90
        applyStyle()
    }, false);

    let callback = function(m) {
        applyStyle()
    }

    let observer = new MutationObserver(callback)
    observer.observe(image, {attributes: true, childList: true})
    body.appendChild(button)
})();