Skip to content

Instantly share code, notes, and snippets.

@aseemk
Last active May 11, 2016 19:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aseemk/5274164 to your computer and use it in GitHub Desktop.
Save aseemk/5274164 to your computer and use it in GitHub Desktop.
GitHub bookmarklet for toggling outdated diffs, and dotjs script for fixing links to pull request comments on outdated diffs.
javascript:(function(){[].forEach.call(document.querySelectorAll('.discussion-item-toggle-closed'), (elmt) => elmt.click())})();
// Fix pull request comments for outdated diffs:
// (via https://gist.github.com/aseemk/5274164)
var DIFF_COMMENT_REGEX = /\/files(\/\w+)?#(r(\w+))/;
// new style: ...pull/123/files/abcdef1234567890#r12345678
// old style: ...pull/123/files#r12345678
var diffCommentMatch = location.href.match(DIFF_COMMENT_REGEX);
var diffCommentId = diffCommentMatch && diffCommentMatch[2];
var diffCommentNum = diffCommentMatch && diffCommentMatch[3];
if (diffCommentId && !document.getElementById(diffCommentId)) {
// TODO can we use history.pushState() instead, to be faster?
// need to figure out how to get GitHub to respond to the change.
// $(window).trigger('popstate') doesn't seem to do the trick.
location.replace(location.href.replace(
DIFF_COMMENT_REGEX, '#discussion_r' + diffCommentNum));
}
@aseemk
Copy link
Author

aseemk commented Mar 30, 2013

@aseemk
Copy link
Author

aseemk commented Mar 15, 2016

TODO: Provide another example link given GitHub's new URL format. Trigger by rebasing after a comment.

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