Created
January 15, 2024 09:30
-
-
Save hyrious/1b82bceddc300e36a4a7eb8564ee239e to your computer and use it in GitHub Desktop.
Get shorten URL if it has abbrev commit hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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