Jandan+

煎蛋评论显示图链接

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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        Jandan+
// @namespace   Jandan+@Byzod
// @description 煎蛋评论显示图链接
// @include     /^https?:\/\/jandan\.net\//
// @version     2016-11-24
// @grant       none
// ==/UserScript==

function JandanPlus(){
	var self = this;
	var IMAGE_URL_REGEX = /(ftp|http)s?:\/\/[^\s\r\n]+\.(jpe?g|png|bmp|gif|ico|tga|tpic|tiff|svgz?|webp|jp2|j2c)/gi;
	
	self.RegisterCommentListMutation = function(){
		var commentLists = document.querySelectorAll(".commentlist");
		var observer = new MutationObserver(
			(e)=>{
				self.ParseImgURLTextInComment(e);
			}
		);
		var config = { childList: true, subtree: true };
		if(commentLists){
			for(var commentList of commentLists){
				observer.observe(commentList, config);
			}
		}
	};
	
	self.ParseImgURLTextInComment = function(e){
		for(var record of e){
			if(record.target.id == "ds-hot-posts" || (record.previousSibling && record.previousSibling.id == "ds-hot-posts")){
				// 评论
				var comments = record.addedNodes[1].querySelectorAll(".ds-comment-body");
				// console.log("jd+ comment-body: %o", comments);//debug
				for(var comment of comments){
					var commentText = comment.querySelector("p").innerHTML;
					var matches = commentText.match(IMAGE_URL_REGEX);
					if(matches){
						for(var i = 0; i < matches.length; i++){
							commentText = commentText.replace(matches[i], '<img src="' + matches[i] + '"></img>');
							// console.log("jd+ matches[%d]: %o;\n    replace to: %o", i, matches[i], i, commentText);//debug
						}
						comment.querySelector("p").innerHTML = commentText;
					}
				}
			}
		}
	};
}
var oioi = new JandanPlus();
oioi.RegisterCommentListMutation();