e-hentai auto hyperlink

e-hentai auto convert urls in gallery comments into hyperlinks

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        e-hentai auto hyperlink
// @namespace   https://greasyfork.org/scripts/441145
// @version     2.4
// @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 */
(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;
        // 暫時替換 <img> 標籤 因為img標籤裡有url 會被影響
        let imgPlaceholders = [];
        before = before.replace(/<img\b[^>]*>/gi, function(match) {
            imgPlaceholders.push(match);
            return `<!--img-placeholder-${imgPlaceholders.length - 1}-->`;
        });
        before = before.replace(/&amp;/g, '&');

        // 更新的URL正则表达式,支持Unicode字符
        const urlRegex = /(<a\b[^>]*>.*<\/a>)|((https?:\/\/)(?:www\.)?(?:[\w\u00a1-\uffff][\w\u00a1-\uffff-]{0,62})?[\w\u00a1-\uffff]\.(?:[a-z\u00a1-\uffff]{2,6}\.?)+(?:\/(?:[^\s<>"{}|\\^`\[\]])*)?)/gi;

        // 處理 URL
        const after = before.replace(urlRegex, 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>';
            }
        });

        // 還原 <img> 標籤
        let finalHTML = after.replace(/<!--img-placeholder-(\d+)-->/g, function(match, index) {
            return imgPlaceholders[parseInt(index)];
        });
        comment.innerHTML = finalHTML;
    });
})();