Gartic background change

Choose the desired image or gif for the Gartic background

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           Gartic background change
// @description    Choose the desired image or gif for the Gartic background
// @version        1.0
// @author         STRAGON
// @license        N/A
// @match          *://gartic.io/*
// @match          *://*/*?__cpo=aHR0cHM6Ly9nYXJ0aWMuaW8
// @icon           https://static.cdnlogo.com/logos/s/96/st.svg
// @grant          GM_addStyle
// @namespace      https://greasyfork.org/en/users/1353946-stragon-x
// ==/UserScript==

(function() {
    'use strict';

    var imageUrl = localStorage.getItem('imageUrl');

    if (window.location.href.indexOf('https://gartic.io') !== -1) {
        if (imageUrl) {
            GM_addStyle('body { background: url("' + imageUrl + '") no-repeat fixed center; background-size: cover; }');
        }

       var button = document.createElement('button');

        button.textContent = 'Change Background';
        button.style.zIndex = '99999';
        button.style.backgroundColor = 'red';
        button.style.position = 'fixed';
        button.style.bottom = '0px';
        button.style.right = '0px';
        button.style.padding = '10px 20px';
        button.style.fontSize = '16px';
        button.style.borderRadius = '5px';
        button.onclick = function() {
            var input = document.createElement('input');
            input.type = 'file';
            input.accept = 'image/*';
            input.onchange = function() {
                var file = input.files[0];
                var reader = new FileReader();
                reader.onload = function(event) {
                    var newImageUrl = event.target.result;
                    localStorage.setItem('imageUrl', newImageUrl);
                    GM_addStyle('body { background: url("' + newImageUrl + '") no-repeat fixed center; background-size: cover; }');
                };
                reader.readAsDataURL(file);
            };
            input.click();
        };
        document.body.appendChild(button);
        document.getElementById('background').remove();

    }
})();