Custom Cursor

Just A Custom Cursor

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Custom Cursor
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Just A Custom Cursor
// @author       Brioche
// @match        https://pixelplanet.fun/*
// @match        https://pixmap.fun/*
// @match        https://pixelya.fun/*
// @icon         https://files.catbox.moe/wz07sm.cur
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';

    const customCursorURL = 'https://files.catbox.moe/your-link';
    const cursorSize = 32;

    const validExtensions = ['png', 'cur'];
    const fileExtension = customCursorURL.split('.').pop().toLowerCase();

    if (!validExtensions.includes(fileExtension)) {
        console.error;
        return;
    }

    function applyCursor(cursorURL) {
        const style = document.createElement('style');
        style.innerHTML = `
            * {
                cursor: url('${cursorURL}') ${cursorSize / 2} ${cursorSize / 2}, auto !important;
            }
        `;
        document.head.appendChild(style);
        const observer = new MutationObserver(() => {
            document.body.style.cursor = `url('${cursorURL}') ${cursorSize / 2} ${cursorSize / 2}, auto !important`;
        });
        observer.observe(document.body, { attributes: true, childList: true, subtree: true });
    }

    const testImage = new Image();
    testImage.onload = function () {
        if (fileExtension === 'png' && (testImage.width > cursorSize || testImage.height > cursorSize)) {
            const canvas = document.createElement('canvas');
            const ctx = canvas.getContext('2d');
            canvas.width = cursorSize;
            canvas.height = cursorSize;
            ctx.drawImage(testImage, 0, 0, cursorSize, cursorSize);

            const resizedCursorURL = canvas.toDataURL('image/png');
            applyCursor(resizedCursorURL);
        } else {
            applyCursor(customCursorURL);
        }
    };

    testImage.onerror = function () {
        console.error;
    };

    testImage.src = customCursorURL;
})();