Skip to content

Instantly share code, notes, and snippets.

@migueldiab
Forked from peterflynn/ Useful GitHub bookmarklets
Last active March 1, 2019 15:38
Show Gist options
  • Save migueldiab/709918ef078b8419cba2293f1c6fd634 to your computer and use it in GitHub Desktop.
Save migueldiab/709918ef078b8419cba2293f1c6fd634 to your computer and use it in GitHub Desktop.
GitHub comment thread bookmarklets
javascript:(function() { document.querySelectorAll(".outdated-comment").forEach(function (node) {
node.classList.add("open");
}) }());
// In the usual, simple case:
javascript:(function(){ document.querySelectorAll(".js-comment .author").forEach(function (node) {
if(node.textContent === "<YOUR USERNAME HERE>") {
for (var parent = node.parentNode; parent; parent = parent.parentNode) {
if (parent.classList && parent.classList.contains("outdated-comment")) { parent.classList.add("open"); break; }
}
}
}) }());
// Or in my case I have two different usernames for GitHub vs. internal GH:
javascript:(function(){ document.querySelectorAll(".js-comment .author").forEach(function (node) {
if(node.textContent === "pflynn" || node.textContent === "peterflynn") {
for (var parent = node.parentNode; parent; parent = parent.parentNode) {
if (parent.classList && parent.classList.contains("outdated-comment")) { parent.classList.add("open"); break; }
}
}
}) }());
javascript:(function(){
var start=new Date(prompt("Enter Date/Time", new Date()));
document.querySelectorAll(".js-comment relative-time").forEach(function (node) {
function closest(node, className) {
for (var parent = node.parentNode; parent; parent = parent.parentNode) {
if (parent.classList && parent.classList.contains(className)) return parent;
}
}
var border=closest(node, "js-comment");
if (new Date(node.getAttribute("datetime")) >= start) {
border.style.border = "1px solid red";
var container = closest(border, "outdated-comment");
if (container) { container.classList.add("open"); }
} else {
border.style.border = "";
}
});
}());
javascript:(function(){
function closest(node, className) {
for (var parent = node.parentNode; parent; parent = parent.parentNode) {
if (parent.classList && parent.classList.contains(className)) return parent;
}
}
var selectionNode = document.getSelection().anchorNode;
if (!selectionNode) {
alert("Select text in the file to go to parent blame for that file");
return;
}
var fileBlock = closest(selectionNode, "file");
var fileRelPath = fileBlock.getElementsByClassName("file-header")[0].dataset.path;
var parentSHABlock = document.querySelectorAll(".commit-meta .sha-block")[0];
var parentSHANodes = parentSHABlock.querySelectorAll(".sha");
if (parentSHANodes.length > 1) {
alert("Commit has two parents - unsure which to use");
return;
}
var commitURL = parentSHANodes[0].href;
var url = commitURL.replace("/commit/", "/blame/") + "/" + fileRelPath;
/* Get line number */
var codeCell = closest(selectionNode, "blob-code");
var lineNumCell = codeCell.previousElementSibling;
var lineNum = lineNumCell.dataset.lineNumber;
url += "#L" + lineNum;
/* Navigate to new page */
window.location.href = url;
}());
javascript:(function() {
loadDiffClassSelector = "text-bold f4 mb-3 js-button-text";
const list = document.getElementsByClassName(loadDiffClassSelector);
for(let i=0; i < list.length; i++) {
list[i].click();
}
}());
To use: create a new bookmark and paste into the URL field.
In Chrome, you can paste the full multiline code as shown below.
In other browsers, you may need to minify the code into one line first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment