// ==UserScript== // @name Destiny2_Term_replace // @namespace your-namespace // @version 2.3 // @description 替换网页中出现的命运2术语 // @match *://*/* // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_xmlhttpRequest // @grant GM_registerMenuCommand // @connect 20xiji.github.io // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/524822/Destiny2_Term_replace.user.js // @updateURL https://update.greasyfork.icu/scripts/524822/Destiny2_Term_replace.meta.js // ==/UserScript== (function() { 'use strict'; const ITEM_LIST_URL = 'https://20xiji.github.io/Destiny-item-list/Destiny2_term.json'; let replacementHistory = []; let termMap = new Map(); let currentMode = 1; let dialogVisible = false; let dialogXOffset = 0; let dialogYOffset = 0; let isDragging = false; let posObjs = []; let hintDialogVisible = false; // 新增提示对话框显示状态 GM_addStyle(` #textReplacerDialog { position: fixed; top: 20px; right: 20px; background: #1a1a1a; padding: 15px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.25); z-index: 9999; width: 260px; font-family: Arial, sans-serif; color: #fff; display: none; overflow: visible; } #textReplacerDialog.dragging { cursor: grabbing; } #dialogHeader { cursor: grab; margin-bottom: 10px; } #modeButtons { display: grid; gap: 8px; margin: 12px 0; } .mode-btn { padding: 8px; border: none; border-radius: 4px; background: #333; color: #888; cursor: pointer; transition: all 0.2s; } .mode-btn.active { background: #4CAF50; color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.2); } #actionButtons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; } #actionButtons button { flex: 1; padding: 8px; border: none; border-radius: 4px; background: #4CAF50; color: white; cursor: pointer; min-width: 80px; } #actionButtons button:disabled { background: #666; cursor: not-allowed; } #termCount { font-size: 12px; color: #888; margin-left: 8px; } #btnClearCache { background: #f44336 !important; } .dialogButton { /* 统一关闭和提示按钮样式 */ position: absolute; top: 8px; width: 12px; height: 12px; border-radius: 50%; background-color: #ff6058; border: 1px solid #e0443e; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 0 rgba(0,0,0,.1); padding: 0; z-index: 10000; } .dialogButton:hover { background-color: #f0413a; border-color: #d02828; } .dialogButton::before { content: ''; display: block; width: 8px; height: 8px; border-radius: 50%; background-color: #fff; transform: scale(0.5); /* 调整小白点初始大小 */ opacity: 0; transition: opacity 0.2s ease, transform 0.2s ease; /* 添加transform过渡 */ } .dialogButton:hover::before { opacity: 1; transform: scale(1); } #dialogCloseButton { right: 8px; } #dialogHintButton { right: 30px; /* 提示按钮位置在关闭按钮左侧 */ background-color: #ffc107; /* 提示按钮颜色 */ border-color: #e0a300; } #dialogHintButton:hover { background-color: #f0b200; border-color: #d09500; } #dialogHintButton:hover::before { background-color: #333; /* 提示按钮悬停小白点颜色 */ } #hintDialog { position: fixed; top: 60px; /* 调整提示框的垂直位置 */ right: 20px; background: #333; color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.25); z-index: 10001; /* 确保提示框在最上层 */ width: 300px; /* 调整宽度 */ font-size: 14px; line-height: 1.6; display: none; /* 初始隐藏 */ } #hintDialog p { margin-bottom: 10px; } #hintDialog p:last-child { margin-bottom: 0; } `); const dialog = document.createElement('div'); dialog.id = 'textReplacerDialog'; const dialogHeader = document.createElement('div'); dialogHeader.id = 'dialogHeader'; dialogHeader.style.margin = '0 0 10px 0'; dialogHeader.style.fontSize = '16px'; dialogHeader.textContent = '文本替换工具 '; dialog.appendChild(dialogHeader); const termCountSpan = document.createElement('span'); termCountSpan.id = 'termCount'; termCountSpan.textContent = '(加载中...)'; dialogHeader.appendChild(termCountSpan); const modeButtonsDiv = document.createElement('div'); modeButtonsDiv.id = 'modeButtons'; const modeButton1 = document.createElement('button'); modeButton1.className = 'mode-btn'; modeButton1.dataset.mode = '1'; modeButton1.textContent = '中文模式'; modeButtonsDiv.appendChild(modeButton1); const modeButton2 = document.createElement('button'); modeButton2.className = 'mode-btn'; modeButton2.dataset.mode = '2'; modeButton2.textContent = '英文|中文'; modeButtonsDiv.appendChild(modeButton2); const modeButton3 = document.createElement('button'); modeButton3.className = 'mode-btn'; modeButton3.dataset.mode = '3'; modeButton3.textContent = '中文(英文)'; modeButtonsDiv.appendChild(modeButton3); const actionButtonsDiv = document.createElement('div'); actionButtonsDiv.id = 'actionButtons'; const btnApplyAll = document.createElement('button'); btnApplyAll.id = 'btnApplyAll'; btnApplyAll.textContent = '应用规则'; actionButtonsDiv.appendChild(btnApplyAll); const btnUndo = document.createElement('button'); btnUndo.id = 'btnUndo'; btnUndo.textContent = '撤销'; btnUndo.disabled = true; actionButtonsDiv.appendChild(btnUndo); const btnClearCache = document.createElement('button'); btnClearCache.id = 'btnClearCache'; btnClearCache.textContent = '清除缓存'; actionButtonsDiv.appendChild(btnClearCache); const closeButton = document.createElement('button'); closeButton.id = 'dialogCloseButton'; closeButton.className = 'dialogButton'; // 添加统一样式类 closeButton.addEventListener('click', toggleDialog); dialog.appendChild(closeButton); // 新增提示按钮 const hintButton = document.createElement('button'); hintButton.id = 'dialogHintButton'; hintButton.className = 'dialogButton'; // 添加统一样式类 hintButton.addEventListener('click', toggleHintDialog); // 添加点击事件监听器 dialog.appendChild(hintButton); // 创建提示对话框 const hintDialog = document.createElement('div'); hintDialog.id = 'hintDialog'; hintDialog.textContent = `
网页多层嵌套操作说明:
当处理采用多层嵌套结构的网页时,系统表现如下特点: