Skip to content

Instantly share code, notes, and snippets.

@markflorkowski
Created April 26, 2023 20:52
Show Gist options
  • Save markflorkowski/e31131fa43bca2c1be2ceb285082a4c3 to your computer and use it in GitHub Desktop.
Save markflorkowski/e31131fa43bca2c1be2ceb285082a4c3 to your computer and use it in GitHub Desktop.
Github "Copy Full SHA" UserScripts
// or just replace the short sha with the full length one
(function() {
const links = document.querySelectorAll("a.Link--muted svg.octicon-git-commit");
links.forEach(link => {
link.parentElement.innerText = link.parentElement.href.split("/").pop()
});
})();
// add button that allows user to copy the full sha
(function() {
const links = document.querySelectorAll("a.Link--muted svg.octicon-git-commit");
links.forEach(link => {
// create a button element
const button = document.createElement("button");
button.textContent = "Copy Full SHA";
button.style.marginLeft = "10px";
// add click event listener to the button
button.addEventListener("click", event => {
event.stopPropagation();
const linkText = link.parentElement.href.split("/").pop();
window.navigator.clipboard.writeText(linkText)
});
// append the button to the parent element of the SVG
link.parentElement.parentElement.appendChild(button);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment