Gartic background change

Choose the desired image or gif for the Gartic background

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();

    }
})();