e-hentai auto hyperlink

e-hentai auto convert urls in gallery comments into hyperlinks

// ==UserScript==
// @name        e-hentai auto hyperlink
// @namespace   https://greasyfork.org/scripts/441145
// @version     2.2
// @description e-hentai auto convert urls in gallery comments into hyperlinks
// @author      fmnijk
// @match       https://e-hentai.org/*
// @icon        https://www.google.com/s2/favicons?domain=e-hentai.org
// @grant       none
// @run-at      document-end
// @license     MIT
// ==/UserScript==

/* main function */
(window.onload = function() {
    'use strict';

    if (window.location.href === 'https://e-hentai.org/'){
        return false;
    }

    const comments = document.querySelectorAll(".c6");

    comments.forEach(function(comment){
        let before = comment.innerHTML;

        before = before.replace(/&/g, '&');

        const after = before.replace(/(<a\b[^>]*>.*<\/a>)|((https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)))/gi, function (match, p1, p2) {
            // Check if the match is already an anchor tag, if so, return it unchanged.
            if (p1) {
                return p1;
            } else {
                // Otherwise, create a new anchor tag.
                return '<a href="' + p2 + '">' + p2 + '</a>';
            }
        });

        comment.innerHTML = after;
    });
})();