Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ updates:
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 3
groups:
github-actions:
patterns:
- "*"

- package-ecosystem: "npm"
directory: "/vscode-extension"
schedule:
interval: "weekly"
146 changes: 146 additions & 0 deletions .github/workflows/build-vscode-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Build Extension

on:
# 定时触发:每5天自动运行一次
schedule:
- cron: '0 0 */5 * *'
Comment thread
th-dd marked this conversation as resolved.

# 代码推送触发:当 vscode-extension 目录有变更时自动构建
push:
paths:
- 'vscode-extension/**'

# PR 触发:当 PR 涉及 vscode-extension 目录变更时构建
pull_request:
paths:
- 'vscode-extension/**'

# 手动触发:允许在 Actions 页面手动点击运行
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
outputs:
expires_at: ${{ steps.calc-expiry.outputs.expires_at }}
artifact_name: ${{ steps.package.outputs.artifact_name }}
vsix_path: ${{ steps.package.outputs.vsix_path }}

steps:
- name: 检出代码
uses: actions/checkout@v4

- name: 设置 Node.js 环境
uses: actions/setup-node@v4
with:
node-version: '24'
Comment thread
th-dd marked this conversation as resolved.
cache: 'npm'
cache-dependency-path: 'vscode-extension/package-lock.json'

- name: 进入插件目录并安装依赖
run: |
cd vscode-extension
npm ci

