poxel.io 模組選單

模組選單

// ==UserScript==
// @name        poxel.io 模組選單
// @grant       none
// @version     1.1
// @author      HUANG WEI-LUN HUANG WEI-LUN
// @description 模組選單
// @match       *://poxel.io/*
// @namespace http://tampermonkey.net/
// ==/UserScript==
// 建立模組選單的 HTML
const menuHTML = `
  <div id="moduleMenu" style="
    position: fixed; top: 20px; right: 20px; width: 180px; background: rgba(0,0,0,0.7);
    color: white; font-family: Arial; font-size: 14px; padding: 10px; border-radius: 8px; z-index: 9999;
  ">
    <h3 style="margin-top:0; margin-bottom:10px; font-size:16px;">模組選單</h3>
    <label><input type="checkbox" id="lockHeadToggle" checked> 鎖頭</label><br>
    <label><input type="checkbox" id="showEnemyToggle" checked> 顯示敵人點位</label><br>
    <label><input type="checkbox" id="invisibleToggle"> 隱身</label><br>
  </div>
`;

// 插入選單到頁面
if (!document.getElementById('moduleMenu')) {
  const div = document.createElement('div');
  div.innerHTML = menuHTML;
  document.body.appendChild(div.firstElementChild);
}

// 狀態變數
let lockHeadEnabled = true;
let showEnemyEnabled = true;
let invisibleEnabled = false;

// 綁定切換事件
document.getElementById('lockHeadToggle').addEventListener('change', (e) => {
  lockHeadEnabled = e.target.checked;
});

document.getElementById('showEnemyToggle').addEventListener('change', (e) => {
  showEnemyEnabled = e.target.checked;
});

document.getElementById('invisibleToggle').addEventListener('change', (e) => {
  invisibleEnabled = e.target.checked;
  toggleInvisibility(invisibleEnabled);
});

// 隱身功能示範(依照遊戲物件調整)
function toggleInvisibility(enable) {
  if (!window.player) return;
  // 假設 player 有個 visible 屬性
  if (enable) {
    window.player.visible = false;
    // 或者用 CSS 隱藏玩家的DOM元素
    // document.getElementById('playerSprite').style.display = 'none';
  } else {
    window.player.visible = true;
    // document.getElementById('playerSprite').style.display = 'block';
  }
}

// 按 M 鍵切換模組選單顯示/隱藏
document.addEventListener('keydown', (e) => {
  if (e.key === 'm' || e.key === 'M') {
    const menu = document.getElementById('moduleMenu');
    if (menu.style.display === 'none') {
      menu.style.display = 'block';
    } else {
      menu.style.display = 'none';
    }
  }
});

// 主迴圈示範
function mainLoop() {
  let player = window.player;
  if (!player) return;

  let enemy = findClosestEnemy(player.x, player.y);

  if (lockHeadEnabled) lockHead(enemy);
  if (showEnemyEnabled) drawEnemyPositions();

  requestAnimationFrame(mainLoop);
}

mainLoop();