Jandan+

煎蛋评论显示图链接

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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();