MH Maps Tweaker

Rearrange mice in the map

当前为 2015-06-29 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           MH Maps Tweaker
// @description    Rearrange mice in the map
// @author         Dusan Djordjevic
// @include        http://www.mousehuntgame.com/*
// @include        https://www.mousehuntgame.com/*
// @include        http://apps.facebook.com/mousehunt/*
// @include        https://apps.facebook.com/mousehunt/*
// @version        1.20 - Revamped maps - new UI
// @history        1.10 - No need to update script when new mice are out
// @history        1.00 - Initial release
// @namespace      MH Tweaks
// ==/UserScript==

VERSION = 1.20;

getLocations();

var LOCATIONS = {
    "Meadow": ["Field", "Flying", "Spotted", "Tiny"],
    "Town of Gnawnia": ["Brown", "Cowardly", "Dwarf", "Grey", "Master Burglar", "Nibbler", "White"],
    "Windmill": ["Spud"],
    "Harbour": ["Magic", "Pirate"],
    "Mountain": ["Black Widow", "Diamond", "Gold", "Silvertail"],
    "Slushy Shoreline": ["Living Ice", "Snow Soldier"],
    "Slushy Shoreline + Softserve charm": ["Yeti", "Icebreaker"],
    "King\'s Arms": [],
    "Tournament Hall": ["Lightning Rod"],
    "King\'s Gauntlet": [],
    "Calm Clearing": ["Bear", "Frog", "Moosker"],
    "Great Gnarled Tree": [],
    "Lagoon": ["Centaur", "Elven Princess", "Hydra", "Nomad", "Tiger"],
    "Claw Shot City": [],
    "Laboratory": ["Monster", "Steel"],
    "Town of Digby": ["Bionic", "Granite", "Zombie"],
    "Mousoleum": ["Bat", "Mummy", "Ravenous Zombie"],
    "Bazaar": ["Burglar"],
    "Training Grounds": ["Monk", "Ninja", "Worker"],
    "Dojo": ["Assassin", "Student of the Cheese Belt", "Student of the Cheese Claw", "Student of the Cheese Fang"],
    "Meditation Room": ["Hapless", "Master of the Cheese Belt", "Master of the Cheese Claw", "Master of the Cheese Fang"],
    "Pinnacle Chamber": ["Dojo Sensei", "Master of the Dojo"],
    "Catacombs": ["Giant Snail", "Keeper", "Ooze", "Scavenger", "Terror Knight"],
    "Forbidden Grove": ["Lycan", "Mutated Grey", "Mutated White", "Realm Ripper", "Vampire"],
    "Acolyte Realm": ["Acolyte", "Lich", "Spectre"],
    "S.S. Huntington III": ["Briegull", "Siren", "Swabbie", "Mermouse"],
    "Seasonal Garden": ["Harvest Harrier", "Icicle", "Puddlemancer", "Stinger"],
    "Zugzwang\'s Tower": ["Chess Master", "Mystic Bishop", "Mystic King", "Mystic Rook", "Technic Bishop", "Technic King", "Technic Rook"],
    "Crystal Library": ["Aether", "Effervescent", "Flutterby", "Infiltrator", "Pocketwatch", "Walker"],
    "Iceberg": ["Chipper", "General Drheller", "Iceblade", "Lady Coldsnap", "Living Salt", "Lord Splodington", "Polar Bear", "Princess Fist", "Snow Slinger", "Stickybomber"],
    "Iceberg - Hidden Depts": ["Frostwing Commander", "Frostlance Guard"],
    "Iceberg - Bombing Run": ["Heavy Blaster"],
    "Cape Clawed": ["Aged"],
    "Cape Clawed + Shell": ["Scout"],
    "Elub Shore": ["Mystic", "Pinchy", "Soothsayer"],
    "Elub Shore + Shell": ["Champion", "Protector", "Elub Chieftain"],
    "Nerg Plains": ["Chameleon", "Conjurer", "Conqueror", "Nerg Chieftain", "Finder", "Beast Tamer", "Alnilam"],
    "Derr Dunes": ["Derr Chieftain", "Mintaka", "Seer"],
    "Jungle of Dread": ["Chitinous", "Fetid Swamp", "Jurassic", "Magma Carrier", "Primal", "Pygmy Wrangler", "Stonework Warrior", "Swarm of Pygmy Mice", "Sylvan"],
    "Dracano": ["Draconic Warden", "Whelpling"],
    "Balack\'s Cove": ["Balack the Banished", "Brimstone", "Derr Lich", "Elub Lich", "Nerg Lich", "Riptide", "Twisted Fiend"],
    "Fiery Warpath": ["Magmarage", "Sand Cavalry", "Flame Ordnance", "Crimson Commander", "Caravan Guard"],
    "Fiery Warpath (Wave 3)": ["Crimson Titan"],
    "Muridae Market": ["Blacksmith", "Desert Architect", "Falling Carpet", "Mage Weaver", "Pie Thief", "Snake Charmer", "Spice Merchant", "Market Thief"],
    "Living Garden": ["Thirsty", "Thistle", "Strawberry Hotcakes", "Bark", "Calalilly", "Shroom", "Camoflower", "Carmine the Apothecary"],
    "Lost City": ["Cursed", "Essence Collector", "Ethereal Enchanter", "Ethereal Engineer", "Ethereal Librarian", "Ethereal Thief"],
    "Sand Dunes": ["Dunehopper", "Grubling", "Grubling Herder", "Quesodillo", "Sand Pilgrim", "Spiky Devil"],
    "Twisted Garden": ["Dehydrated", "Thorn", "Twisted Hotcakes", "Barkshell", "Twisted Lilly", "Fungal Spore", "Camofusion", "Twisted Carmine"],
    "Cursed City": ["Essence Guardian", "Cursed Enchanter", "Corrupt", "Cursed Engineer", "Cursed Thief", "Cursed Librarian"],
    "Sand Crypts": ["Sarcophamouse", "Sand Colossus", "Serpentine", "Scarab", "King Grub"],
    "Festive Snow Fort": ["Snowflake", "Nutcracker", "Candy Cane", "Snow Scavenger", "Snowglobe", "Ridiculous Sweater", "Triple Lutz", "Destructoy", "Snowblower", "Elf", "Missile Toe", "Wreath Thief", "Snow Fort", "Stocking"],
    "Gnawnian Express Station": ["Farrier", "Cute Crate Carrier", "Parlour Player", "Stoutgear", "Travelling Barber", "Crate Camo"],
    "Gnawnia Rift": [""],
    "Burroughs Rift": ["Lycanoid", "Portable Generator", "Assassin Beast"],
    "Whisker Woods Rift": ["Grizzled Silth", "Gilded Leaf", "Cherry Sprite", "Tree Troll"],
    "Whisker Woods Rift - Yellow": ["Lambent"],
    "Whisker Woods Rift - Red + Polluted parmesan": ["The Menace of the Rift"],
    "Fungal Cavern": ["Crystalline Slasher", "Splintered Stone Sentry", "Bitter Root", "Spore Muncher", "Crystal Queen", "Crystalback", "Dirt Thing"],
    "Sunken City - Carnivore Cove": ["Carnivore"],
    "Sunken City - Pearl Patch": ["Pearl Diver"]
};
    
