Greasy Fork

Greasy Fork is available in English.

Empyrean Sky Palace Treasure Map Helper

Categorize missing mice

当前为 2022-05-21 提交的版本,查看 最新版本

// ==UserScript==
// @name        Empyrean Sky Palace Treasure Map Helper
// @namespace   Violentmonkey Scripts
// @match       http://www.mousehuntgame.com/*
// @match       https://www.mousehuntgame.com/*
// @version     0.1
// @author      viettrung9012
// @description Categorize missing mice
// @include		http://apps.facebook.com/mousehunt/*
// @include		https://apps.facebook.com/mousehunt/*
// @license     MIT
// ==/UserScript==

const spMaps = [
  "Empyrean Sky Palace Treasure Chest",
  "Rare Empyrean Sky Palace Treasure Chest"
];

const lookUp = {
  1019: ['launchPad'],
  1037: ['launchPad'],
  1055: ['launchPad'],
  1060: ['launchPad'],
  1045: ['wardens'],
  1029: ['wardens'],
  1031: ['wardens'],
  1069: ['wardens'],
  1014: ['pirates', 'common'],
  1022: ['pirates', 'common'],
  1023: ['pirates', 'common'],
  1066: ['pirates', 'common'],
  1048: ['pirates', 'common'],
  1040: ['pirates', 'common'],
  1084: ['pirates', 'sp'],
  1032: ['physical', 'common'],
  1034: ['physical', 'common'],
  1059: ['physical', 'common'],
  1057: ['physical', 'hai'],
  1044: ['physical', 'hai'],
  1083: ['physical', 'sp'],
  1017: ['shadow', 'common'],
  1043: ['shadow', 'common'],
  1065: ['shadow', 'common'],
  1051: ['shadow', 'hai'],
  1050: ['shadow', 'hai'],
  1085: ['shadow', 'sp'],
  1070: ['tactical', 'common'],
  1033: ['tactical', 'common'],
  1049: ['tactical', 'common'],
  1018: ['tactical', 'hai'],
  1067: ['tactical', 'hai'],
  1086: ['tactical', 'sp'],
  1052: ['arcane', 'common'],
  1053: ['arcane', 'common'],
  1054: ['arcane', 'common'],
  1056: ['arcane', 'hai'],
  1016: ['arcane', 'hai'],
  1074: ['arcane', 'sp'],
  1062: ['forgotten', 'common'],
  1063: ['forgotten', 'common'],
  1020: ['forgotten', 'common'],
  1061: ['forgotten', 'hai'],
  1030: ['forgotten', 'hai'],
  1078: ['forgotten', 'sp'],
  1042: ['hydro', 'common'],
  1058: ['hydro', 'common'],
  1021: ['hydro', 'common'],
  1041: ['hydro', 'hai'],
  1035: ['hydro', 'hai'],
  1079: ['hydro', 'sp'],
  1068: ['dragon', 'common'],
  1028: ['dragon', 'common'],
  1027: ['dragon', 'common'],
  1046: ['dragon', 'hai'],
  1026: ['dragon', 'hai'],
  1077: ['dragon', 'sp'],
  1025: ['law', 'common'],
  1064: ['law', 'common'],
  1039: ['law', 'common'],
  1015: ['law', 'hai'],
  1038: ['law', 'hai'],
  1080: ['law', 'sp'],
  1047: ['others', 'common'],
  1075: ['others', 'sp'],
  1076: ['others', 'sp'],
  1081: ['others', 'sp'],
  1082: ['others', 'sp'],
  1087: ['others', 'sp']
}

function buildMiceDiv(parentEl, title, els) {
  if (els.length > 0) {
    let miceDiv = document.createElement('div');
    miceDiv.innerHTML = "<div style=\"font-style: italic;\">" + title + "</div>";
    els.forEach(el => miceDiv.appendChild(el));
    parentEl.appendChild(miceDiv);
  }
}

const commonTitle = "Common (available in LAI, HAI and SP)";
const haiTitle = "HAI only";
const spTitle = "Sky Palace only"

