Custom Profile Background

Style the profile section on PixelPlace

目前為 2024-04-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Custom Profile Background
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Style the profile section on PixelPlace
// @author       Ghost
// @match        https://pixelplace.io/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

// Retrieve the last set background image URL from local storage
const lastBackgroundImage = GM_getValue('lastBackgroundImage', '');

// Add an event listener to handle Ctrl+M key press
document.addEventListener('keydown', function(event) {
    if (event.ctrlKey && event.key === 'm') {
        // Prompt the user to upload an image
        const input = document.createElement('input');
        input.type = 'file';
        input.accept = 'image/*';
        input.addEventListener('change', function() {
            const file = input.files[0];
            if (file) {
                // Read the image file as data URL
                const reader = new FileReader();
                reader.onload = function() {
                    const imageUrl = reader.result;
                    // Store the image URL in local storage
                    GM_setValue('lastBackgroundImage', imageUrl);
                    // Apply the image as background
                    applyBackgroundImage(imageUrl);
                };
                reader.readAsDataURL(file);
            }
        });
        input.click();
    }
});

// Function to apply the background image
function applyBackgroundImage(imageUrl) {
    GM_addStyle(`
        /* Styling for the profile section */
        .box-x {
            background-image: url('${imageUrl}');
            background-size: cover; /* Adjust as needed */
            background-position: center; /* Adjust as needed */
            background-repeat: no-repeat; /* Prevents the image from repeating */
        }
    `);
}

// Apply the last set background image on page load
if (lastBackgroundImage) {
    applyBackgroundImage(lastBackgroundImage);
}