Skip to content

Add plugin 繁简转换 v1.0.0#203

Open
lecoix wants to merge 1 commit into
ZToolsCenter:mainfrom
lecoix:plugin/traditional-simplified-cn
Open

Add plugin 繁简转换 v1.0.0#203
lecoix wants to merge 1 commit into
ZToolsCenter:mainfrom
lecoix:plugin/traditional-simplified-cn

Conversation

@lecoix
Copy link
Copy Markdown
Contributor

@lecoix lecoix commented May 18, 2026

插件信息

  • 名称: 繁简转换
  • 插件ID: traditional-simplified-cn
  • 版本: 1.0.0
  • 描述: 剪贴板有文本时在启动器中推送入口;亦可手动打开(OpenCC)
  • 作者: lecoix
  • 类型: 新增

本次变更

  • Initial commit

截图 / 演示

clipboard_20260518_220335

自检清单

  • plugin.json 的 name / title / version / description / author 字段均已检查
  • 已移除调试日志、未使用文件、敏感信息(.env、token、密钥等)
  • 本次 PR 的 diff 仅涉及 plugins/traditional-simplified-cn/ 目录
  • 已在本地 ZTools 客户端实际加载并测试过此插件,主要功能正常
  • 同意以仓库声明的开源协议发布此插件

此 PR 由 ztools-plugin-cli 自动管理:每次 ztools publish 在分支上追加一个 commit,PR 链接保持不变。

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +39 to +40
applyVariant()
resultEl.value = window.nodeAPI.toSimplified(originalEl.value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

此处调用 applyVariant() 是多余的。applyVariant() 已经在初始化(第 29 行)以及 variantElchange 事件监听器(第 26 行)中被调用,确保了转换器状态始终与 UI 同步。移除此处的重复调用可以避免每次点击转换按钮时都重新初始化 OpenCC 转换器,从而提升性能。

Suggested change
applyVariant()
resultEl.value = window.nodeAPI.toSimplified(originalEl.value)
resultEl.value = window.nodeAPI.toSimplified(originalEl.value)

Comment on lines +46 to +47
applyVariant()
resultEl.value = window.nodeAPI.toTraditional(originalEl.value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

同上,此处无需重复调用 applyVariant()。转换器状态已通过事件监听器保持同步。

Suggested change
applyVariant()
resultEl.value = window.nodeAPI.toTraditional(originalEl.value)
resultEl.value = window.nodeAPI.toTraditional(originalEl.value)

Comment on lines +2 to +4
var originalEl = document.getElementById('inputOriginal')
var resultEl = document.getElementById('inputResult')
var variantEl = document.getElementById('variant')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

建议使用 const 代替 var 来声明这些 DOM 元素的引用。在现代 JavaScript 开发中,const 是声明不打算重新赋值的变量的首选方式,有助于提高代码的可读性和可维护性。

Suggested change
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')

Comment on lines +11 to +16
setTimeout(function () {
var h = document.body.scrollHeight
if (window.ztools && window.ztools.setExpendHeight) {
window.ztools.setExpendHeight(h + 48)
}
}, 80)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

使用 setTimeout 配合硬编码的延迟(80ms)来处理高度调整是一种比较脆弱的做法。这可能导致 UI 响应迟钝或在性能较差的设备上出现布局计算不准确的问题。此外,48 是一个魔术数字,建议将其定义为常量或通过计算得出。可以考虑使用 requestAnimationFrame 来确保在下一次重绘前执行高度调整,并将内部的 var h 改为 const h

@lecoix lecoix marked this pull request as ready for review May 18, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant