卡厄思
梦
境
菜单
首页
回到首页
WIKI工具
全站样式
全站JS
修改导航栏
测试
沙盒
可视化管理器
战斗员管理器
卡牌管理器
伙伴管理器
装备管理器
词典管理器
图鉴
战斗员
伙伴
装备
怪物卡牌
中立卡牌
词典
小工具
配队模拟器
节奏榜生成器
搜索
链入页面
相关更改
特殊页面
页面信息
最近更改
登录
MediaWiki
查看“︁Gadget-CopyTextTool.js”︁的源代码
←
MediaWiki:Gadget-CopyTextTool.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
// 文本复制工具 (function() { 'use strict'; // ===== 自定义配置区域 ===== const BUTTON_CONFIG = { '蓝色': '{{文本|蓝|', '绿色': '{{文本|绿|', '蓝色下划线': '{{文本|蓝|下划线|', '绿色描边': '{{描边|绿|', '词典': '{{词典|' }; // ======================== let toolElement = null; let isPinned = true; let isDragging = false; let currentX; let currentY; let initialX; let initialY; let xOffset = 0; let yOffset = 0; // 创建工具面板 function createToolPanel() { const tool = document.createElement('div'); tool.id = 'copy-text-tool'; tool.innerHTML = ` <div class="tool-header" id="tool-header"> <span class="tool-title">📋 文本复制工具</span> <div class="tool-controls"> <button class="tool-btn" id="minimize-btn" title="最小化">−</button> <button class="tool-btn" id="close-btn" title="关闭">×</button> </div> </div> <div class="tool-body"> <div class="pin-control"> <input type="checkbox" id="pin-checkbox" ${isPinned ? 'checked' : ''}> <label for="pin-checkbox">窗口置顶</label> </div> <div id="button-container"></div> <div class="tool-status" id="tool-status">准备就绪</div> </div> `; // 添加按钮 const buttonContainer = tool.querySelector('#button-container'); for (const [name, text] of Object.entries(BUTTON_CONFIG)) { const button = document.createElement('button'); button.className = 'copy-button'; button.textContent = name; button.onclick = () => copyText(text, name); buttonContainer.appendChild(button); } document.body.appendChild(tool); return tool; } // 复制文本到剪贴板 function copyText(text, buttonName) { // 使用现代剪贴板API if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(text).then(() => { showStatus(`✓ 已复制: ${buttonName}`, true); }).catch(() => { fallbackCopy(text, buttonName); }); } else { fallbackCopy(text, buttonName); } } // 备用复制方法 function fallbackCopy(text, buttonName) { const textarea = document.createElement('textarea'); textarea.value = text; textarea.style.position = 'fixed'; textarea.style.opacity = '0'; document.body.appendChild(textarea); textarea.select(); try { document.execCommand('copy'); showStatus(`✓ 已复制: ${buttonName}`, true); } catch (err) { showStatus('❌ 复制失败', false); } document.body.removeChild(textarea); } // 显示状态 function showStatus(message, success) { const status = document.getElementById('tool-status'); status.textContent = message; status.className = 'tool-status' + (success ? ' success' : ''); } // 拖拽功能 function dragStart(e) { if (e.type === "touchstart") { initialX = e.touches[0].clientX - xOffset; initialY = e.touches[0].clientY - yOffset; } else { initialX = e.clientX - xOffset; initialY = e.clientY - yOffset; } if (e.target.id === "tool-header" || e.target.className === "tool-title") { isDragging = true; } } function drag(e) { if (isDragging) { e.preventDefault(); if (e.type === "touchmove") { currentX = e.touches[0].clientX - initialX; currentY = e.touches[0].clientY - initialY; } else { currentX = e.clientX - initialX; currentY = e.clientY - initialY; } xOffset = currentX; yOffset = currentY; setTranslate(currentX, currentY, toolElement); } } function dragEnd(e) { initialX = currentX; initialY = currentY; isDragging = false; } function setTranslate(xPos, yPos, el) { el.style.transform = `translate3d(${xPos}px, ${yPos}px, 0)`; } // 初始化 function init() { // 添加菜单项 mw.util.addPortletLink( 'p-tb', '#', '📋 文本复制工具', 't-copy-text-tool', '打开文本复制工具', null, '#t-permalink' ); // 点击菜单项显示工具 document.getElementById('t-copy-text-tool').addEventListener('click', function(e) { e.preventDefault(); if (!toolElement) { toolElement = createToolPanel(); // 绑定事件 const header = document.getElementById('tool-header'); header.addEventListener('mousedown', dragStart); document.addEventListener('mousemove', drag); document.addEventListener('mouseup', dragEnd); // 最小化按钮 document.getElementById('minimize-btn').onclick = () => { toolElement.classList.toggle('minimized'); }; // 关闭按钮 document.getElementById('close-btn').onclick = () => { toolElement.remove(); toolElement = null; }; // 置顶开关 document.getElementById('pin-checkbox').onchange = (e) => { isPinned = e.target.checked; toolElement.style.position = isPinned ? 'fixed' : 'absolute'; }; } else { toolElement.style.display = toolElement.style.display === 'none' ? 'block' : 'none'; } }); } // 页面加载完成后初始化 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();
该页面使用的模板:
模板:描边
(
查看源代码
)
模板:描边/颜色
(
查看源代码
)
模板:文本
(
查看源代码
)
模板:词典
(
查看源代码
)
模块:文本
(
查看源代码
)
模块:词典
(
查看源代码
)
模块:词典/data
(
查看源代码
)
返回
MediaWiki:Gadget-CopyTextTool.js
。