function categorize() {
  const categorized = {
    launchPad: [],
    wardens: [],
    pirates: {
      common: [],
      sp: []
    },
    others: {
      common: [],
      sp: []
    }
  };

  const types = ['physical', 'shadow', 'tactical', 'arcane', 'forgotten', 'hydro', 'dragon', 'law'];

  types.forEach(type => categorized[type] = {
    common: [],
    hai: [],
    sp: []
  })
  
  const missingMiceDiv = document.querySelector('.treasureMapView-goals-groups').children[1];

  Array.from(missingMiceDiv.children).forEach(child => {
    const miceId = parseInt(child.getAttribute('data-unique-id'));
    let arr = lookUp[miceId].reduce((curVal, path) => {
        return curVal[path];
      }, categorized);
      arr.push(child);
  });
  
  if (categorized.launchPad.length > 0) {
    let launchPadDiv = document.createElement('div');
    launchPadDiv.innerHTML = "<span style=\"font-weight: bold; font-size: 12px\">Launchpad</span>";
    buildMiceDiv(launchPadDiv, "", categorized.launchPad);
    launchPadDiv.innerHTML = launchPadDiv.innerHTML + "<br />"
    missingMiceDiv.appendChild(launchPadDiv);
  }
  
  types.forEach(type => {
    var typeDiv;
    let { common : commonMice, hai : haiMice, sp : spMice } = categorized[type];
    if (commonMice.length > 0 || haiMice.length > 0 || spMice.length > 0) {
      typeDiv = document.createElement('div');
      typeDiv.innerHTML = "<span style=\"font-weight: bold; font-size: 12px\">" + type.charAt(0).toUpperCase() + type.slice(1); + "</span>";
    }
    buildMiceDiv(typeDiv, commonTitle, commonMice);
    buildMiceDiv(typeDiv, haiTitle, haiMice);
    buildMiceDiv(typeDiv, spTitle, spMice);
    if (typeDiv.innerHTML !== '') {
      typeDiv.innerHTML = typeDiv.innerHTML + "<br />"
      missingMiceDiv.appendChild(typeDiv);
    }
  });
  
  if (categorized.wardens.length > 0) {
    let wardensDiv = document.createElement('div');
    wardensDiv.innerHTML = "<span style=\"font-weight: bold; font-size: 12px\">Wardens</span>";
    buildMiceDiv(wardensDiv, "", categorized.wardens);
    wardensDiv.innerHTML = wardensDiv.innerHTML + "<br />"
    missingMiceDiv.appendChild(wardensDiv);
  }
  
  if (categorized.pirates.common.length > 0 || categorized.pirates.sp.length > 0) {
    let piratesDiv = document.createElement('div');
    piratesDiv.innerHTML = "<span style=\"font-weight: bold; font-size: 12px\">Pirates</span>";
    buildMiceDiv(piratesDiv, commonTitle, categorized.pirates.common);
    buildMiceDiv(piratesDiv, spTitle, categorized.pirates.sp);
    piratesDiv.innerHTML = piratesDiv.innerHTML + "<br />"
    missingMiceDiv.appendChild(piratesDiv);
  }
  
  if (categorized.others.common.length > 0 || categorized.others.sp.length > 0) {
    let othersDiv = document.createElement('div');
    othersDiv.innerHTML = "<span style=\"font-weight: bold; font-size: 12px\">Richard and rest of Sky Palace</span>";
    buildMiceDiv(othersDiv, commonTitle, categorized.others.common);
    buildMiceDiv(othersDiv, spTitle, categorized.others.sp);
    othersDiv.innerHTML = othersDiv.innerHTML + "<br />"
    missingMiceDiv.appendChild(othersDiv);
  }
}

// Listen to XHRs, opening a map always at least triggers board.php
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async) {
    this.addEventListener("load", function () {
      if (url.endsWith("board.php")) {
        const mapEl = document.querySelector(".treasureMapView-mapMenu-rewardName");
        if (mapEl) {
          const mapName = mapEl.textContent;
          if (mapName && spMaps.indexOf(mapName) > -1) {
            categorize();
          }
        }
      }
  });
  originalOpen.apply(this, arguments);
};