Перейти к основному содержимому
claw
am
tools
Инструменты
Документы
Daoark
EN
Главная
Главная
/
Текстовые инструменты
›
Главная
manifest.json
= 0xFF01 && c <= 0xFF5E) out += String.fromCharCode(c - 0xFEE0); else out += s[i]; } return out; } function toFullWidth(s) { var out = ''; for (var i = 0; i < s.length; i++) { var c = s.charCodeAt(i); if (c === 0x20) out += '\u3000'; else if (c >= 0x21 && c <= 0x7E) out += String.fromCharCode(c + 0xFEE0); else out += s[i]; } return out; } function doProcess() { try { var textA = getVal('text-a'); if (!textA) { showError('请输入文本'); return; } var op = getVal('op'); var out; if (op === 'to-half') out = toHalfWidth(textA); else if (op === 'to-full') out = toFullWidth(textA); else if (op === 'normalize') { if (typeof textA.normalize !== 'function') { showError('浏览器不支持 String.normalize'); return; } out = textA.normalize('NFKC'); } else if (op === 'decompose') { if (typeof textA.normalize !== 'function') { showError('浏览器不支持 String.normalize'); return; } out = textA.normalize('NFKD'); } else { showError('未知操作'); return; } showResult(out, '操作: ' + op + ',输入 ' + textA.length + ' 字符,输出 ' + out.length + ' 字符'); } catch (e) { showError('处理失败: ' + (e.message || e)); } } $('btn-main').addEventListener('click', function(e) { e.preventDefault(); doProcess(); }); $('btn-clear').addEventListener('click', function() { var inputs = document.querySelectorAll('input,textarea,select'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].tagName === 'SELECT') inputs[i].selectedIndex = 0; else inputs[i].value = ''; } var ra = $('result-area'); ra.hidden = true; ra.style.display = 'none'; var em = $('error-msg'); em.hidden = true; em.style.display = 'none'; }); })();