GitHubのDOMに依存しないフローティングボタンに変更する - #9
Merged
Merged
Conversation
GitHubのPRヘッダーが React ベースに刷新され `.gh-header-title .js-issue-title` が消えたことでボタンが表示されなくなっていた。プラットフォームUIへの依存自体が 脆弱なので、DOM クラスに依存しない画面右下のフローティングボタンに差し替え、 タイトルは document.title から取り出すようにする。 https://claude.ai/code/session_01XtTNUF75qGJhaHCXT1TPgv
GitHub の PR ページタイトルは現在 "<タイトル> by <author> · Pull Request #<N> · <owner>/<repo>" という形式で、 ` · ` で分割しただけだと author 名までタイトルに含まれてしまうため、 末尾の " by <username>" を除去する。 https://claude.ai/code/session_01XtTNUF75qGJhaHCXT1TPgv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
PRページでコピーボタンが表示されなくなっていた。原因は
src/content.tsが.gh-header-title .js-issue-titleというGitHub旧DOM構造のクラスに依存しており、GitHubがPRヘッダーを React ベースへ刷新したことで該当要素が消失し、titleElementが常にnullになってボタン挿入の early return に入っていたため。そもそもプラットフォーム固有のDOM/クラス名に依存する設計が脆弱なので、対症療法(新しいセレクタに差し替える)ではなくアーキテクチャごと見直す。
変更点
document.bodyにposition: fixedのボタンを挿入するだけで、GitHub側のどの要素にも依存しないdocument.titleから取り出す ("Title · Pull Request #N · owner/repo"の先頭部分を抽出)getPullRequestTitle()として関数に切り出しremoveCopyButton()を追加し、URL変化時の処理をsyncButton()に統一styles.cssをフローティングボタン用のスタイル(丸型、影、z-index)に更新。ダークモードも対応getPullRequestTitle/removeCopyButtonのテストを追加)テスト
pnpm lint通過pnpm test:run通過(20 tests)pnpm build通過手動確認TODO
dist/をChromeに読み込み、GitHub PRページで右下にフローティングボタンが表示されることhttps://claude.ai/code/session_01XtTNUF75qGJhaHCXT1TPgv