// ==UserScript==
// @name MouseHunt - GWH Map Color Coder 2019
// @author Tran Situ (tsitu)
// @namespace https://gf.qytechs.cn/en/users/232363-tsitu
// @version 1.0
// @description Color codes mice on GWH maps according to decorations & cheese
// @match *.mousehuntgame.com/*
// ==/UserScript==
const sportMice = [
"Sporty Ski Instructor",
"Young Prodigy Racer",
"Toboggan Technician",
"Free Skiing",
"Nitro Racer",
"Rainbow Racer",
"Double Black Diamond Racer",
"Black Diamond Racer"
];
const toyMice = [
"Nutcracker",
"Toy",
"Slay Ride",
"Squeaker Claws",
"Destructoy",
"Toy Tinkerer",
"Mad Elf",
"Elf"
];
const ornamentalMice = [
"Christmas Tree",
"Stocking",
"Candy Cane",
"Ornament",
"Missile Toe",
"Wreath Thief",
"Ribbon",
"Snowglobe"
];
const snowMice = [
"Snow Fort",
"Snowball Hoarder",
"S.N.O.W. Golem",
"Snow Sorceress",
"Reinbo",
"Tundra Huntress",
"Stuck Snowball",
"Snow Boulder"
];
const fireworksMice = [
"Frightened Flying Fireworks",
"New Year's",
"Party Head"
];
const glazyMice = ["Glazy", "Joy"];
const pecanMice = [
"Borean Commander",
"Builder",
"Frigid Foreman",
"Glacia Ice Fist",
"Great Winter Hunt Impostor",
"Iceberg Sculptor",
"Naughty Nougat",
"Nice Knitting",
"Ridiculous Sweater",
"Snow Golem Jockey",
"Snow Scavenger",
"Snowblower"
];
const sbMice = [
"Mouse of Winter Future",
"Mouse of Winter Past",
"Mouse of Winter Present",
"Scrooge"
];
const standardMice = [
"Confused Courier",
"Gingerbread",
"Greedy Al",
"Hoarder",
"Miser",
"Present",
"Triple Lutz"
];
const gwhMaps = [
"Nice List",
"Rare Nice List",
"Naughty List",
"Rare Naughty List"
];
function colorize() {
let sportColor = "#c97c49"; // brown-ish
let sportCount = 0;
let toyColor = "#f06a60"; // red
let toyCount = 0;
let ornamentalColor = "#5ae031"; // green
let ornamentalCount = 0;
let snowColor = "#4fcaf0"; // blue
let snowCount = 0;
let fireworksColor = "#cd87ff"; // light purple
let fireworksCount = 0;
let glazyColor = "#ff9966"; // orange
let glazyCount = 0;
let pecanColor = "#ffff66"; // yellow
let pecanCount = 0;
let sbColor = "#66ffff"; // teal-ish
let sbCount = 0;
let standardColor = "#afa500"; // mountain dew-ish
let standardCount = 0;
const isChecked =
localStorage.getItem("highlightPref") === "uncaught-only" ? true : false;
const isCheckedStr = isChecked ? "checked" : "";
if (
document.querySelectorAll(".treasureMapView-goals-group-goal").length === 0
) {
return;
}
document.querySelectorAll(".treasureMapView-goals-group-goal").forEach(el => {
el.querySelector("span").style = "color: black; font-size: 11px;";
const mouseName = el.querySelector(".treasureMapView-goals-group-goal-name")
.textContent;
if (sportMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = sportColor;
if (el.className.indexOf(" complete ") < 0) {
sportCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
} else if (toyMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = toyColor;
if (el.className.indexOf(" complete ") < 0) {
toyCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
} else if (ornamentalMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = ornamentalColor;
if (el.className.indexOf(" complete ") < 0) {
ornamentalCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
} else if (snowMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = snowColor;
if (el.className.indexOf(" complete ") < 0) {
snowCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
} else if (fireworksMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = fireworksColor;
if (el.className.indexOf(" complete ") < 0) {
fireworksCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
} else if (glazyMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = glazyColor;
if (el.className.indexOf(" complete ") < 0) {
glazyCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
} else if (pecanMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = pecanColor;
if (el.className.indexOf(" complete ") < 0) {
pecanCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
} else if (sbMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = sbColor;
if (el.className.indexOf(" complete ") < 0) {
sbCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
} else if (standardMice.indexOf(mouseName) > -1) {
el.style.backgroundColor = standardColor;
if (el.className.indexOf(" complete ") < 0) {
standardCount++;
} else {
if (isChecked) el.style.backgroundColor = "white";
}
}
});
// Remove existing GWH Map related elements before proceeding
document.querySelectorAll(".tsitu-gwh-map").forEach(el => el.remove());
const masterDiv = document.createElement("div");
masterDiv.className = "tsitu-gwh-map";
masterDiv.style =
"display: inline-flex; margin-bottom: 10px; width: 100%; text-align: center; line-height: 1.5; overflow: hidden";
const spanStyle =
"; width: auto; padding: 5px; font-weight: bold; font-size: 12.5px";
const strikethroughStyle = "; text-decoration: line-through";
const sportSpan = document.createElement("span");
sportSpan.style = "background-color: " + sportColor + spanStyle;
if (sportCount === 0) {
sportSpan.style =
"background-color: " + sportColor + spanStyle + strikethroughStyle;
}
sportSpan.innerHTML = "Sport<br>" + sportCount;
const toySpan = document.createElement("span");
toySpan.style = "background-color: " + toyColor + spanStyle;
if (toyCount === 0) {
toySpan.style =
"background-color: " + toyColor + spanStyle + strikethroughStyle;
}
toySpan.innerHTML = "Toy<br>" + toyCount;
const ornamentalSpan = document.createElement("span");
ornamentalSpan.style = "background-color: " + ornamentalColor + spanStyle;
if (ornamentalCount === 0) {
ornamentalSpan.style =
"background-color: " + ornamentalColor + spanStyle + strikethroughStyle;
}
ornamentalSpan.innerHTML = "Ornament<br>" + ornamentalCount;
const snowSpan = document.createElement("span");
snowSpan.style = "background-color: " + snowColor + spanStyle;
if (snowCount === 0) {
snowSpan.style =
"background-color: " + snowColor + spanStyle + strikethroughStyle;
}
snowSpan.innerHTML = "Snow<br>" + snowCount;
const fireworksSpan = document.createElement("span");
fireworksSpan.style = "background-color: " + fireworksColor + spanStyle;
if (fireworksCount === 0) {
fireworksSpan.style =
"background-color: " + fireworksColor + spanStyle + strikethroughStyle;
}
fireworksSpan.innerHTML = "Fireworks<br>" + fireworksCount;
const glazySpan = document.createElement("span");
glazySpan.style = "background-color: " + glazyColor + spanStyle;
if (glazyCount === 0) {
glazySpan.style =
"background-color: " + glazyColor + spanStyle + strikethroughStyle;
}
glazySpan.innerHTML = "Glazy<br>" + glazyCount;
const pecanSpan = document.createElement("span");
pecanSpan.style = "background-color: " + pecanColor + spanStyle;
if (pecanCount === 0) {
pecanSpan.style =
"background-color: " + pecanColor + spanStyle + strikethroughStyle;
}
pecanSpan.innerHTML = "Pecan<br>" + pecanCount;
const sbSpan = document.createElement("span");
sbSpan.style = "background-color: " + sbColor + spanStyle;
if (sbCount === 0) {
sbSpan.style =
"background-color: " + sbColor + spanStyle + strikethroughStyle;
}
sbSpan.innerHTML = "SB+<br>" + sbCount;
const standardSpan = document.createElement("span");
standardSpan.style = "background-color: " + standardColor + spanStyle;
if (standardCount === 0) {
standardSpan.style =
"background-color: " + standardColor + spanStyle + strikethroughStyle;
}
standardSpan.innerHTML = "Standard<br>" + standardCount;
// Highlight uncaught only feature
const highlightLabel = document.createElement("label");
highlightLabel.htmlFor = "tsitu-highlight-box";
highlightLabel.innerText = "Highlight uncaught mice only";
const highlightBox = document.createElement("input");
highlightBox.type = "checkbox";
highlightBox.name = "tsitu-highlight-box";
highlightBox.style.verticalAlign = "middle";
highlightBox.checked = isChecked;
highlightBox.addEventListener("click", function() {
if (highlightBox.checked) {
localStorage.setItem("highlightPref", "uncaught-only");
} else {
localStorage.setItem("highlightPref", "all");
}
colorize();
});
const highlightDiv = document.createElement("div");
highlightDiv.className = "tsitu-gwh-map";
highlightDiv.style =
"margin-bottom: 5px; width: 35%; border: 1px dotted black";
highlightDiv.appendChild(highlightBox);
highlightDiv.appendChild(highlightLabel);
// Assemble masterDiv
masterDiv.appendChild(sportSpan);
masterDiv.appendChild(toySpan);
masterDiv.appendChild(ornamentalSpan);
masterDiv.appendChild(snowSpan);
masterDiv.appendChild(fireworksSpan);
masterDiv.appendChild(glazySpan);
masterDiv.appendChild(pecanSpan);
masterDiv.appendChild(sbSpan);
masterDiv.appendChild(standardSpan);
// Inject into DOM
const insertEl = document.querySelector(
".treasureMapView-leftBlock .treasureMapView-block-content"
);
if (
insertEl &&
document.querySelector(
".treasureMapManagerView-header-navigation-item.tasks.active"
)
) {
insertEl.insertAdjacentElement("afterbegin", highlightDiv);
insertEl.insertAdjacentElement("afterbegin", masterDiv);
}
// "Goals" button
document.querySelector("[data-type='show_goals']").onclick = function() {
colorize();
};
}
// Listen to XHRs, opening a map always at least triggers board.php
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
this.addEventListener("load", function() {
const mapEl = document.querySelector(".treasureMapManagerView-task-name");
if (mapEl) {
const mapName = mapEl.textContent;
if (mapName && gwhMaps.indexOf(mapName) > -1) {
colorize();
}
}
});
originalOpen.apply(this, arguments);
};