Library for e-mail forward highlighting

Enable user scripts to highlight forwarded e-mails

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/40782/265774/Library%20for%20e-mail%20forward%20highlighting.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

function addStyles() {
    if (document.getElementById("email-quotes")) {
        console.log("Styles for e-mail quote highlighting already added, doing nothing");
        return;
    }
    console.log("Adding styles for e-mail quote highlighting");
    var styleNode = document.createElement('style');
    styleNode.setAttribute("type", "text/css");
    styleNode.id = "email-quotes";
    styleNode.innerHTML =
        'mark.quote1 { background: #eee }\n' +
        'mark.quote2 { background: #eef }\n' +
        'mark.quote3 { background: #efe }\n' +
        'mark.quote4 { background: #fee }\n' +
        'mark.quote5 { background: #ddd }\n' +
        'mark.quote6 { background: #ddf }\n' +
        'mark.quote7 { background: #dfd }\n' +
        'mark.quote8 { background: #fdd }\n';
    document.body.appendChild(styleNode);
}

function highlightQuotes() {
    addStyles();
    if (
        document.getElementsByClassName("quote1").length ||
        document.getElementsByClassName("quote2").length ||
        document.getElementsByClassName("quote3").length ||
        document.getElementsByClassName("quote4").length ||
        document.getElementsByClassName("quote5").length ||
        document.getElementsByClassName("quote6").length ||
        document.getElementsByClassName("quote7").length ||
        document.getElementsByClassName("quote8").length
    ) {
        console.log("E-mail quotes already highlighted, doing nothing");
        return;
    }
    console.log("Highlighting e-mail quotes");
    var context = document.querySelector("pre,blockquote,.Wordsection1,.MsoPlainText,body");
    var instance = new Mark(context);
    instance.markRegExp(/^(> *){1}([^>\n].*|)$/gm, {"className" : "quote1" });
    instance.markRegExp(/^(> *){2}([^>\n].*|)$/gm, {"className" : "quote2" });
    instance.markRegExp(/^(> *){3}([^>\n].*|)$/gm, {"className" : "quote3" });
    instance.markRegExp(/^(> *){4}([^>\n].*|)$/gm, {"className" : "quote4" });
    instance.markRegExp(/^(> *){5}([^>\n].*|)$/gm, {"className" : "quote5" });
    instance.markRegExp(/^(> *){6}([^>\n].*|)$/gm, {"className" : "quote6" });
    instance.markRegExp(/^(> *){7}([^>\n].*|)$/gm, {"className" : "quote7" });
    instance.markRegExp(/^(> *){8,}([^>\n].*|)$/gm, {"className" : "quote8" });
}