var miceRows = {},
    miceMap = [],
    miceOrdered = '',
    remainingMice = '',
    locationsLoaded = false;
    
var mapButton = document.getElementsByClassName('treasureMap')[0];
mapButton.addEventListener('click', doMap, false);

function doMap() {
    var loaded = (document.getElementsByClassName('treasureMapPopup-mice-group-header').length == 0) ? false : true;
    
    if(loaded && locationsLoaded) {
        prepareMice();
        rearrangeMice();
    } else {
        setTimeout(doMap, 1000);
    }
}

function prepareMice() {
    var miceContainer = document.getElementsByClassName('treasureMapPopup-miceBlockRow')[0],
        mice = miceContainer.getElementsByClassName('mice')[0],
        miceContent = mice.getElementsByClassName('treasureMapPopup-leftBlock-content')[0],
        miceContentDefault = miceContent.getElementsByClassName('treasureMapPopup-leftBlock-content-default')[0],
        uncaughtmice = miceContentDefault.getElementsByClassName('uncaughtmice')[0],
        miceGroupContainer = uncaughtmice.getElementsByClassName('treasureMapPopup-mice-group-miceContainer')[0],
        miceMapUncaugth = miceGroupContainer.getElementsByClassName('treasureMapPopup-mice-group-mouse');

    miceRows = {};
    miceMap = [];
    
    for(var i=0; i<miceMapUncaugth.length; i++) {
        var mouseUncaughtElement = miceMapUncaugth[i],
            mouseName = mouseUncaughtElement.getAttribute("data-name");    
        miceRows[mouseName] = mouseUncaughtElement.innerHTML;
        miceMap.push(mouseName);
    }
    
    miceOrdered = '';
    remainingMice = '';
}
    
