GitHub Boldless Title

Remove strong style in GitHub repo/gist title

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name              GitHub Boldless Title
// @namespace         https://github.com/Vinfall/UserScripts
// @version           1.2.1
// @author            Vinfall
// @match             https://github.com/*
// @match             https://gist.github.com/*
// @exclude-match     https://github.com/login
// @exclude-match     https://github.com/sessions/*
// @exclude-match     https://github.com/signin
// @exclude-match     https://gist.github.com/auth/*
// @exclude-match     https://gist.github.com/join*
// @exclude-match     https://gist.github.com/login
// @grant             none
// @run-at            document-end
// @license           CC0 1.0 Universal (Public Domain)
// @description       Remove strong style in GitHub repo/gist title
// @description:zh-cn GitHub 仓库名取消加粗
// ==/UserScript==

(() => {
    function replaceStrongWithAnchor() {
        const isGist = window.location.href.includes('gist');
        const selector = isGist ? 'strong[itemprop="name"].css-truncate-target.mr-1' : 'strong.mr-2.flex-self-stretch';

        const strongElements = document.querySelectorAll(selector);
        for (const strong of strongElements) {
            const anchor = strong.querySelector('a'); // Select the <a> tag inside <strong>
            if (anchor) {
                // Create a new <a> element
                const newAnchor = document.createElement('a');
                newAnchor.href = anchor.href; // Preserve the href
                newAnchor.textContent = anchor.textContent; // Preserve the text content

                // Replace the <strong> element with the new <a> element in the DOM
                strong.parentNode.replaceChild(newAnchor, strong);
            }
        }
    }

    // Run after the window has fully loaded
    window.onload = () => {
        replaceStrongWithAnchor();

        // Observe changes in the page (e.g., for dynamic content)
        const observer = new MutationObserver((_mutations) => {
            replaceStrongWithAnchor();
        });
        observer.observe(document.body, { childList: true, subtree: true });
    };
})();