Skip to content

Instantly share code, notes, and snippets.

@david-crespo
Last active August 19, 2024 04:58
Show Gist options
  • Save david-crespo/19d4cf6a212fe184662c56fd7ac15f76 to your computer and use it in GitHub Desktop.
Save david-crespo/19d4cf6a212fe184662c56fd7ac15f76 to your computer and use it in GitHub Desktop.
GitHub bookmarklets

Bookmarklets for GitHub pain points

To install these bookmarklets, copy the line starting with javascript: into the URL field of a bookmark in your browser. For each one, I've included both a one-line version you can paste directly and a formatted version so you can read it. The (function() { ... })() IIFE wrapper in the one-liner is there because that's how you have to wrap up a block of code.

Load collapsed diffs

Presumably to optimize initial page load time, GitHub collapses large files in a diff by default. This clicks all the "load diff" buttons on the page. Note that we use a setTimeout to do it a second time 5 seconds later because on very large diffs, the full list of files can take time to load, which means you can click the bookmarklet too early.

Page to try it on: https://github.com/oxidecomputer/omicron/pull/2645/files

javascript:(function() { const loadAll = () => document.querySelectorAll('button.load-diff-button').forEach((b) => b.click()); loadAll(); setTimeout(loadAll, 5000); })()
const loadAll = () =>
  document
    .querySelectorAll("button.load-diff-button")
    .forEach((b) => b.click());
    
loadAll();
setTimeout(loadAll, 5000);

Load all conversations

This one is a little more elaborate because of pagination: you can click all the visible load more buttons, but there might be more appearing after that attempt. So when we click the buttons, we also queue up another attempt to click 5 seconds later. In order to avoid looping forever (if for example, an error causes ones of the buttons to stay on the page), we cap the total number of runs.

Page to try it on: oxidecomputer/omicron#2645

javascript:(function () { let runs = 0; function loadMore() { runs += 1; if (runs > 10) { console.log("Max run count reached"); return; } const btns = document.querySelectorAll(".ajax-pagination-btn"); if (btns.length > 0) { console.log(`Clicking ${btns.length} load more buttons (run ${runs})`); btns.forEach((b) => b.click()); setTimeout(loadMore, 5000); } else { console.log(`No more load more buttons found`); } } loadMore(); })();
let runs = 0;
function loadMore() {
  runs += 1;
  if (runs > 10) {
    console.log("Max run count reached");
    return;
  }

  const btns = document.querySelectorAll(".ajax-pagination-btn");
  if (btns.length > 0) {
    console.log(`Clicking ${btns.length} load more buttons (run ${runs})`);
    btns.forEach((b) => b.click());
    setTimeout(loadMore, 5000);
  } else {
    console.log(`No more load more buttons found`);
  }
}

loadMore();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment