Skip to content

Commit

Permalink
Adopt to new github UI (v0.0.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Oct 27, 2024
1 parent 0ba6fd8 commit d921ebb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ NB: I have no idea how to make extensions. You might know better than me.

The code as-written is pretty hacky, but it does work.

For testing see [this issue](https://github.com/rust-lang/rust/issues/35121#issuecomment-243008208) ("Load more") or this [pull request](https://github.com/rust-lang/rust/pull/111503/files#diff-b12d31237d3790cfe414f072d2ac7ed12906ccbc95f01b7454c72ebab5001421) ("Load diff"). For debugging on android see [this page](https://extensionworkshop.com/documentation/develop/developing-extensions-for-firefox-for-android/). For instructions on how to publish extensions see [this](https://extensionworkshop.com/documentation/publish/submitting-an-add-on/).
For testing see [this issue](https://github.com/rust-lang/rust/issues/35121#issuecomment-243008208) ("Load more") or this [pull request](https://github.com/rust-lang/rust/pull/111503/files#diff-b12d31237d3790cfe414f072d2ac7ed12906ccbc95f01b7454c72ebab5001421) ("Load diff"). For debugging on android see [this page](https://extensionworkshop.com/documentation/develop/developing-extensions-for-firefox-for-android/). For instructions on how to publish extensions see [this](https://extensionworkshop.com/documentation/publish/submitting-an-add-on/).
17 changes: 14 additions & 3 deletions content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
// Clicks on all buttons which contain "Load more..." or "Load diff"

const find_buttons =
(text) => Array.from(document.getElementsByTagName("button")).filter((e) => e.textContent.includes(text));
(f) => Array.from(document.getElementsByTagName("button")).filter((e) =>
// HACK: "new" github UI doesn't remove the button once clicked.
// `.ariaDisabled` is the only way I found to check if the button was already clicked.
// (otherwise clicking would cause updates, which would cause clicking... -> infinite loop)
e.ariaDisabled !== "true"
&& f(e.textContent)
);

async function expandAllLoads(mutations) {
// If a text or button node was added
if (!mutations.some((m) => Array.from(m.addedNodes).some((n) => n.nodeName === "#button" || n.nodeName === "#text"))) {
return
}

// Click on all "Load more…" and "Load diff" buttons
let loads = find_buttons("Load more…").concat(find_buttons("Load diff"));
// Click on all the "Load more…" and its variations buttons
let loads = find_buttons((text) =>
text.includes("Load more…")
|| text.includes("Load diff")
|| text.includes("Load all")
|| (text.includes("Load ") && text.includes(" more")) // "Load 150 more"
);
loads.forEach((b) => b.click());
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "github-no-more",
"description": "No more \"Load more...\" on github",
"version": "0.0.1",
"version": "0.0.2",
"homepage_url": "https://github.com/WaffleLapkin/github-no-more",
"icons": {
"256": "icons/icon.png"
Expand Down

0 comments on commit d921ebb

Please sign in to comment.