IdlePixel Chat window resizer handle

Resize the chat window to your heart's content

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         IdlePixel Chat window resizer handle
// @namespace    com.zlef.idlepixel
// @version      1.0.0
// @description  Resize the chat window to your heart's content
// @author       Zlef
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// @require      https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
// ==/UserScript==

(function() {
    'use strict';

    class ChatResizer extends IdlePixelPlusPlugin {
        constructor() {
            super("chatresizer", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                }
            });
        }

        onLogin() {
            // Add the resizable handle to the chat window
            this.addResizableHandle();
        }

        addResizableHandle() {
            // Assuming the chat window has an ID of 'game-chat' and the game has an ID of 'game-screen'
            const chat = $('#game-chat');
            const game = $('#game-screen');

            // Create the resizer div and insert it between the game and chat divs
            const resizer = $('<div id="chat-resizer-handle"></div>');
            resizer.insertAfter(game); // Place the resizer after the game div

            // Make the resizer handle interactive
            resizer.draggable({
                axis: 'x',
                containment: 'parent', // Contain the drag within the parent element
                drag: (event, ui) => {
                    const totalWidth = game.width() + chat.width();
                    const gameWidth = ui.position.left;
                    const chatWidth = totalWidth - gameWidth;

                    // Update the widths of game and chat divs
                    game.width(gameWidth);
                    chat.width(chatWidth);

                    // Move the chat div to the new position
                    chat.css('left', gameWidth);
                }
            });

            // Style the handle
            resizer.css({
                width: '5px',
                height: '100%',
                cursor: 'ew-resize',
                'background-color': 'gray',
                position: 'absolute',
                top: 0,
                // Position the resizer to the left edge of the chat div
                left: game.width()
            });

            // Initial position adjustment for chat
            chat.css({
                position: 'absolute', // Make the chat div absolute
                left: game.width(), // Position it next to the game div
                width: chat.width() // Set the initial width if needed
            });

        }
    }

    // Update class initialiser
    const plugin = new ChatResizer();
    IdlePixelPlus.registerPlugin(plugin);

})();