MWI-Equipment-Diff

Make life easier

目前為 2025-05-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MWI-Equipment-Diff
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  Make life easier
// @author       BKN46
// @match        https://*.milkywayidle.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=milkywayidle.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
  'use strict';

  let equipmentToDiff = {};
  const isZHInGameSetting = localStorage.getItem("i18nextLng")?.toLowerCase()?.startsWith("zh");
  let isZH = isZHInGameSetting;

  function parseEquipmentModal(element) {
    const equipmentDetail = {};
    const detailLines = element.querySelectorAll('.EquipmentStatsText_stat__27Sus');
    for (const line of detailLines) {
      if (line.querySelector('.EquipmentStatsText_uniqueStat__2xvqX')) continue;
      const data = line.textContent.split(':');
      if (data.length === 2) {
        const key = data[0].trim();
        const value = data[1].split('(')[0].trim();
        if (value === 'N/A') continue;
        equipmentDetail[key] = value;
      }
    }

    if (!element.querySelector('.diff-tooltip')) {
      const diffTooltip = document.createElement('div');
      diffTooltip.className = 'diff-tooltip';
      diffTooltip.textContent = isZH ? '按\'d\'来添加作为对比对象' : 'Press "d" to add to quick diff';
      diffTooltip.style = 'color:rgb(0, 108, 158); font-weight: bold;';
      element.appendChild(diffTooltip);

      if (equipmentToDiff.data) {
        const diffRemoveTooltip = document.createElement('div');
        diffRemoveTooltip.className = 'diff-remove-tooltip';
        diffRemoveTooltip.textContent = isZH ? '按\'r\'来移除当前对比' : 'Press "r" to remove present quick diff';
        diffRemoveTooltip.style = 'color:rgb(0, 108, 158); font-weight: bold;';
        element.appendChild(diffRemoveTooltip);
      }
    }
    
    return equipmentDetail;
  }

  function addDiffToModal(element, data) {
    if (element.querySelector('.diff-value')) return;
    const TextArea = element.querySelector('.EquipmentStatsText_equipmentStatsText__djKBS').firstChild;
    const detailLines = element.querySelectorAll('.EquipmentStatsText_stat__27Sus');
    for (const line of detailLines) {
      const key = line.textContent.split(':')[0].trim();
      const valueElement = line.querySelectorAll('span')[1];
      const diffSpan = document.createElement('span');
      diffSpan.className = 'diff-value';
      diffSpan.style = 'color: rgb(0, 108, 158); font-weight: bold;';
      if (key in equipmentToDiff.data) {
        const diffValue = equipmentToDiff.data[key];
        diffSpan.textContent = ` (${diffValue})`;
        if (data[key] === diffValue) {
          continue;
        }
      } else {
        diffSpan.textContent = ` (N/A)`;
      }
      valueElement.appendChild(diffSpan);
    }
    for (const key in equipmentToDiff.data) {
      if (!(key in data)) {
        const newLine = document.createElement('div');
        newLine.className = 'EquipmentStatsText_stat__27Sus';

        const keySpan = document.createElement('span');
        keySpan.textContent = `${key}: `;
        newLine.appendChild(keySpan);

        const valueSpan = document.createElement('span');
        valueSpan.textContent = 'N/A';
        newLine.appendChild(valueSpan);

        const diffSpan = document.createElement('span');
        diffSpan.className = 'diff-value';
        diffSpan.textContent = ` (${equipmentToDiff.data[key]})`;
        diffSpan.style = 'color: rgb(0, 108, 158); font-weight: bold;';
        valueSpan.appendChild(diffSpan);
        TextArea.appendChild(newLine);
      }
    }
  }

  setInterval(() => {
    const modal = document.querySelector('.MuiPopper-root');
    if (!modal) return;
    const equipmentDetail = modal.querySelector('.ItemTooltipText_equipmentDetail__3sIHT');
    if (!equipmentDetail) return;

    const equipmentName = modal.querySelector('.ItemTooltipText_name__2JAHA').textContent.trim();
    const equipmentData = parseEquipmentModal(equipmentDetail);

    if (equipmentToDiff.data) {
      addDiffToModal(equipmentDetail, equipmentData);
    }

    document.onkeydown = (event) => {
      if (event.key === 'd') {
        // event.preventDefault();
        console.log(`Added to quick diff: ${equipmentName}`);
        equipmentToDiff = {
          data: equipmentData,
          name: equipmentName,
        };
        equipmentDetail.querySelector('.diff-tooltip').textContent = isZH ? '已添加作为对比' : 'Added to quick diff';
      } else if (event.key === 'r') {
        // event.preventDefault();
        console.log(`Removed from quick diff: ${equipmentName}`);
        equipmentToDiff = {};
        equipmentDetail.querySelector('.diff-tooltip').textContent = isZH ? '已移除对比' : 'Removed from quick diff';
      }
    };

  }, 500)

})();