// ==UserScript== // @name s1麻将脸r板显示脚本 // @namespace Majfacesinreddit // @version 0.1 // @description 在r板显示麻将脸 // @author huayu3rd // @match https://www.reddit.com/r/s1bbs/** // @downloadURL none // ==/UserScript== //参考了https://greasyfork.org/scripts/372459 (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 window.onload = function () { var zhengze1 = new RegExp("{{mjl:","g") var zhengze2 = new RegExp(".png}}","g") var zhengze3 = new RegExp(".gif}}","g") var img1 = ""; var img3 = ".gif\">"; document.body.innerHTML = document.body.innerHTML.replace(zhengze1, img1); document.body.innerHTML = document.body.innerHTML.replace(zhengze2, img2); document.body.innerHTML = document.body.innerHTML.replace(zhengze3, img3); } })();