Skip to content

Instantly share code, notes, and snippets.

@hyrious
Created January 15, 2024 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyrious/1b82bceddc300e36a4a7eb8564ee239e to your computer and use it in GitHub Desktop.
Save hyrious/1b82bceddc300e36a4a7eb8564ee239e to your computer and use it in GitHub Desktop.
Get shorten URL if it has abbrev commit hash
// ==UserScript==
// @name GitHub Shorten Commit URL
// @namespace short-commit.github.com
// @match https://github.com/**/commit/*
// @grant none
// @version 1.0
// @author hyrious
// @description Replace shorter URL if abbrev commit hash exist
// ==/UserScript==
void function() {
"use strict"
let $sha = document.querySelector('.sha.user-select-contain')
if ($sha) {
let sha = $sha.textContent.trim()
let parts = location.pathname.split('/')
let index = parts.findIndex(e => e.startsWith(sha))
if (index > 0) {
parts[index] = sha
let url = parts.join('/')
if (location.search) url += location.search
history.replaceState({}, "", url)
}
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment