AO3: highlight author fandoms

Highlight favourite fandoms in user page

// ==UserScript==
// @name         AO3: highlight author fandoms
// @namespace    https://greasyfork.org/en/users/757649-certifieddiplodocus
// @version      1.1
// @description  Highlight favourite fandoms in user page
// @author       CertifiedDiplodocus
// @require      http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @match     http*://archiveofourown.org/users/*
// @exclude   http*://archiveofourown.org/users/*/works*
// @exclude   http*://archiveofourown.org/users/*/pseuds/*/works*
// @grant        none
// ==/UserScript==

    //cannibalised from fangirlishness's ao3 Highlight tags V1, with thanks

/* eslint-env jquery */ //           allows jQuery
/* jshint esversion:6 */ //          allows "let"

(function($) {
    'use strict';

    // select the list of fandoms
    $('.fandom.listbox.group li').each(function() {

        // check that config extension is loaded, throw error if not
        if (!window.fandomHighlighterConfig) {throw new Error("AO3 Fandom Highlighter CONFIG not loaded")}; // HALT!

        // pass variables from config script
        let config = window.fandomHighlighterConfig;
        let fandomsToHighlight = config.fandomsToHighlight,
            fandomsInColour = config.fandomsInColour,
            highlightIsOn = config.highlightIsOn,
            boldIsOn = config.boldIsOn,
            customHighlightIsOn = config.customHighlightIsOn,
            highlightDefaultCol = config.highlightDefaultCol;

        // get fandoms
        let $list = $(this);
        $list.find('a').each(function() {
            let $fandom = $(this);
            let text = $fandom.text();
//            let $fandomLine = $(this).closest("li"); //whole list item (i.e. to also highlight the number of fics)

            // iterate through fandoms, check against list, then highlight and/or bold
            for (var i = 0; i<fandomsToHighlight.length; i++) {
                let pattern = new RegExp(fandomsToHighlight[i], "gi") //global case-insensitive
                if(text.match(pattern) != null) {
                    if(highlightIsOn) highlightFandom($fandom, highlightDefaultCol)
                    if(boldIsOn) boldFandom($fandom)
                }
            }

            // custom highlighting, if applicable
            if (customHighlightIsOn) {
                for (let key in fandomsInColour) {
                    let pattern2 = new RegExp(key, "gi") //global case-insensitive
                    if(text.match(pattern2) != null) {
                        highlightFandom($fandom, fandomsInColour[key])
                        if(boldIsOn) boldFandom($fandom);
                    }
                }
            }

        });
    });

    function highlightFandom($fandom, color) {
        $fandom.css('background-color', color);
    }
    function boldFandom($fandom) {
        $fandom.css('font-weight', 'bold');
    }

})(jQuery);