Player List Mod (Draggable) | Shell Shockers | flyg0n LiTe

Draggable player list UI Mod for Shell Shockers. Shows paused players and players hp.

目前為 2023-05-09 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Player List Mod (Draggable) | Shell Shockers | flyg0n LiTe
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Draggable player list UI Mod for Shell Shockers. Shows paused players and players hp.
// @author       flyg0n LiTe
// @match        https://shellshock.io/*
// @match        https://mathactivity.xyz/*
// @match        https://mathdrills.life/*
// @icon         https://www.berrywidgets.com/assets/health-bar2.png
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

 GM_addStyle(`
    #playerHealthContainer {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1000;
        color: white;
        font-size: 14px;
        background-color: #DB5A48;
        font-family: 'Kanit', sans-serif;
        padding: 5px;
        cursor: grab;
        margin: 5px;
    }
    .changeColor {
        position: absolute;
        top: 0;
        right: 0;
        z-index: 1001;
        background: none;
        border: none;
        color: white;
        font-size: 20px;
        cursor: pointer;
        outline: none;
    }
`);

    // Add a container to display the health
    const playerHealthContainer = document.createElement('div');
    playerHealthContainer.id = 'playerHealthContainer';
    document.body.appendChild(playerHealthContainer);

    function sortByHealth(a, b) {
        if (a.hp > b.hp) {
            return -1;
        }
        if (a.hp < b.hp) {
            return 1;
        }
        return 0;
    }

    function updateHealthDisplay() {
        let playersArray = Array.from(window.players.values());
        playersArray.sort(sortByHealth);

        let healthInfo = '';
        playersArray.forEach((player) => {
             healthInfo += `${player.name}: ${player.hp === 0 ? 'Paused' : (player.hp).toFixed(2) + ' HP'}<br>`;
        });
        playerHealthContainer.innerHTML = healthInfo;
    }

    // Store player data
    window.players = new Map();

    // Intercept push method to store player data
    const originalPush = Array.prototype.push;
    Array.prototype.push = function(data) {
        try {
            if (arguments[0].player && arguments[0].id) {
                const playerProxy = new Proxy(arguments[0].player, {
                    set: (target, property, value) => {
                        target[property] = value;
                        if (property === 'hp') {
                            updateHealthDisplay();
                        }
                        return true;
                    },
                });
                window.players.set(playerProxy.id, playerProxy);
                updateHealthDisplay();
            }
        } catch (e) {
            console.log(e);
        }
        return originalPush.apply(this, arguments);
    };

    // Add color picker
    const colorPicker = document.createElement('input');
    colorPicker.type = 'color';
    colorPicker.style.display = 'none';
    colorPicker.onchange = () => {
        playerHealthContainer.style.backgroundColor = colorPicker.value;
    };
    document.body.appendChild(colorPicker);

    // Add change color button
    const changeColorBtn = document.createElement('button');
    changeColorBtn.className = 'changeColor';
    changeColorBtn.innerHTML = '&#9881;';
    changeColorBtn.onclick = () => {
        colorPicker.click();
    };
    document.body.appendChild(changeColorBtn);

    // Load Google Fonts
    const googleFontLink = document.createElement('link');
    googleFontLink.href = 'https://fonts.googleapis.com/css2?family=Kanit&display=swap';
googleFontLink.rel = 'stylesheet';
document.head.appendChild(googleFontLink);
    // Make the playerHealthContainer draggable
playerHealthContainer.addEventListener('mousedown', (event) => {
    event.preventDefault();
    const offsetX = event.clientX - playerHealthContainer.getBoundingClientRect().left;
    const offsetY = event.clientY - playerHealthContainer.getBoundingClientRect().top;

    const onMouseMove = (event) => {
        playerHealthContainer.style.left = `${event.clientX - offsetX}px`;
        playerHealthContainer.style.top = `${event.clientY - offsetY}px`;
    };

    const onMouseUp = () => {
        document.removeEventListener('mousemove', onMouseMove);
        document.removeEventListener('mouseup', onMouseUp);
    };

    document.addEventListener('mousemove', onMouseMove);
    document.addEventListener('mouseup', onMouseUp);
});
})();