Hacker News - Match Comment Link Style to Story Link

Make the comment link on Hacker News front page match the story link formatting (external stories only). So that you can use Snap Links to easily Right Click and drag to mass open links if you like to read Comments page for stories.

// ==UserScript==
// @name         Hacker News - Match Comment Link Style to Story Link
// @author       MedX
// @namespace    MedX-AA
// @license      MIT
// @icon         https://news.ycombinator.com/favicon.ico
// @version      1.2
// @description  Make the comment link on Hacker News front page match the story link formatting (external stories only). So that you can use Snap Links to easily Right Click and drag to mass open links if you like to read Comments page for stories.
// @match        https://news.ycombinator.com/front*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    function styleCommentLink(titleLink) {
        const href = titleLink.getAttribute('href');
        if (!href) return;

        const isInternal =
            href.includes('ycombinator.com') ||
            href.startsWith('item?id=') ||
            href.startsWith('from?site=');
        if (isInternal) return;

        const titleRow = titleLink.closest('tr');
        const subtextRow = titleRow?.nextElementSibling;
        const subtext = subtextRow?.querySelector('.subtext');
        if (!subtext) return;

        const subLinks = subtext.querySelectorAll('a[href^="item?id="]');
        if (subLinks.length === 0) return;

        const commentLink = subLinks[subLinks.length - 1];
        if (!commentLink || !/\d+\s*comments|discuss/i.test(commentLink.textContent)) return;

        const computed = window.getComputedStyle(titleLink);
        commentLink.style.fontSize = computed.fontSize;
        commentLink.style.fontWeight = computed.fontWeight;
        commentLink.style.color = computed.color;
        commentLink.style.fontFamily = computed.fontFamily;
        commentLink.style.textDecoration = computed.textDecoration;

        if (titleLink.className) {
            commentLink.className = titleLink.className;
        }
    }

    // Run immediately on load
    document.querySelectorAll('.titleline > a').forEach(styleCommentLink);
})();