Greasy Fork

Greasy Fork is available in English.

真白萌新站阅读体验优化

去掉span的内联字体样式,删除部分小说的多余换行。

当前为 2021-09-02 提交的版本,查看 最新版本

// ==UserScript==
// @name         真白萌新站阅读体验优化
// @namespace    mashiro_me
// @version      0.2
// @description  去掉span的内联字体样式,删除部分小说的多余换行。
// @author       MikaRyu
// @match        https://masiro.me/admin/novelReading*
// @icon         https://www.google.com/s2/favicons?domain=masiro.me
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var baseBox = document.getElementsByClassName("box-body nvl-content")[0];
    var spans = baseBox.getElementsByTagName("span");
    for(var i = 0;i<spans.length;i++){
        spans[i].style.fontFamily = null;
        spans[i].style.fontSize = null;
    }

    DeleteEmpty(baseBox);
    DeleteBrs(baseBox);

})();

function DeleteEmpty(parent){

    var childs = parent.childNodes;
    var tagName, innerText;

    for(var i = 0; i < childs.length; i++){

        tagName = childs[i].localName;

        if (tagName == "br"){
            continue;
        }

        innerText = childs[i].innerHTML;
        if (typeof(innerText) == "undefined"){
            innerText = childs[i].data;
        }

        if ((/^(&nbsp;|\s)*$/g.test(innerText)) ||
            ((! childs[i].hasChildNodes()) && typeof(tagName) != "undefined")){

            parent.removeChild(childs[i]);
            i -= 1;
            continue;

        }

        DeleteEmpty(childs[i]);

    }
}

function DeleteBrs(parent){

    var j = 0;
    var childs = parent.childNodes;
    var tagName;

    for(var i = 0; i < childs.length; i++){

        tagName = childs[i].localName;

        if (tagName == "br"){

            if( j == 3 ){
                parent.removeChild(childs[i]);
                i -= 1;
            }else{
                j += 1;
            }
            continue;
        }

        j = 0;
        if (childs[i].hasChildNodes()){
            DeleteBrs(childs[i]);
        }

    }

}