`pr-commit-lines-changed` - Restore feature by fregante · Pull Request #9486 · refined-github/refined-github · GitHub
Skip to content

pr-commit-lines-changed - Restore feature#9486

Merged
fregante merged 6 commits into
mainfrom
commit-lines
May 17, 2026
Merged

pr-commit-lines-changed - Restore feature#9486
fregante merged 6 commits into
mainfrom
commit-lines

Conversation

@fregante

@fregante fregante commented May 16, 2026

Copy link
Copy Markdown
Member

@fregante fregante added the bug label May 16, 2026
Comment on lines +32 to +33

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not perfect but better than all gray


async function init(): Promise<void> {
function repeatItems(count: number, Item: () => React.JSX.Element): React.JSX.Element[] {
return Array.from({length: count}).map(() => <Item style={{borderRadius: '2px'}}/>);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

GitHub is using a new style with custom classes. This gets it closer, but the red is not striped like theirs. Oh well

import {tooltipped} from '../helpers/tooltip.js';
import GetCommitChanges from './pr-commit-lines-changed.gql';
import observe from '../helpers/selector-observer.js';
import {expectToken} from '../github-helpers/github-token.js';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Uh, not sure why the lack of expectToken was not causing the tests to fail before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh it's because it requires observe too 🤔

&& /observe\(|delegate\(/.test(String(file.contents()))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh it's because line api.v4 failures within init are already caught. expectToken was required specifically because api.v4 (and therefore their already-existing internal expectToken) was called too late to be caught.

Comment thread source/features/pr-commit-lines-changed.tsx Outdated
Co-authored-by: Grigory <techuila.sunset@gmail.com>
Comment thread source/features/pr-commit-lines-changed.tsx Outdated
Comment on lines +13 to +26

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🙌

Image

@fregante fregante merged commit 01b1c93 into main May 17, 2026
10 checks passed
@fregante fregante deleted the commit-lines branch May 17, 2026 18:33
DCjanus added a commit to DCjanus/userscripts that referenced this pull request May 22, 2026
## Why

- 在 GitHub PR 文件较多时,左侧文件树缺少每个文件的增删行数,不方便优先定位改动较大的文件。
- 希望像 GitLab MR 一样,在文件树里直接区分文件是否已标记为 Viewed。

## What

- 新增 `GitHubPrFileTreeReviewStats.user.js`,在 GitHub PR Files/Changes
页的文件树中注入每个文件的 `+N -N`。
- 通过当前页面 DOM 读取 diff header 和 Viewed 按钮状态,不调用 GitHub API,避免 rate limit
和额外认证问题。
- 未 Viewed 文件在文件树中加粗,已 Viewed 文件恢复正常字重。
- 在 README 脚本列表中加入新脚本入口。

## Validation

- `node --check scripts/GitHubPrFileTreeReviewStats.user.js`
- `git diff --check`
- 使用 Chrome 登录态在 `refined-github/refined-github#9486` 的 PR Files 页面确认
DOM 可匹配到文件树、增删行数和 Viewed 状态。
DCjanus added a commit to DCjanus/userscripts that referenced this pull request May 22, 2026
## Why

- Viewed 按钮保存是异步的,点击后文件树状态需要在不刷新页面的情况下重新同步。
- GitHub PR 的局部刷新可能只更新 diff header 文本或重挂载部分 DOM,文件树里的增删行数也需要跟着更新。

## What

- 改成事件驱动同步:DOM mutation、Viewed 控件事件、GitHub 自身 `fetch` / `XMLHttpRequest`
完成后都会触发同步。
- Viewed 点击时只对当前文件做乐观同步,后续由 DOM/network 事件回读页面真实状态校正。
- 新增 `@run-at document-start`,尽早安装网络完成 hook,覆盖 PR Files 的局部刷新和新 commit
更新。
- 保持 userscript version 不变,不用版本号承载这个 draft PR 的内部迭代。
- 兼容旧版 GitHub file tree 中没有 `file-tree-row` li 的链接结构。

## Validation

- `node --check scripts/GitHubPrFileTreeReviewStats.user.js`
- `git diff --check`
- 使用本机 Chrome headless 加载 `refined-github/refined-github#9486`,注入脚本后确认 3
个文件统计可显示。
- 模拟 diff header 文本变化后触发页面 fetch 完成信号,文件树统计从原始值更新到 `+2-0`。

---------

Co-authored-by: DCjanus <DCjanus@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

pr-commit-lines-changed: Cannot read properties of undefined (reading 'replaceWith')

2 participants