Greasy Fork

s1新版麻将脸显示脚本

将新增的麻将脸代码转换成图片

当前为 2018-09-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         s1新版麻将脸显示脚本
// @namespace    s1newmjfacejioben
// @version      1.1
// @description  将新增的麻将脸代码转换成图片
// @author       a simple s1 user
// @match        https://bbs.saraba1st.com/2b/*.html
// @match        https://bbs.saraba1st.com/2b/forum.php?mod=viewthread&tid=*
// ==/UserScript==

(function() {
function replace(search,replacement){
	var xpathResult = document.evaluate(
		"//*/text()",
		document,
		null,
		XPathResult.ORDERED_NODE_ITERATOR_TYPE,
		null
	);
	var results = [];
	// We store the result in an array because if the DOM mutates
	// during iteration, the iteration becomes invalid.
	while(res = xpathResult.iterateNext()) {
		results.push(res);
	}
	results.forEach(function(res){
		res.textContent = res.textContent.replace(search,replacement);
	})
}
    //上面那一段我也不懂什么意思,作用应该就是让replace仅限于可见文本。代码来源:http://bit.ly/2PR7uDG

replace(/\[a:/g,'::mjla');
//这一段是动物分类的

replace(/\[c:/g,'::mjlc');
replace(/]/g,'ljm::');
//这一段是动漫分类的

replace(/\{:1465_/g,'::mjlf')
replace(/:}/g,'ljm::')
//这一段是普通分类的


    window.onload = function () {


    for (var i=0;i<12;i++){
		var id = 1691 + i;
		var zhengze = new RegExp("::mjlf" + id + "ljm::","g")
		var img = "<img src =\"http://mahjongface.tk/smiley/face/" + id + "\">";
		document.body.innerHTML = document.body.innerHTML.replace(zhengze, img);
	}//这一段是普通分类的

    for (var i=0;i<39;i++){
		var id = 252 + i;
		var zhengze = new RegExp("::mjlc" + id + "ljm::","g")
		var img = "<img src =\"http://mahjongface.tk/smiley/carton/" + id + "\">";
		document.body.innerHTML = document.body.innerHTML.replace(zhengze, img);
	}//这一段是动漫分类的

	document.body.innerHTML = document.body.innerHTML.replace(/::mjla017ljm::/g, '<img src =\"http://mahjongface.tk/smiley/animal/017\">');
	document.body.innerHTML = document.body.innerHTML.replace(/::mjla018ljm::/g, '<img src =\"http://mahjongface.tk/smiley/animal/018\">');
	//动物分类才增加两个,我都不想用for循环了
}

})();