- name: 打包 VSIX
id: package
run: |
cd vscode-extension
# 清理旧的 VSIX 文件,避免上传历史构件
rm -f ./*.vsix
# 使用 package.json 中的 name 和 version 生成确定性的文件名
PKG_NAME=$(node -p "require('./package.json').name")
PKG_VERSION=$(node -p "require('./package.json').version")
VSIX_FILE="${PKG_NAME}-${PKG_VERSION}.vsix"
# 以指定的文件名打包 VSIX,避免依赖 ls 和通配符
npx @vscode/vsce package -o "$VSIX_FILE"
echo "artifact_name=$VSIX_FILE" >> $GITHUB_OUTPUT
echo "vsix_path=vscode-extension/$VSIX_FILE" >> $GITHUB_OUTPUT
Comment thread
sourcery-ai[bot] marked this conversation as resolved.

- name: 计算过期时间
id: calc-expiry
run: |
EXPIRY_DATE=$(date -u -d "+5 days" '+%Y-%m-%d %H:%M UTC')
echo "expires_at=$EXPIRY_DATE" >> $GITHUB_OUTPUT

- name: 上传构件
uses: actions/upload-artifact@v7
with:
name: github-chinese-extension
path: ${{ steps.package.outputs.vsix_path }}
retention-days: 5
archive: false
Comment thread
sourcery-ai[bot] marked this conversation as resolved.

- name: 评论 PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const artifactName = '${{ steps.package.outputs.artifact_name }}';
const expiresAt = '${{ steps.calc-expiry.outputs.expires_at }}';
const runId = context.runId;
const repo = context.repo;

const artifactUrl = `https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}/artifacts`;

const comment = `
## 📦 GitHub 中文化扩展构建完成

| 项目 | 详情 |
| :--- | :--- |
| **构建状态** | ✅ 成功 |
| **产物名称** | \`${artifactName}\` |
| **预计过期时间** | **${expiresAt}** |
| **下载链接** | [点击下载构件](${artifactUrl}) |

> [!WARNING]
> Actions 工作流工件仅保存5天,到期将永久删除

---
**工作流运行详情**:${process.env.GITHUB_SERVER_URL}/${repo.owner}/${repo.repo}/actions/runs/${runId}
`;

const { data: comments } = await github.rest.issues.listComments({
owner: repo.owner,
repo: repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('GitHub 中文化扩展构建完成')
);

if (botComment) {
await github.rest.issues.updateComment({
owner: repo.owner,
repo: repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner: repo.owner,
repo: repo.repo,
issue_number: context.issue.number,
body: comment
});
}

- name: 生成运行摘要
if: always()
run: |
cat >> $GITHUB_STEP_SUMMARY << 'EOF'
## 📦 GitHub 中文化扩展构建报告

| 项目 | 详情 |
| :--- | :--- |
| **构建状态** | ${{ job.status == 'success' && '✅ 成功' || '❌ 失败' }} |
| **触发方式** | ${{ github.event_name }} |
| **产物名称** | `${{ steps.package.outputs.artifact_name }}` |
| **预计过期时间** | **${{ steps.calc-expiry.outputs.expires_at }}** |
EOF
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ Desktop.ini
main(local).js
# VS Code extension package
*.vsix

# logs
*.log
38 changes: 0 additions & 38 deletions main(vscode).user.js

This file was deleted.

4 changes: 2 additions & 2 deletions main.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
// @description 中文化 GitHub 界面的部分菜单及内容。原作者为楼教主(http://www.52cik.com/)。
// @copyright 2021, 沙漠之子 (https://maboloshi.github.io/Blog)
// @icon https://github.githubassets.com/pinned-octocat.svg
// @version 1.9.4.4-2026-07-26
// @version 1.9.4.4-2026-07-29
// @author 沙漠之子
// @license GPL-3.0
// @match https://github.com/*
// @match https://skills.github.com/*
// @match https://gist.github.com/*
// @match https://education.github.com/*
// @match https://www.githubstatus.com/*
// @require https://raw.githubusercontent.com/maboloshi/github-chinese/gh-pages/locals.js?v1.9.4.4-2026-07-26
// @require https://raw.githubusercontent.com/maboloshi/github-chinese/gh-pages/locals.js?v1.9.4.4-2026-07-29
// @run-at document-start
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
Expand Down
19 changes: 10 additions & 9 deletions test/issue-702-regression.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ const expectedReactNavLabels = {
"Repositories": "儲存庫",
"Code": "程式碼",
"Issues": "議題",
"Pull requests": "拉取請求",
"Pull requests": "合併請求",
"Discussions": "討論",
"Actions": "操作",
"Projects": "專案",
"Wiki": "Wiki",
"Security": "安全",
"Security and quality": "安全和品質",
"Insights": "洞察",
"Settings": "設定",
"Packages": "軟體包",
"Releases": "發行版",
"Security and quality": "安全和質量",
"Insights": "分析",
"Settings": "設置",
"Packages": "軟件包",
"Releases": "發行版本",
"Stars": "星號",
"Agents": "智能體",
"Agents": "AI 代理",
"Models": "模型",
"Set status": "狀態設置",
"Profile": "個人資料",
Expand All @@ -186,7 +186,7 @@ const expectedReactNavLabels = {
"Sign out": "退出",
"Free": "免費",
"Type / to search": "輸入 / 搜尋",
"Search code, repositories, users, issues, pull requests...": "搜尋程式碼、儲存庫、使用者、議題、拉取請求...",
"Search code, repositories, users, issues, pull requests...": "搜尋程式碼、儲存庫、用戶、議題、合併請求...",
"Search": "搜尋",
"Clear": "清除",
"Search syntax tips": "搜尋語法提示",
Expand Down Expand Up @@ -256,7 +256,8 @@ function loadRuntimeFunction(fileName, functionName, document) {
const filePath = path.join(__dirname, '..', fileName);
const source = fs.readFileSync(filePath, 'utf8');
const start = source.indexOf(` function ${functionName}(`);
const end = source.indexOf('\n\n function ', start + 1);
const nextFunction = source.slice(start + 1).search(/\r?\n\r?\n function /);
Comment thread
th-dd marked this conversation as resolved.
const end = nextFunction === -1 ? -1 : start + 1 + nextFunction;
assert.notEqual(start, -1, `${functionName} should exist in ${fileName}`);
assert.notEqual(end, -1, `${functionName} should be followed by another runtime function`);

Expand Down
77 changes: 63 additions & 14 deletions vscode-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
> 该依赖扩展的 GitHub 源码仓库已被作者删除(404),市场列表仍存在但扩展不再维护。功能在当前版本中正常可用,但未来可能因 VS Code 更新而失效。

> [!NOTE]
> 本扩展尚未上架 [VS Code 市场](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_find-and-install-an-extension),需通过[源码构建](#从本仓库源码构建)或下载 VSIX 安装。上架后从市场安装时会自动安装 Integrated Browser Extensions。
> 本扩展尚未上架 [VS Code 市场](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_find-and-install-an-extension),需通过[源码构建](#方案二从源码构建)或下载 VSIX 安装。上架后从市场安装时会自动安装 Integrated Browser Extensions。

### 添加启动参数

Expand All @@ -23,32 +23,81 @@ VS Code 必须带 `--enable-proposed-api boylett.integrated-browser-extensions`
<details>
<summary>带参数启动 VS Code 的方式</summary>

- 打开[运行对话框](https://learn.microsoft.com/windows/advanced-settings/modern-run),录入:
- 打开[运行对话框](https://learn.microsoft.com/windows/advanced-settings/modern-run),输入:

```cmd
"%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" --enable-proposed-api boylett.integrated-browser-extensions
```

- 或修改[“开始”菜单](https://www.microsoft.com/zh-cn/windows/tips/start-menu)的 VS Code 快捷方式,在 `目标` 字段末尾追加 [COMMAND_LINE_ARGUMENTS](https://learn.microsoft.com/openspecs/windows_protocols/ms-shllink/17b69472-0f34-4bcf-b290-eccdb8de224b):

```cmd
--enable-proposed-api boylett.integrated-browser-extensions
```

然后从“开始”菜单启动

</details>

## 从本仓库源码构建
## 安装方式

### 方案一:从 GitHub Actions 下载(推荐)

> 该方案需要登录 GitHub 账号,若你没有账号,请使用 [方案二](#方案二从源码构建)

1. 打开本仓库的 [Actions](https://github.com/maboloshi/github-chinese/actions/workflows/build-vscode-extension) 页面

2. 选择最近一次成功运行的 workflow

3. 滚动到页面底部,在 **Artifacts** 区域下载 `github-chinese-extension.vsix`

4. 在 VS Code 中按 `Ctrl+Shift+P` 打开命令面板

5. 输入 `Extensions: Install from VSIX...` 并选择刚才下载的 `.vsix` 文件

6. 安装完成后,在 VS Code 集成浏览器中刷新 GitHub 页面即可生效

### 方案二:从源码构建

#### 环境要求

- [Git](https://git-scm.cn/install) (可选,用于克隆仓库,若不打算安装 Git ,请自行将仓库下载至本地)

- [NodeJS](https://nodejs.org)
Comment thread
th-dd marked this conversation as resolved.

#### 构建步骤

在 PowerShell 中执行以下代码:

```shell
git clone https://github.com/maboloshi/github-chinese.git # 克隆仓库

# 若你的网络环境无法访问 GitHub 克隆仓库,请自行寻找加速器等解决

cd github-chinese/vscode-extension # 进入插件目录

npm install # 安装依赖

# 若你的网络环境缓慢,请使用这行命令:

# npm install --registry=https://registry.npmmirror.com

npx @vscode/vsce package # 打包插件
```

构建完成后,按方案一的第 4-5 步安装生成的 `.vsix` 文件。

## 常见问题

### 为什么打开 GitHub 页面没有汉化?

1. [克隆仓库](https://docs.github.com/zh/repositories/creating-and-managing-repositories/cloning-a-repository)
1. [在 VS Code 中打开该文件夹](https://code.visualstudio.com/docs/editor/workspaces#_folder-projects)
1. [打开终端](https://code.visualstudio.com/docs/terminal/getting-started#_run-your-first-command-in-the-terminal),执行:
```powershell
cd vscode-extension
npm install
npx @vscode/vsce package
```
1. [从 VSIX 安装](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_install-from-a-vsix)
请检查以下几点:

> [!TIP]
> 推荐从[发行版](https://github.com/maboloshi/github-chinese/releases)直接下载 `.vsix`(如有)。
1. **确认已安装依赖扩展**:Integrated Browser Extensions 必须已安装并启用
2. **确认启动参数正确**:VS Code 必须带 `--enable-proposed-api boylett.integrated-browser-extensions` 参数启动
3. **确认扩展已启用**:在扩展面板中确认 `GitHub 中文化` 扩展已启用
4. **刷新页面**:在 VS Code 的集成浏览器中按 `Ctrl+R` 或 `F5` 刷新页面
5. **重启 VS Code**:尝试完全退出并重新启动 VS Code

## 调试

Expand Down
2 changes: 1 addition & 1 deletion vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "github-chinese",
"displayName": "GitHub 中文化",
"description": "一键安装 GitHub 中文化脚本到 VS Code 集成浏览器",
"version": "1.0.0",
"version": "1.0.1",
"author": "PtJade-Ceramic",
"publisher": "PtJade-Ceramic",
"license": "GPL-3.0",
Expand Down
Loading