IdlePixel Chat window resizer handle

Resize the chat window to your heart's content

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);

})();