Custom Background CybHack

Установка кастомного фона на всех страницах форума CybHack.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Custom Background CybHack
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Установка кастомного фона на всех страницах форума CybHack.
// @author       Elfiyka
// @match        https://cybhack.net/*
// @icon         https://cybhack.net/data/assets/logo/CH_emoji01.png
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var container = document.createElement('div');
    container.style.position = 'fixed';
    container.style.top = '97%';
    container.style.left = '99%';
    container.style.transform = 'translate(-50%, -50%)';
    container.style.zIndex = '9999';

    // Функция создания кнопки
    function createButton(iconURL, hoverColor, clickColor, clickHandler) {
        var button = document.createElement('button');
        button.style.backgroundColor = 'transparent';
        button.style.border = 'none';
        button.style.width = '35px';
        button.style.height = '35px';
        button.style.marginRight = '5px';
        button.style.boxShadow = 'none';

        var icon = new Image();
        icon.src = iconURL;
        icon.style.width = '100%';
        icon.style.height = '100%';
        icon.style.filter = 'invert(100%)';
        button.appendChild(icon);

        button.addEventListener('mouseover', function () {
            icon.style.opacity = '0.7';
        });

        button.addEventListener('mouseout', function () {
            icon.style.opacity = '1';
        });

        button.addEventListener('click', function () {
            icon.style.opacity = '0.5';
            clickHandler();
        });

        return button;
    }

    function handleUploadButtonClick() {
        var linkBG = prompt("Введите URL для фона:", localStorage.getItem('linkBG') || "");
        if (linkBG !== null && linkBG.trim() !== "") {
            localStorage.setItem('linkBG', linkBG);
            document.querySelectorAll('.p-code, .p-body').forEach(function(elem) {
                elem.style.backgroundImage = 'url(' + linkBG + ')';
                elem.style.backgroundSize = '100%';
                elem.style.backgroundAttachment = 'fixed';
            });
        } else {
            localStorage.removeItem('linkBG');
            document.querySelectorAll('.p-code, .p-body').forEach(function(elem) {
                elem.style.backgroundImage = '';
                elem.style.backgroundSize = '';
                elem.style.backgroundAttachment = '';
            });
        }
    }

    var uploadButton = createButton('https://www.svgrepo.com/show/239880/background.svg', 'darkgreen', 'lightgreen', handleUploadButtonClick);

    container.appendChild(uploadButton);

    document.body.appendChild(container);

    var storedLinkBG = localStorage.getItem('linkBG');
    if (storedLinkBG && storedLinkBG.trim() !== "") {
        document.querySelectorAll('.p-code, .p-body').forEach(function(elem) {
            elem.style.backgroundImage = 'url(' + storedLinkBG + ')';
            elem.style.backgroundSize = '100%';
            elem.style.backgroundAttachment = 'fixed';
        });
    }
})();