Custom Profile Background 2

background

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

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

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 Profile Background 2
// @namespace    http://tampermonkey.net/
// @version      2
// @description  background
// @author       Ghost
// @match        https://pixelplace.io/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==


const lastBackgroundImage = GM_getValue('lastBackgroundImage', '');
let isTiled = GM_getValue('isTiled', false);

// press Ctrl+M
document.addEventListener('keydown', function(event) {
    if (event.ctrlKey && event.key === 'm') {
        const input = document.createElement('input');
        input.type = 'file';
        input.accept = 'image/*';
        input.addEventListener('change', function() {
            const file = input.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function() {
                    const imageUrl = reader.result;
                    GM_setValue('lastBackgroundImage', imageUrl);
                    applyBackgroundImage(imageUrl, isTiled);
                };
                reader.readAsDataURL(file);
            }
        });
        input.click();
    }
});

// press ctrl+1 to change to tile mode
document.addEventListener('keydown', function(event) {
    if (event.ctrlKey && event.key === 'i') {
        isTiled = !isTiled;
        GM_setValue('isTiled', isTiled);
        applyBackgroundImage(GM_getValue('lastBackgroundImage', ''), isTiled);
    }
});


function applyBackgroundImage(imageUrl, tile) {
    GM_addStyle(`
        .box-x {
            background-image: url('${imageUrl}');
            background-size: ${tile ? '100px auto' : 'cover'};
            background-position: ${tile ? 'top left' : 'center'};
            background-repeat: ${tile ? 'repeat' : 'no-repeat'};
            background-origin: border-box;
            background-clip: content-box;
        }
        }
    `);
}


if (lastBackgroundImage) {
    applyBackgroundImage(GM_getValue('lastBackgroundImage', ''), isTiled);
}