Better Daymap

Customize your profile picture and background on Daymap.

Устаревшая версия за 10.04.2025. Перейдите к последней версии.

// ==UserScript==
// @name         Better Daymap
// @namespace    Better Daymap
// @version      1.1.1
// @description  Customize your profile picture and background on Daymap.
// @author       LiamGo
// @match        https://*.daymap.net/*
// @icon         https://lh3.googleusercontent.com/_Jt3LvQt0VV4wQkW6brDIvKNCQMSWgzbE_ofiwnWCgWTw4pUv4HsLX0AH8PpNEde85jt8XPWyXQo91d4MEYqZZgm-k4=s60
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addScript
// @run-at document-start
// ==/UserScript==

(function() {
    'use strict';

    // Load and execute the Customize Daymap script
    GM_addScript('https://update.greasyfork.org/scripts/532395/Daymap Translucency.user.js')
    GM_addScript('https://update.greasyfork.org/scripts/532424/Daymap TD Transparency.user.js')
    GM_addScript('https://update.greasyfork.org/scripts/532425/Daymap Timetable Redesign.user.js')

    // Function to set the background color
    function setBackgroundColor(color) {
        document.body.style.backgroundColor = color;
        GM_setValue('backgroundColor', color); // Save to GM storage
    }

    // Function to set the background image (now stretches to fill)
    function setBackgroundImage(url) {
        document.body.style.backgroundImage = `url(${url})`;
        document.body.style.backgroundSize = '100% 100%'; // Stretch to fill entire screen
        document.body.style.backgroundRepeat = 'no-repeat';
        document.body.style.backgroundPosition = 'top left'; // Align to top-left
        document.body.style.backgroundAttachment = 'fixed'; // Fixed position
        GM_setValue('backgroundImage', url); // Save to GM storage
    }

    // Function to set the profile image
    function setProfileImage(url) {
        const avatarElements = [
            document.querySelector('.nav-user-image'), // Updated selector for the first profile image
            document.getElementById('divUserAvatar') // Adjust ID for the second profile image
        ];
        avatarElements.forEach(avatarElement => {
            if (avatarElement) {
                avatarElement.style.backgroundImage = `url(${url})`;
            }
        });
        GM_setValue('profileImage', url); // Save to GM storage
    }

    // Check if there's a saved color, image, and profile image in GM storage
    const savedColor = GM_getValue('backgroundColor', '#000000'); // Default background color set to black
    const savedImage = GM_getValue('backgroundImage', '');
    const savedProfileImage = GM_getValue('profileImage', '');

    setBackgroundColor(savedColor); // Apply saved color
    if (savedImage) setBackgroundImage(savedImage); // Apply saved image

    // Set the profile image after a 1.75-second delay
    if (savedProfileImage) {
        setTimeout(() => {
            setProfileImage(savedProfileImage); // Apply saved profile image after 1.75 seconds
        }, 1750);
    }

    // Create a settings modal for background color
    const colorModal = createModal('Change Background Color');
    const colorInput = createInput('text', savedColor);
    colorModal.appendChild(colorInput);
    const saveColorButton = createButton('Save', () => {
        const newColor = colorInput.value;
        setBackgroundColor(newColor);
        colorModal.style.display = 'none';
    });
    const closeColorButton = createButton('Close', () => colorModal.style.display = 'none');
    colorModal.appendChild(saveColorButton);
    colorModal.appendChild(closeColorButton);
    document.body.appendChild(colorModal);

    GM_registerMenuCommand("Change Background Color", () => {
        colorModal.style.display = 'block';
    });

    // Create a settings modal for background image
    const imageModal = createModal('Change Background Image');
    const imageInput = createInput('text', savedImage, 'Enter image URL');
    imageModal.appendChild(imageInput);
    const saveImageButton = createButton('Save', () => {
        const newImage = imageInput.value;
        setBackgroundImage(newImage);
        imageModal.style.display = 'none';
    });
    const closeImageButton = createButton('Close', () => imageModal.style.display = 'none');
    imageModal.appendChild(saveImageButton);
    imageModal.appendChild(closeImageButton);
    document.body.appendChild(imageModal);

    GM_registerMenuCommand("Change Background Image", () => {
        imageModal.style.display = 'block';
    });

    // Create a settings modal for profile image
    const profileImageModal = createModal('Change Profile Image');
    const profileImageInput = createInput('text', savedProfileImage, 'Enter profile image URL');
    profileImageModal.appendChild(profileImageInput);
    const saveProfileImageButton = createButton('Save', () => {
        const newProfileImage = profileImageInput.value;
        setProfileImage(newProfileImage);
        profileImageModal.style.display = 'none';
    });
    const closeProfileImageButton = createButton('Close', () => profileImageModal.style.display = 'none');
    profileImageModal.appendChild(saveProfileImageButton);
    profileImageModal.appendChild(closeProfileImageButton);
    document.body.appendChild(profileImageModal);

    GM_registerMenuCommand("Change Profile Image", () => {
        profileImageModal.style.display = 'block';
    });

    function createModal(title) {
        const modal = document.createElement('div');
        modal.style.display = 'none';
        modal.style.position = 'fixed';
        modal.style.left = '50%';
        modal.style.top = '50%';
        modal.style.transform = 'translate(-50%, -50%)';
        modal.style.backgroundColor = '#fff';
        modal.style.padding = '20px';
        modal.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
        modal.style.zIndex = '1001';

        const titleElement = document.createElement('h3');
        titleElement.textContent = title;
        modal.appendChild(titleElement);

        return modal;
    }

    function createInput(type, value = '', placeholder = '') {
        const input = document.createElement('input');
        input.type = type;
        input.value = value;
        input.placeholder = placeholder;
        return input;
    }

    function createButton(text, onClick) {
        const button = document.createElement('button');
        button.textContent = text;
        button.addEventListener('click', onClick);
        return button;
    }
})();