GitHub Release - Strip Hash Prefix

On GitHub release pages, strips the "sha256:" (and other hash) prefix when copying asset checksums.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         GitHub Release - Strip Hash Prefix
// @namespace    https://github.com/anon
// @version      1.1
// @description  On GitHub release pages, strips the "sha256:" (and other hash) prefix when copying asset checksums.
// @match        https://github.com/*/*/releases*
// @grant        none
// @inject-into  page
// @license      CC-BY-NC-SA-4.0
// ==/UserScript==

(function() {
    'use strict';

    const HASH_PREFIXES = /^(sha256|sha1|sha512|sha384|md5|sha224|sha3_256|sha3_384|sha3_512|sha3_224):/;

    function stripPrefix(value) {
        const match = value.match(HASH_PREFIXES);
        return match ? value.slice(match[0].length) : value;
    }

    function wireClipboardCopy(el) {
        if (el.dataset.hashStripped) return;
        const origValue = el.getAttribute('value');
        if (!origValue || !HASH_PREFIXES.test(origValue)) return;

        el.setAttribute('value', stripPrefix(origValue));
        el.dataset.hashStripped = '1';

        const hashDisplay = el.parentElement?.previousElementSibling?.querySelector('.Truncate-text');
        if (hashDisplay) {
            hashDisplay.textContent = stripPrefix(hashDisplay.textContent);
        }
    }

    function scan() {
        document.querySelectorAll('clipboard-copy').forEach(wireClipboardCopy);
    }

    scan();

    new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const node of m.addedNodes) {
                if (node.nodeType !== 1) continue;
                if (node.matches && node.matches('clipboard-copy')) {
                    wireClipboardCopy(node);
                }
                if (node.querySelectorAll) {
                    node.querySelectorAll('clipboard-copy').forEach(wireClipboardCopy);
                }
            }
        }
    }).observe(document.documentElement, { childList: true, subtree: true });
})();