Library for e-mail forward highlighting

Enable user scripts to highlight forwarded e-mails

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/40782/265774/Library%20for%20e-mail%20forward%20highlighting.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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" });
}