Kindroid Tools, BackGround

Allows the user to customize the background image and some visual test.

目前为 2023-09-19 提交的版本。查看 最新版本

// ==UserScript==
// @name         Kindroid Tools, BackGround 
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Allows the user to customize the background image and some visual test.
// @match        https://kindroid.ai/home
// @grant        GM_setValue
// @grant        GM_getValue
// @info         By TenPassion
// @license      GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    // Function to change text
    function changeText(elements) {
        const text1 = document.querySelector('.css-19hb772');
        const text2 = document.querySelector('.css-ppua9z');
        elements.forEach(function(element) {
            element.textContent = text1.textContent + ' x ' + text2.textContent + ' on Kindroid ';
        });
    }

    // Function to remove elements based on XPath
    function removeElements(xpath) {
        const elementsToRemove = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null);
        let element = elementsToRemove.iterateNext();
        while (element) {
            element.parentNode.removeChild(element);
            element = elementsToRemove.iterateNext();
        }
    }

    // Function to change the background image
    function changeBackground(imageURL) {
        const targetElement = document.querySelector('.css-1lvpjll');
        if (targetElement) {
            // Remove the old background image
            const oldBackground = targetElement.style.backgroundImage;
            if (oldBackground !== 'none') {
                URL.revokeObjectURL(oldBackground);
            }

            targetElement.style.backgroundImage = 'none';

            if (imageURL !== '') {
                targetElement.style.backgroundImage = `url("${imageURL}")`;
                targetElement.style.backgroundSize = 'cover';
                targetElement.style.backgroundRepeat = 'no-repeat';
            }
        }
    }

    // Function to adjust opacity of 'css-teti0a' and 'css-100dd8p' elements
    function adjustOpacityTeti0a() {
        const elementsToAdjust = document.querySelectorAll('.css-teti0a, .css-1j9xj7u');
        elementsToAdjust.forEach(function(element) {
            element.style.opacity = '0.9';
        });
    }

    // Function to adjust opacity of 'css-100dd8p' elements
    function adjustOpacity100dd8p() {
        const elementsToAdjust = document.querySelectorAll('.css-100dd8p');
        elementsToAdjust.forEach(function(element) {
            element.style.opacity = '0.9';
        });
    }

    // Function to handle file selection for custom background image
    function handleFileSelect(event) {
        const file = event.target.files[0];
        if (file) {
            const reader = new FileReader();
            reader.onload = function(e) {
                const imageURL = e.target.result;
                GM_setValue('customImageURL', imageURL);
                changeBackground(imageURL);
            };
            reader.readAsDataURL(file);
        }
    }

    // Create a hidden file input element for image customization
    const fileInput = document.createElement('input');
    fileInput.type = 'file';
    fileInput.style.display = 'none';
    fileInput.addEventListener('change', handleFileSelect);

    // Create a button for customizing the background image
    const customImageButton = document.createElement('button');
    customImageButton.textContent = '😈';
    customImageButton.style.position = 'fixed';
    customImageButton.style.bottom = '10px';
    customImageButton.style.right = '10px';
    customImageButton.style.zIndex = '9999';
    customImageButton.addEventListener('click', function() {
        fileInput.click();
    });

    // Append the file input and custom image button to the document body
    document.body.appendChild(fileInput);
    document.body.appendChild(customImageButton);

    // Get the URL of the custom image from local storage
    const customImageURL = GM_getValue('customImageURL', '');
    if (customImageURL !== '') {
        changeBackground(customImageURL);
    }

    // Add an event listener to re-display the image when the page is loaded
    window.addEventListener('load', function() {
        const customImageURL = GM_getValue('customImageURL', '');
        if (customImageURL !== '') {
            changeBackground(customImageURL);
        }
    });

    // Use MutationObserver to watch for changes in the DOM
    const observer = new MutationObserver(function(mutationsList, observer) {
        for (let mutation of mutationsList) {
            if (mutation.type === 'childList') {
                const elements = document.querySelectorAll('.chakra-text.css-s68iw5');
                if (elements.length > 0) {
                    changeText(elements);
                    adjustOpacityTeti0a();
                    adjustOpacity100dd8p();
                }
                removeElements('//header/div[2]/a[1]/*[1]');
                removeElements('//header/div[2]/a[2]/*[1]');
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

    // Initial adjustments
    adjustOpacityTeti0a();
    adjustOpacity100dd8p();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址