{"id":"625fee35-b2da-44d1-9903-0518d1ad522a","name":"正则调试工具-By AI助手","type":"window","description":"","matches":["*://*/*"],"code":"\n// 创建主容器\nconst regexTool = document.createElement('div');\nregexTool.id = 'regex-tool';\nregexTool.innerHTML = `\n<div style=\"font-family: Arial, sans-serif; max-width: 800px; margin: 20px auto; padding: 20px; border: 1px solid #ddd; border-radius: 8px; background: #f9f9f9;\">\n    <h2 style=\"color: #333; text-align: center;\">正则表达式调试工具</h2>\n    \n    <div style=\"margin-bottom: 15px;\">\n        <label style=\"display: block; margin-bottom: 5px; font-weight: bold;\">正则表达式:</label>\n        <input type=\"text\" id=\"regex-input\" placeholder=\"输入正则表达式，如: /\\\\w+/g\" \n               style=\"width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; font-family: monospace;\">\n    </div>\n    \n    <div style=\"margin-bottom: 15px;\">\n        <label style=\"display: block; margin-bottom: 5px; font-weight: bold;\">测试文本:</label>\n        <textarea id=\"test-text\" placeholder=\"输入要测试的文本\" \n                  style=\"width: 100%; height: 120px; padding: 8px; border: 1px solid #ccc; border-radius: 4px; font-family: monospace; resize: vertical;\"></textarea>\n    </div>\n    \n    <div style=\"margin-bottom: 15px;\">\n        <label style=\"display: block; margin-bottom: 5px; font-weight: bold;\">替换文本:</label>\n        <input type=\"text\" id=\"replace-input\" placeholder=\"输入替换文本（可选）\" \n               style=\"width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; font-family: monospace;\">\n    </div>\n    \n    <div style=\"margin-bottom: 15px;\">\n        <button id=\"test-btn\" style=\"padding: 8px 16px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; margin-right: 10px;\">测试匹配</button>\n        <button id=\"replace-btn\" style=\"padding: 8px 16px; background: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;\">执行替换</button>\n    </div>\n    \n    <div id=\"results\" style=\"background: white; padding: 15px; border-radius: 4px; border: 1px solid #ddd; min-height: 100px; font-family: monospace; white-space: pre-wrap;\"></div>\n    \n    <div id=\"error\" style=\"color: #dc3545; margin-top: 10px; display: none;\"></div>\n</div>\n`;\n\ndocument.body.appendChild(regexTool);\n\n// 工具函数：解析正则表达式\nfunction parseRegex(input) {\n    const match = input.match(/^\\/(.*)\\/([gimy]*)$/);\n    if (!match) {\n        throw new Error('正则表达式格式错误，请使用 /pattern/flags 格式');\n    }\n    \n    const pattern = match[1];\n    const flags = match[2];\n    \n    // 处理转义字符\n    const processedPattern = pattern.replace(/\\\\\\//g, '/');\n    \n    return new RegExp(processedPattern, flags);\n}\n\n// 高亮匹配文本\nfunction highlightMatches(text, regex) {\n    if (!text || !regex) return text;\n    \n    try {\n        const matches = [];\n        let match;\n        let lastIndex = 0;\n        \n        // 重置lastIndex以确保从开头开始匹配\n        regex = new RegExp(regex.source, regex.flags.includes('g') ? regex.flags : regex.flags + 'g');\n        \n        while ((match = regex.exec(text)) !== null) {\n            matches.push({\n                start: match.index,\n                end: match.index + match[0].length,\n                text: match[0]\n            });\n            \n            // 避免无限循环\n            if (match.index === regex.lastIndex) {\n                regex.lastIndex++;\n            }\n        }\n        \n        if (matches.length === 0) return text;\n        \n        let result = '';\n        let lastEnd = 0;\n        \n        matches.forEach((match, index) => {\n            // 添加匹配前的文本\n            result += text.slice(lastEnd, match.start);\n            // 添加高亮的匹配文本\n            result += `<span style=\"background-color: #ffeb3b; padding: 2px 0; border-radius: 2px;\">${match.text}</span>`;\n            lastEnd = match.end;\n        });\n        \n        // 添加最后一段文本\n        result += text.slice(lastEnd);\n        \n        return result;\n    } catch (error) {\n        throw error;\n    }\n}\n\n// 显示匹配结果\nfunction showMatches() {\n    const regexInput = document.getElementById('regex-input');\n    const testText = document.getElementById('test-text');\n    const results = document.getElementById('results');\n    const errorDiv = document.getElementById('error');\n    \n    errorDiv.style.display = 'none';\n    \n    try {\n        const regex = parseRegex(regexInput.value);\n        const text = testText.value;\n        \n        if (!text) {\n            results.innerHTML = '请输入测试文本';\n            return;\n        }\n        \n        const highlightedText = highlightMatches(text, regex);\n        \n        // 统计匹配信息\n        const globalRegex = new RegExp(regex.source, regex.flags.includes('g') ? regex.flags : regex.flags + 'g');\n        const matches = [...text.matchAll(globalRegex)];\n        \n        let resultHTML = `<div style=\"margin-bottom: 10px; color: #666;\">`;\n        resultHTML += `匹配结果: ${matches.length} 处匹配<br>`;\n        resultHTML += `正则表达式: ${regex.toString()}<br>`;\n        resultHTML += `标志: ${regex.flags || '无'}`;\n        resultHTML += `</div>`;\n        resultHTML += `<div style=\"border-top: 1px solid #eee; padding-top: 10px;\">`;\n        resultHTML += `<strong>高亮结果:</strong><br>`;\n        resultHTML += highlightedText;\n        resultHTML += `</div>`;\n        \n        if (matches.length > 0) {\n            resultHTML += `<div style=\"border-top: 1px solid #eee; padding-top: 10px; margin-top: 10px;\">`;\n            resultHTML += `<strong>详细匹配信息:</strong><br>`;\n            matches.forEach((match, index) => {\n                resultHTML += `匹配 ${index + 1}: \"${match[0]}\" (位置: ${match.index}-${match.index + match[0].length})<br>`;\n                if (match.length > 1) {\n                    match.slice(1).forEach((group, groupIndex) => {\n                        if (group !== undefined) {\n                            resultHTML += `  分组 ${groupIndex + 1}: \"${group}\"<br>`;\n                        }\n                    });\n                }\n            });\n            resultHTML += `</div>`;\n        }\n        \n        results.innerHTML = resultHTML;\n        \n    } catch (error) {\n        errorDiv.style.display = 'block';\n        errorDiv.textContent = `错误: ${error.message}`;\n        results.innerHTML = '';\n    }\n}\n\n// 执行替换\nfunction performReplace() {\n    const regexInput = document.getElementById('regex-input');\n    const testText = document.getElementById('test-text');\n    const replaceInput = document.getElementById('replace-input');\n    const results = document.getElementById('results');\n    const errorDiv = document.getElementById('error');\n    \n    errorDiv.style.display = 'none';\n    \n    try {\n        const regex = parseRegex(regexInput.value);\n        const text = testText.value;\n        const replacement = replaceInput.value || '';\n        \n        if (!text) {\n            results.innerHTML = '请输入测试文本';\n            return;\n        }\n        \n        const replacedText = text.replace(regex, replacement);\n        \n        let resultHTML = `<div style=\"margin-bottom: 10px; color: #666;\">`;\n        resultHTML += `替换前字符数: ${text.length}<br>`;\n        resultHTML += `替换后字符数: ${replacedText.length}<br>`;\n        resultHTML += `正则表达式: ${regex.toString()}<br>`;\n        resultHTML += `替换文本: \"${replacement}\"`;\n        resultHTML += `</div>`;\n        resultHTML += `<div style=\"border-top: 1px solid #eee; padding-top: 10px;\">`;\n        resultHTML += `<strong>替换结果:</strong><br>`;\n        resultHTML += `<div style=\"background: #f8f9fa; padding: 10px; border-radius: 4px; border: 1px solid #e9ecef;\">${replacedText}</div>`;\n        resultHTML += `</div>`;\n        \n        results.innerHTML = resultHTML;\n        \n    } catch (error) {\n        errorDiv.style.display = 'block';\n        errorDiv.textContent = `错误: ${error.message}`;\n        results.innerHTML = '';\n    }\n}\n\n// 添加事件监听器\ndocument.getElementById('test-btn').addEventListener('click', showMatches);\ndocument.getElementById('replace-btn').addEventListener('click', performReplace);\n\n// 添加实时预览（可选）\nlet previewTimeout;\ndocument.getElementById('regex-input').addEventListener('input', function() {\n    clearTimeout(previewTimeout);\n    previewTimeout = setTimeout(showMatches, 500);\n});\n\ndocument.getElementById('test-text').addEventListener('input', function() {\n    clearTimeout(previewTimeout);\n    previewTimeout = setTimeout(showMatches, 500);\n});\n\n// 添加示例数据\ndocument.getElementById('regex-input').value = '/\\\\w+/g';\ndocument.getElementById('test-text').value = 'Hello World! This is a test text with 123 numbers.';\ndocument.getElementById('replace-input').value = 'WORD';\n\n// 初始显示结果\nsetTimeout(showMatches, 100);","installTime":1736387375025,"author":"script dog","version":"1.0.0","enabled":true,"source":"{\"blocks\":{\"languageVersion\":0,\"blocks\":[{\"type\":\"set_element\",\"id\":\"xe[%aq`ZjIPVDDBE(K!L\",\"x\":562,\"y\":263,\"inputs\":{\"element\":{\"block\":{\"type\":\"element_body\",\"id\":\"x2]%%+yJsdBNB.7:z;PL\"}},\"attribute\":{\"block\":{\"type\":\"element_attribute\",\"id\":\"]-v6:J:UtuYbo|bUXF()\",\"fields\":{\"value\":\"style\"}}},\"value\":{\"block\":{\"type\":\"style_size\",\"id\":\"OoQ)[`687,*Y%hQ0Z@vL\",\"inputs\":{\"width\":{\"block\":{\"type\":\"dom_size\",\"id\":\"NclkOFbK:(#DV5(hucp=\",\"fields\":{\"value\":100,\"unit\":\"%\"}}},\"height\":{\"block\":{\"type\":\"dom_size\",\"id\":\"PJrQNF2fb9MDPLB5X~BI\",\"fields\":{\"value\":100,\"unit\":\"vh\"}}}}}}},\"next\":{\"block\":{\"type\":\"element_event\",\"id\":\"VVn%uQ(x$I_dTwfLpJP2\",\"fields\":{\"event\":\"contextmenu\",\"args\":{\"id\":\"4}C1*%Y}Wo-GBa,Af@:L\"}},\"inputs\":{\"element\":{\"block\":{\"type\":\"element_body\",\"id\":\";)=eScO{,SRKV+p|Dpk/\"}},\"body0\":{\"block\":{\"type\":\"func_call\",\"id\":\"L#i]3?*2kH_OI,taoGRa\",\"inputs\":{\"func\":{\"block\":{\"type\":\"element_event_object\",\"id\":\"zRJ,=6M2B{95,J[,D?KE\",\"fields\":{\"key\":\"preventDefault\"},\"inputs\":{\"value\":{\"block\":{\"type\":\"variables\",\"id\":\"p+[t{qqxa6*%1MQ8Gz|3\",\"fields\":{\"name\":{\"id\":\"%l=2,T9gi+!mnVB-JM:N\"}}}}}}}}}}},\"next\":{\"block\":{\"type\":\"new_variables_assign\",\"id\":\"]|+2Pf+]H(q92Au4/!8l\",\"fields\":{\"name\":{\"id\":\"0WLG]xF]Iw7h0[CJsgRj\"}},\"inputs\":{\"value\":{\"block\":{\"type\":\"load_image\",\"id\":\"ohBSG(KmYB_`7j{K?HAl\",\"inputs\":{\"url\":{\"block\":{\"type\":\"text\",\"id\":\"sMuaf},$PSWJH^:i)_@O\",\"fields\":{\"TEXT\":\"https://www.gate.io/tgwallet/_next/image?url=https%3A%2F%2Fweb3-icon.s3.ap-northeast-1.amazonaws.com%2F1%2F-.png&w=32&q=75\"}}}}}}},\"next\":{\"block\":{\"type\":\"console\",\"id\":\"[|/kGLXRDC=qj@r7gkY+\",\"fields\":{\"type\":\"log\"},\"inputs\":{\"value\":{\"block\":{\"type\":\"func_await\",\"id\":\"x4!v?,o#bZ4wj/c)/upd\",\"inputs\":{\"func\":{\"block\":{\"type\":\"variables\",\"id\":\"Bw]pSQ6jk{isa|LJ7}S}\",\"fields\":{\"name\":{\"id\":\"kXf6lv;xS%m=IujCz)dJ\"}}}}}}}}}}}}}}}]},\"variables\":[{\"name\":\"i\",\"id\":\"4}C1*%Y}Wo-GBa,Af@:L\"},{\"name\":\"j\",\"id\":\"%l=2,T9gi+!mnVB-JM:N\"},{\"name\":\"k\",\"id\":\"0WLG]xF]Iw7h0[CJsgRj\"},{\"name\":\"m\",\"id\":\"kXf6lv;xS%m=IujCz)dJ\"}]}","runAt":"document_idle","useGM":false,"useDog":true,"templates":{},"window":{"icon":"","width":"440","height":"495","left":"1","top":"0"},"updateTime":1758680255716,"size":2445,"loading":false,"programmingType":"text"}