Flyme社区审核图片解析

to parse the img tag to show images directly

当前为 2018-05-31 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Flyme社区审核图片解析
// @namespace    https://greasyfork.org/zh-CN/users/188666-gehongyan
// @version      1.0.1
// @description  to parse the img tag to show images directly
// @author       gehongyan
// @grant        none
// @include      http://bbs.flyme.cn/forum.php?mod=modcp&action=moderate*
// ==/UserScript==

(function() {
    'use strict';
    var allDivs, thisDiv;
    allDivs = document.evaluate(
        "//div[@style=\"overflow: auto; overflow-x: hidden; height:55px; word-break: break-all;\"]",
        document,
        null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
        null);
    for (var i = 0; i < allDivs.snapshotLength; i++) {
        thisDiv = allDivs.snapshotItem(i);
        var altText = thisDiv.innerHTML;
        var altHTML = altText.replace(/\[img\](.+?)\[\/img\]/ig,"<img src=$1 style=\"max-width:60%; max-height:60%;\" >");
        //document.write(altHTML + "<br /><br />");
        /*var nodeList = parseToDOM(altHTML);
        console.log(nodeList.length);
        for (var j = 0; j < nodeList.length; j++) {
            console.log(j, nodeList[j]);
        }*/
        var newImgTag = document.createElement("div");
        newImgTag.innerHTML = altHTML;
        thisDiv.parentNode.replaceChild(newImgTag, thisDiv);
        //var altTextNode = document.createTextNode(theImage.alt);
        //theImage.parentNode.replaceChild(altText, theImage);
        //var replacement = document.createTextNode(altHTML);
        //document.body.insertBefore(nodeList.innerText, document.body.firstChild);
    }

})();

function parseToDOM(str){
   var div = document.createElement("div");
   if(typeof str == "string"){
       div.innerHTML = str;
   }
   return div.childNodes;
}