// ==UserScript==
// @name AO3: highlight fandoms in user page
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Highlight favourite fandoms on AO3 user dashboards
// @author CertifiedDiplodocus
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @match http://archiveofourown.org/users/*
// @match https://archiveofourown.org/users/*
// @exclude http://archiveofourown.org/users/YourUsernameHere/*
// @exclude https://archiveofourown.org/users/YourUsernameHere/*
// @grant none
// ==/UserScript==
//cannibalised from fangirlishness's ao3 Highlight tags
// tell eslinter that I am working with jquery
/* eslint-env jquery */
/* jshint esversion:6 */
(function($) {
'use strict';
/****** CONFIG ****************************************************/
// Favourite fandoms to highlight (default colour and/or bold)
let fandomsToHighlight = ["Original Work", "Critical Role", "Harry Potter", "Naruto", "Scooby Doo",
"Stranger Things", "Holmes", "^Avatar:"];
// !!!! BUG: can't seem to escape \( or \).
// !!!! Temporary workaround: use "." (= "any character" in regex).
// fandomsToHighlight = ["The Avengers \(Marvel\)", "Doctor Who"]; // this breaks the script
fandomsToHighlight = ["Original Work",
"Alice in Wonderland .2010.", "All Creatures Great and Small", "Attack on Titan",
"^Avatar:", "Black Books", "Blake's 7", "Broadchurch", "Buffy the Vampire Slayer",
"Cabin Pressure", "Cinderbrush", "Colbert", "Critical Role",
"Daily Show", "Discworld", "Dishonored .Video Games.", "Doctor Who", "Dresden Files",
"Fake News", "Firefly", "Fullmetal Alchemist", "Good Omens", "Gravity Falls", "Harry Potter", "Hornblower", "House M\.D\.",
"Indiana Jones", "Jonathan Strange & Mr Norrell", "Kung Fu Panda", "Life On Mars",
"MASH", "Mob Psycho 100", "Monty Python's Flying Circus", "Mushishi", "My Hero Academia",
"Marvel Cinematic Universe", "^Marvel$", // **MCU
"The Avengers .Marvel", "The Avengers - Ambiguous", // **MCU**
"^Captain America", "Guardians of the Galaxy", "^Iron Man .Movies.", // **MCU**
"^Thor .Movies.", "^Doctor Strange", "^Captain Marvel", // **MCU**
"Naruto", "One-Punch Man", "Pirates of the Caribbean", "Pokemon - All Media Types", "Pokemon .Anime.",
"Red Dwarf", "Rick and Morty", "Sagas of Sundry: Dread",
"Scoob and Shag", "Scooby.Doo", "Sherlock", "Sleepy Hollow", "Spider-Man: Into the Spider-Verse",
"^Star Trek$", "Star Trek: Alternate Original Series", "Star Trek: The Next Generation", "Star Trek: The Original Series",
"Star Wars", "Steven Universe", "Stranger Things", "Swallows and Amazons",
"Team Fortress 2", "The Brittas Empire", "The Magnus Archives", "The Thick of It",
"The Umbrella Academy", "The X-Files", "Tintin", "Welcome to Night Vale"];
// Fandoms to highlight in a different colour (specify colour for each).
// If a fandom appears in both lists, the page will show the custom colour
// (so you can add a fandom here without needing it to remove it from the main list above)
let fandomsInColour = {"Fandom1":"#fda7d1", // pink
"Fandom2":"#adf7d1", // light green
"^Putin RPF":"red", // regexp patterns can be used
"somethingelse": "blue", // named colors work too
};
// SOME NOTES ON REGEXP AND PATTERN MATCHING
// By default, the search matches any string containing the search text:
// "Sherlock" matches "Sherlock (TV)", "Sherlock Holmes" and "Young Sherlock Holmes"
// To match exactly that, use the regex symbols "^" (string start) and/or "$" (string end):
// "^Sherlock" matches "Sherlock Holmes" but not "Young Sherlock Holmes"
// "^Avatar:" matches both "Avatar: the Last Air
// SPECIAL CHARACTERS: If a fandom contains any of the following characters
// . + * ? ^ $ ( ) [ ] { } | \
// they must be preceded (escaped) with a backslash (e.g. "House M\.D\.")
// for the script to work.
// Use bold text, highlighting, or both?
let boldIsOn = true;
let highlightIsOn = true;
let highlightDefaultCol = 'LightYellow';
let customHighlightIsOn = true; // enable or disable custom highlighting
/****************************************************************/
$('.fandom.listbox.group li').each(function() { //do I need to include "li"?
let $list = $(this);
$list.find('a').each(function() {
let $fandom = $(this);
let text = $fandom.text();
// let $fandomLine = $(this).closest("li"); //whole list item (including number of fics) - currently not formatted
// alternative approach: run regexp on all fandoms ("Naruto"|"Harry Potter"|...) instead of iterating through the array
// let pattern1 = new RegExp(fandomsToHighlight.join("|"));
for (var i = 0; i<fandomsToHighlight.length; i++) {
let pattern = new RegExp(fandomsToHighlight[i], "g")
if(text.match(pattern) != null) {
if(highlightIsOn) {
highlightTag($fandom, highlightDefaultCol)
}
if(boldIsOn) {
boldFandom($fandom)
}
}
}
// fandoms with custom highlighting, if applicable
if (customHighlightIsOn) {
for (let key in fandomsInColour) {
let pattern2 = new RegExp(key, "g")
if(text.match(pattern2) != null) {
if(highlightIsOn === true) {
highlightTag($fandom, fandomsInColour[key]);
}
if(boldIsOn === true) {
boldFandom($fandom);
}
}
}
}
});
});
function highlightTag($fandom, color) {
$fandom.css('background-color', color);
}
function boldFandom($fandom) {
$fandom.css('font-weight', 'bold');
}
function comboFormat($fandom, color, weight) { // should I specify defaults? e.g. weight = 'normal'
$fandom.css({'background-color': color, 'font-weight': weight});
}
})(jQuery);