Add plugin 繁简转换 v1.0.0#203
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a Traditional and Simplified Chinese conversion plugin for ZTools, featuring a dual-pane UI and clipboard integration. The code review identifies several improvement opportunities in the frontend logic, specifically regarding the removal of redundant function calls, the adoption of modern variable declarations, and the implementation of more robust UI resizing logic to replace fragile timeouts and magic numbers.
| applyVariant() | ||
| resultEl.value = window.nodeAPI.toSimplified(originalEl.value) |
There was a problem hiding this comment.
此处调用 applyVariant() 是多余的。applyVariant() 已经在初始化(第 29 行)以及 variantEl 的 change 事件监听器(第 26 行)中被调用,确保了转换器状态始终与 UI 同步。移除此处的重复调用可以避免每次点击转换按钮时都重新初始化 OpenCC 转换器,从而提升性能。
| applyVariant() | |
| resultEl.value = window.nodeAPI.toSimplified(originalEl.value) | |
| resultEl.value = window.nodeAPI.toSimplified(originalEl.value) |
| applyVariant() | ||
| resultEl.value = window.nodeAPI.toTraditional(originalEl.value) |
| var originalEl = document.getElementById('inputOriginal') | ||
| var resultEl = document.getElementById('inputResult') | ||
| var variantEl = document.getElementById('variant') |
There was a problem hiding this comment.
建议使用 const 代替 var 来声明这些 DOM 元素的引用。在现代 JavaScript 开发中,const 是声明不打算重新赋值的变量的首选方式,有助于提高代码的可读性和可维护性。
| var originalEl = document.getElementById('inputOriginal') | |
| var resultEl = document.getElementById('inputResult') | |
| var variantEl = document.getElementById('variant') | |
| const originalEl = document.getElementById('inputOriginal') | |
| const resultEl = document.getElementById('inputResult') | |
| const variantEl = document.getElementById('variant') |
| setTimeout(function () { | ||
| var h = document.body.scrollHeight | ||
| if (window.ztools && window.ztools.setExpendHeight) { | ||
| window.ztools.setExpendHeight(h + 48) | ||
| } | ||
| }, 80) |
插件信息
本次变更
截图 / 演示
自检清单
plugins/traditional-simplified-cn/目录此 PR 由 ztools-plugin-cli 自动管理:每次
ztools publish在分支上追加一个 commit,PR 链接保持不变。