From f457da27b975824c83f7867ff3786abd1b67266f Mon Sep 17 00:00:00 2001 From: shawn Date: Mon, 30 Nov 2026 00:51:31 +0800 Subject: [PATCH 1/2] feat: load more Feed activity on scroll --- e2e/regression.spec.mjs | 28 ++++++++++++++++++++++++++++ src/content.ts | 2 ++ src/features/feed-auto-load.ts | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/features/feed-auto-load.ts diff --git a/e2e/regression.spec.mjs b/e2e/regression.spec.mjs index 3269244..ef42af2 100644 --- a/e2e/regression.spec.mjs +++ b/e2e/regression.spec.mjs @@ -27,6 +27,34 @@ async function hydrate(root, html) { }, html); } +test("loads successive Feed pages as their pagination buttons approach the viewport", async ({ + page, +}) => { + await page.route("https://github.com/feed", (route) => + route.fulfill({ + contentType: "text/html", + body: `
+
+
+ `, + }), + ); + await page.goto("https://github.com/feed"); + const more = page.getByRole("button", { name: "More" }); + for (const count of [1, 2]) { + await expect(page.locator("article")).toHaveCount(count - 1); + await more.scrollIntoViewIfNeeded(); + await expect(page.locator("article")).toHaveCount(count); + } +}); + test("copies a repository-qualified issue number after GitHub replaces the list", async ({ page, context, diff --git a/src/content.ts b/src/content.ts index 952e61e..a2eeaaa 100644 --- a/src/content.ts +++ b/src/content.ts @@ -32,6 +32,7 @@ import { injectContributorCard, cleanupContributorCard } from "./features/contri import { reserveInfoRowSkeletons } from "./lib/info-row-skeleton"; import { applyPageMarker, syncListLayout } from "./lib/page-marker"; import { injectTrendingLink } from "./features/trending-link"; +import { observeFeedPagination } from "./features/feed-auto-load"; const FEATURE_KEYS = [ "feature-pr-branch-names", @@ -215,6 +216,7 @@ onPageReady(async () => { // Always-on features injectFileAgeColor(); injectNumberCopy(); + observeFeedPagination(); // Reserve row height with skeleton placeholders before any async fetch starts // — avoids layout-shift "flash" when real badges arrive. diff --git a/src/features/feed-auto-load.ts b/src/features/feed-auto-load.ts new file mode 100644 index 0000000..d7d9890 --- /dev/null +++ b/src/features/feed-auto-load.ts @@ -0,0 +1,34 @@ +let currentButton: HTMLButtonElement | null = null; +let observer: IntersectionObserver | null = null; + +export function observeFeedPagination(): void { + const button = + location.pathname === "/feed" + ? document.querySelector( + "#conduit-feed-frame .js-ajax-pagination button.ajax-pagination-btn", + ) + : null; + if (button === currentButton) return; + + observer?.disconnect(); + observer = null; + currentButton = button; + if (!button) return; + + observer = new IntersectionObserver( + ([entry], paginationObserver) => { + if ( + !entry.isIntersecting || + !button.isConnected || + currentButton !== button || + location.pathname !== "/feed" + ) { + return; + } + paginationObserver.disconnect(); + button.click(); + }, + { rootMargin: "0px 0px 200px" }, + ); + observer.observe(button); +} From 47bea44d11f97608240c6ed210ce3505eb562a9c Mon Sep 17 00:00:00 2001 From: shawn Date: Mon, 30 Nov 2026 12:16:41 +0800 Subject: [PATCH 2/2] feat: add a toggle for Feed auto-load --- README.md | 4 +++- README_CN.md | 4 +++- e2e/regression.spec.mjs | 19 ++++++++++++++++++- src/_locales/en/messages.json | 2 ++ src/_locales/zh_CN/messages.json | 2 ++ src/_locales/zh_TW/messages.json | 2 ++ src/content.ts | 9 +++++++-- src/features/feed-auto-load.ts | 11 ++++++++--- src/options.test.ts | 1 + src/options.ts | 1 + static/options.html | 12 ++++++++++++ 11 files changed, 59 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c0d9e99..5e73b65 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Better GitHub is a Chrome extension that enhances the GitHub experience. Inspire ### Home +- **Feed Auto-Load** — On by default. Scroll near the bottom of `/feed` to load more posts. Turn it off under **Options → Home** to load more posts manually. + - ~~**Better Top Repositories** — Auto-expand the "Top repositories" sidebar list and pin your favorite repos to the top. Works on the dashboard, feed page, and navigation drawer.~~ On GitHub’s new dashboard, use **Edit repositories** in the sidebar to choose your favorites. [GitHub changelog](https://github.blog/changelog/2026-11-20-pin-your-favorite-repositories-to-your-dashboard/)
@@ -166,4 +168,4 @@ A few small features have little impact on the page experience. To avoid adding Right-click the extension icon → **Options**: - **GitHub Token** — A **classic** personal access token for private repos and review status. Needs `repo` scope. [Create one here](https://github.com/settings/tokens). -- **Feature Toggles** — Enable or disable each feature individually. Changes take effect immediately. +- **Feature Toggles** — Turn features listed on the options page on or off individually. Changes take effect immediately. diff --git a/README_CN.md b/README_CN.md index ff14544..db3bc61 100644 --- a/README_CN.md +++ b/README_CN.md @@ -24,6 +24,8 @@ Better GitHub 是一个增强 GitHub 使用体验的 Chrome 插件,灵感源 ### 首页 +- **Feed 自动加载** — 默认开启。在 `/feed` 页面滚动到接近底部时会自动加载更多动态。想手动加载时,可在**选项 → 首页**中关闭。 + - ~~**Better Top Repositories** — 自动展开侧边栏 "Top repositories" 列表,并支持将常用仓库置顶。适用于 Dashboard、Feed 页面和导航抽屉。~~ 在 GitHub 新版首页,点击侧边栏的 **Edit repositories** 即可选择要置顶的仓库。[GitHub 更新公告](https://github.blog/changelog/2026-11-20-pin-your-favorite-repositories-to-your-dashboard/)
@@ -166,4 +168,4 @@ Better GitHub 是一个增强 GitHub 使用体验的 Chrome 插件,灵感源 右键扩展图标 → **选项**: - **GitHub Token** — 用于访问私有仓库和获取 review 状态。需要 **classic** 类型的 token,勾选 `repo` 权限。[点此创建](https://github.com/settings/tokens)。 -- **功能开关** — 独立控制每个功能的启用/禁用,修改后即时生效。 +- **功能开关** — 可单独开启或关闭选项页列出的功能,修改后即时生效。 diff --git a/e2e/regression.spec.mjs b/e2e/regression.spec.mjs index ef42af2..35d2ff5 100644 --- a/e2e/regression.spec.mjs +++ b/e2e/regression.spec.mjs @@ -27,8 +27,9 @@ async function hydrate(root, html) { }, html); } -test("loads successive Feed pages as their pagination buttons approach the viewport", async ({ +test("loads successive Feed pages and applies the auto-load toggle immediately", async ({ page, + context, }) => { await page.route("https://github.com/feed", (route) => route.fulfill({ @@ -53,6 +54,22 @@ test("loads successive Feed pages as their pagination buttons approach the viewp await more.scrollIntoViewIfNeeded(); await expect(page.locator("article")).toHaveCount(count); } + + const worker = context.serviceWorkers()[0] ?? (await context.waitForEvent("serviceworker")); + const options = await context.newPage(); + await options.goto(new URL("options.html", worker.url()).href); + await options.locator("summary", { hasText: "Home" }).click(); + const toggle = options.locator("label", { has: options.locator("#feature-feed-auto-load") }); + await toggle.click(); + await expect(toggle.locator("input")).not.toBeChecked(); + + await more.scrollIntoViewIfNeeded(); + await more.click(); + await expect(page.locator("article")).toHaveCount(3); + await more.scrollIntoViewIfNeeded(); + await expect(more).toBeInViewport(); + await toggle.click(); + await expect(page.locator("article")).toHaveCount(4); }); test("copies a repository-qualified issue number after GitHub replaces the list", async ({ diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index ff450ef..97739de 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -41,6 +41,8 @@ "featTrendingLinkDesc": { "message": "Add a Trending shortcut below Feed in the home sidebar." }, + "featFeedAutoLoadName": { "message": "Feed Auto-Load" }, + "featFeedAutoLoadDesc": { "message": "Load more posts as you scroll near the bottom of the Feed." }, "featDefaultSortName": { "message": "Default Sort by Updated" }, "featDefaultSortDesc": { "message": "Sort PR and issue lists by recently updated instead of creation time." diff --git a/src/_locales/zh_CN/messages.json b/src/_locales/zh_CN/messages.json index 48828cc..277e07a 100644 --- a/src/_locales/zh_CN/messages.json +++ b/src/_locales/zh_CN/messages.json @@ -41,6 +41,8 @@ "featTrendingLinkDesc": { "message": "在首页侧栏的 Feed 下方添加 Trending 快捷入口。" }, + "featFeedAutoLoadName": { "message": "Feed 自动加载" }, + "featFeedAutoLoadDesc": { "message": "在 Feed 页面滚动到接近底部时,自动加载更多动态。" }, "featDefaultSortName": { "message": "默认按更新时间排序" }, "featDefaultSortDesc": { "message": "PR 和 Issue 列表按最近更新排序,而非创建时间。" diff --git a/src/_locales/zh_TW/messages.json b/src/_locales/zh_TW/messages.json index bc7e292..2a2d74c 100644 --- a/src/_locales/zh_TW/messages.json +++ b/src/_locales/zh_TW/messages.json @@ -41,6 +41,8 @@ "featTrendingLinkDesc": { "message": "在首頁側欄的 Feed 下方加入 Trending 快捷入口。" }, + "featFeedAutoLoadName": { "message": "Feed 自動載入" }, + "featFeedAutoLoadDesc": { "message": "在 Feed 頁面捲動到接近底部時,自動載入更多動態。" }, "featDefaultSortName": { "message": "預設依更新時間排序" }, "featDefaultSortDesc": { "message": "PR 和 Issue 清單依最近更新排序,而非建立時間。" diff --git a/src/content.ts b/src/content.ts index a2eeaaa..125f91b 100644 --- a/src/content.ts +++ b/src/content.ts @@ -32,7 +32,7 @@ import { injectContributorCard, cleanupContributorCard } from "./features/contri import { reserveInfoRowSkeletons } from "./lib/info-row-skeleton"; import { applyPageMarker, syncListLayout } from "./lib/page-marker"; import { injectTrendingLink } from "./features/trending-link"; -import { observeFeedPagination } from "./features/feed-auto-load"; +import { cleanupFeedPagination, observeFeedPagination } from "./features/feed-auto-load"; const FEATURE_KEYS = [ "feature-pr-branch-names", @@ -48,6 +48,7 @@ const FEATURE_KEYS = [ "feature-commit-tags", "feature-commit-diff-stats", "feature-trending-link", + "feature-feed-auto-load", "feature-watch-fork-star-popup", "feature-pr-collapse-expand", "feature-contributor-card", @@ -69,6 +70,7 @@ const FEATURE_CLASSES: Record = { "feature-default-sort": [], "feature-commit-tags": ["better-github-commit-tag"], "feature-commit-diff-stats": ["better-github-commit-diff-stats", "bg-skeleton-pill--commit-diff"], + "feature-feed-auto-load": [], "feature-trending-link": ["better-github-trending-nav"], "feature-watch-fork-star-popup": ["bg-wfs-popup"], "feature-pr-collapse-expand": ["better-github-toggle-tree", "better-github-collapse-expand"], @@ -85,6 +87,7 @@ const FEATURE_CLEANUPS: Partial void>> = { "feature-watch-fork-star-popup": cleanupWatchForkStarPopup, "feature-release-downloads-count": cleanupReleaseAssetDownloads, "feature-contributor-card": cleanupContributorCard, + "feature-feed-auto-load": cleanupFeedPagination, }; function isExtensionValid(): boolean { @@ -166,6 +169,9 @@ function injectFeature(key: FeatureKey): void { case "feature-trending-link": injectTrendingLink(); break; + case "feature-feed-auto-load": + observeFeedPagination(); + break; case "feature-watch-fork-star-popup": injectWatchForkStarPopup(); break; @@ -216,7 +222,6 @@ onPageReady(async () => { // Always-on features injectFileAgeColor(); injectNumberCopy(); - observeFeedPagination(); // Reserve row height with skeleton placeholders before any async fetch starts // — avoids layout-shift "flash" when real badges arrive. diff --git a/src/features/feed-auto-load.ts b/src/features/feed-auto-load.ts index d7d9890..b0f073d 100644 --- a/src/features/feed-auto-load.ts +++ b/src/features/feed-auto-load.ts @@ -1,6 +1,12 @@ let currentButton: HTMLButtonElement | null = null; let observer: IntersectionObserver | null = null; +export function cleanupFeedPagination(): void { + observer?.disconnect(); + observer = null; + currentButton = null; +} + export function observeFeedPagination(): void { const button = location.pathname === "/feed" @@ -10,8 +16,7 @@ export function observeFeedPagination(): void { : null; if (button === currentButton) return; - observer?.disconnect(); - observer = null; + cleanupFeedPagination(); currentButton = button; if (!button) return; @@ -20,7 +25,7 @@ export function observeFeedPagination(): void { if ( !entry.isIntersecting || !button.isConnected || - currentButton !== button || + observer !== paginationObserver || location.pathname !== "/feed" ) { return; diff --git a/src/options.test.ts b/src/options.test.ts index 7f0ebb5..4cf51f4 100644 --- a/src/options.test.ts +++ b/src/options.test.ts @@ -14,6 +14,7 @@ const FEATURE_KEYS = [ "feature-commit-tags", "feature-commit-diff-stats", "feature-trending-link", + "feature-feed-auto-load", "feature-watch-fork-star-popup", "feature-pr-collapse-expand", "feature-contributor-card", diff --git a/src/options.ts b/src/options.ts index 206f2e4..4539654 100644 --- a/src/options.ts +++ b/src/options.ts @@ -38,6 +38,7 @@ const FEATURE_KEYS = [ "feature-commit-tags", "feature-commit-diff-stats", "feature-trending-link", + "feature-feed-auto-load", "feature-watch-fork-star-popup", "feature-pr-collapse-expand", "feature-contributor-card", diff --git a/static/options.html b/static/options.html index d85752f..986739f 100644 --- a/static/options.html +++ b/static/options.html @@ -561,6 +561,18 @@

Settings

+
  • +
    +
    Feed Auto-Load
    +
    + Load more posts as you scroll near the bottom of the Feed. +
    +
    + +