function rearrangeMice() {
    for(loc in LOCATIONS) {
        var mice = LOCATIONS[loc], miceList = '';
        for(key in mice) {
            var mouse = mice[key];
            if(arrayContains(miceMap, mouse)) {
                var mouseHtml = miceRows[mouse],
                    index = miceMap.indexOf(mouse);
                miceList += '<div onmouseout="app.views.TreasureMapView.map.removeHighlight(); return false;" onmouseover="app.views.TreasureMapView.map.highlightMouse(this);" data-name="'+mouse+'" class="treasureMapPopup-mice-group-mouse treasureMapPopup-searchIndex">'+mouseHtml+'</div>';
                //miceList += '<div class="treasureMap-mice-group-row">'+mouseHtml+'</div>';
                miceMap.splice(index, 1); 
            }       
        }
        if(miceList.length > 0) {
            miceOrdered += '<div class="treasureMapPopup-mice-group-header" style="margin-top:10px">'+loc+'</div>'+miceList;
        }    
    }
    
    for(var i=0; i<miceMap.length; i++) {
        var mouse = miceMap[i];
        //remainingMice += '<div class="treasureMap-mice-group-row">'+miceRows[mouse]+'</div>';
        remainingMice += '<div onmouseout="app.views.TreasureMapView.map.removeHighlight(); return false;" onmouseover="app.views.TreasureMapView.map.highlightMouse(this);" data-name="'+mouse+'" class="treasureMapPopup-mice-group-mouse treasureMapPopup-searchIndex">'+miceRows[mouse]+'</div>';
    }
    
    if(remainingMice != '') {
        miceOrdered += '<div class="treasureMapPopup-mice-group-header" style="margin-top:10px">Uncaught Mice</div>'+remainingMice;
    }

    var firstMiceGroup = document.getElementsByClassName('uncaughtmice')[0];
    firstMiceGroup.innerHTML = miceOrdered;
}

function arrayContains(a, obj) { 
    var i = a.length; 
    while(i--) { 
       if(a[i] === obj) { 
           return true; 
       } 
    } 
    return false; 
}

function getLocations() {
    var protocol = location.protocol,
        url = protocol + '//igrajtenis.net/mousehunt/maps_tweaker.php',
	    request = new XMLHttpRequest();
	
	request.onreadystatechange = function () {
	   if(request.readyState == 4) {
			if(request.status == 200) {
				var result = eval('('+request.responseText+')');
				if(result.status == 'ok') {
					LOCATIONS = result.data;
				}				
			}
			locationsLoaded = true;
		}
	}
	
	request.open("GET", url, true);
	request.send();
}