您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Keyboard shortcuts (1-9) to add tags
// ==UserScript== // @name map-making.app Tags Keyboard Shortcuts // @version 0.1 // @description Keyboard shortcuts (1-9) to add tags // @author @teqoa9 // @match https://map-making.app/maps/* // @grant none // @license MIT // @namespace https://gf.qytechs.cn/en/users/1375871-teqoa1 // @downloadURL // @updateURL // ==/UserScript== /* To use: * Each tag (1-9) receives a number (written in [square brackets] before the tag name in the 'click to add' view); * Press a number on your keyboard to assign the corresponding tag to the loc; * Press enter to save the loc, as you normally would. */ (function() { 'use strict'; let tagMappings = new Map(); // tagName -> number let numberMappings = new Map(); // number -> button element let originalTagTexts = new Map(); // button -> original text function assignNumbersToTags() { const tagList = document.querySelector('ol.tag-list'); if (!tagList) return; const tagItems = tagList.querySelectorAll('li.tag.is-small.has-button'); numberMappings.clear(); tagItems.forEach((li, index) => { const textSpan = li.querySelector('span.tag__text'); const button = li.querySelector('button.tag__button.tag__button--add'); if (!textSpan || !button) return; let originalText; if (originalTagTexts.has(button)) { originalText = originalTagTexts.get(button); } else { originalText = textSpan.textContent; originalTagTexts.set(button, originalText); } let assignedNumber; if (tagMappings.has(originalText)) { assignedNumber = tagMappings.get(originalText); } else { assignedNumber = index + 1; while (Array.from(tagMappings.values()).includes(assignedNumber) && assignedNumber <= 9) { assignedNumber++; } if (assignedNumber <= 9) { tagMappings.set(originalText, assignedNumber); } } if (assignedNumber <= 9) { textSpan.textContent = `[${assignedNumber}] ${originalText}`; numberMappings.set(assignedNumber, button); } }); } function handleKeyPress(event) { const keyNum = parseInt(event.key); if (isNaN(keyNum) || keyNum < 1 || keyNum > 9) return; if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA' || event.target.isContentEditable) { return; } const button = numberMappings.get(keyNum); if (button && button.isConnected) { event.preventDefault(); button.click(); } } function observeTagList() { const observer = new MutationObserver((mutations) => { let shouldProcess = false; mutations.forEach((mutation) => { if (mutation.type === 'childList') { mutation.addedNodes.forEach((node) => { if (node.nodeType === Node.ELEMENT_NODE) { if (node.classList && node.classList.contains('tag-list')) { shouldProcess = true; } else if (node.querySelector && node.querySelector('ol.tag-list')) { shouldProcess = true; } } }); } if (mutation.target.closest && mutation.target.closest('ol.tag-list')) { shouldProcess = true; } }); if (shouldProcess) { setTimeout(assignNumbersToTags, 10); } }); observer.observe(document.body, { childList: true, subtree: true }); setTimeout(assignNumbersToTags, 100); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', observeTagList); } else { observeTagList(); } document.addEventListener('keydown', handleKeyPress); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址