// ==UserScript==
// @name Special Filters
// @namespace http://tampermonkey.net/
// @version 0.9
// @description New way of catagorized filters
// @author CzPeet
// @match https://www.munzee.com/specials*
// @icon https://www.google.com/s2/favicons?domain=munzee.com
// @update https://greasyfork.org/en/scripts/433078-special-filters
// @grant none
// ==/UserScript==
var imgs = [];
var filterimgcategchboxes = [];
var imgPrefix = "https://munzee.global.ssl.fastly.net/images/pins/";
var filterHelper = "";
var filterImgs = null;
var disabledFilterImgs = [];
var needMapRefresh = true;
var isMapLoaded = false;
var Mythologicals = ["theunicorn","hippocampunicorn","battleunicorn","leprechaun","dwarfleprechaun","goblinleprechaun","dragon","chinesedragon","wyverndragon","yeti","reptoidyeti","lycanthropeyeti","faun","centaurfaun","krampusfaun","hydra","cerberushydra","cthulhuhydra","pegasus","alicornpegasus","griffinpegasus","cyclops","balorcyclops","minotaurcyclops","mermaid","hotspringmermaid","melusinemermaid","fairy","dryadfairy","wildfirefairy","banshee","harpybanshee","witchbanshee","nymph","elfnymph","vampirenymph"];
var RetiredMyths = ["retiredunicorn","retiredleprechaun","retireddragon","retiredyeti","retiredfaun","retiredhydra","retiredpegasus","retiredcyclops","retiredmermaid","retiredfairy","retiredbanshee","retirednymph"];
var AlternaMyths = ["cherub","chimera","fairygodmother","firepegasus","gnomeleprechaun","gorgon","icedragon","motherearth","ogre","rainbowunicorn","sasquatchyeti","siren"];
var ModernMyths = ["aphrodite","glasses","shell-phone","poseidon","trident","lifebuoy","hades","bident","firestarter"];
var FancyFlats = ["beachflatrob","coldflatrob","tuxflatrob","face-offflatmatt","footyflatmatt","matt'erupflatmatt","internationellesflatlou","polkadotflatlou","teamgbflatlou"];
var PhantomFlats = ["phantomflatrob", "phantomflatmatt", "phantomflatlou"];
var PouchCreations = ["tuli","tuliferno","tulimber","gleamingtuli","gleamingtuliferno","gleamingtulimber","vesi","vesial","vesisaur","gleamingvesi","gleamingvesial","gleamingvesisaur","muru","muruchi","murutain","gleamingmuru","gleamingmuruchi","gleamingmurutain","mitmegu","jootmegu","lokemegu","rohimegu","murinmegu","ohkmegu","urgasmegu","pimedus","puffle","puflawn","pufrain","magnetus","elekjoud","elekter","elektrivool","hadavale"];
var ZombiePouchs = ["zombietuli","zombievesi","zombiemuru","zombiepimedus","zombiepuffle","zombiemagnetus","zombieelekter"];
var Nomads = ["nomad","nomadvirtual","nomadmystery","jewelthiefnomad","bellhopnomad","piratenomad","warriornomad","travelernomad","seasonalnomad","virtualflatnomad","coupechampionnomad","virtualzeecretagentnomad","zeecretagentnomad","virtualgamingnomad","gamingnomad","virtualjewelthiefnomad","virtualwarriornomad","virtualbellhopnomad","jason4zeesnomad","killermask"];
var FunfinityStones = ["akvamariin","ametust","oniks","roosa","rubiin","safiir","smaragd","teemant","topaas","tsitriin","vikerkaar"];
var MechZBouncers = ["arcticlasershark","botwurst","carafeborg","cybersaurusrex","cyborgsanta","dronut","fr057y","geologgersrumbot","gingermechman","goldenlasershark","goldncoinsrumbot","kingc0g","lasershark","mechanic4k3","monk3y","mumm33","negsrumbot","prim8","rud01ph","s4rc0ph4gus","sc4rab","scgsrumbot","spyderbot","steinbot","krampbot","31f","reindroid"];
var GardenGnomes = ["10thmunzeebirthdayhat","archerygardengnome","astronautgardengnome","aussieexplorergardengnome","awardshowgardengnome","baseballgardengnome","basketballgardengnome","cricketgardengnome","footballgardengnome","gardengnome","gnomearcheryhood","gnomeastronauthelmet","gnomebearskinhat","gnomecatcherscap","gnomeclubcap","gnomeexplorerhat","gnomeheaderhat","gnomeheadphones","gnomeheelfliphat","gnomehockeyhelmet","gnomeminerhat","gnomenogginnet","gnometouchdowntopper","goldminergardengnome","icehockeygardengnome","queen'sguardsmangardengnome","runninggardengnome","skateboardinggardengnome","soccergardengnome","cyclinggardengnome"];
var Destinations = ["skyland1","skyland2","skyland3","skyland4","skyland5","skyland6","skyland7","skyland8","skyland9","skyland10","treehouse1","treehouse2","treehouse3","treehouse4","treehouse5","treehouse6","treehouse7","treehouse8","treehouse9","treehouse10"];
var EvoBouncers = ["boxjellyfish","goldenjellyfish","pb&jellyfish","limebutterfly","monarchbutterfly","morphobutterfly","poisondartfrog","tomatofrog","treefrog","seaturtle","snappingturtle","taekwondotortoise","honeybee","queenbee","wallabee"];
var Scatters = ["fire","frozengreenie","waterdroplet","feather","goldenfeather","charge","tree","redapple","cherryblossom","peach","pear","pecan","acorn","deadbranch","cardinalfeather","blackhole","planet","spaceship","lostkey","lostsock","meteor","satellite","scattered","boulder","flamingarrow","sc4rab","ankhartifact","ouroborosartifact","djedartifact","scarabartifact","eyeofraartifact","shenartifact","canopicjarartifact","sesenartifact","wasscepterartifact","sistrumartifact","sistrumartifact","tyetartifact","eyeofhorusartifact","sweettreats","scgsresellerpackage","geologgersresellerpackage","gold'ncoinsresellerpackage","negsresellerpackage","cloverleaf","goldenclover","dossier","infraredvirtual","lasertrail1","lasertrail2","lasertrail3","pixelpresent","undercoveragent","liaisonagent","maplepawn","mapleknight","maplebishop","maplerook","maplequeen","mapleking","walnutpawn","walnutknight","walnutbishop","walnutrook","walnutqueen","walnutking","leapfrog","munch-man","runzeerob","goldcoin","fly","ghostzee","1stroll","bowling-1stroll","2ndroll","bowling-2ndroll"];
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function restructureImages() {
//Wait until the progressbar is hidden
while ($("#map-box-special-loading").is(':visible'))
{
isMapLoaded = true;
//wait
await sleep(500);
}
if (!isMapLoaded)
{
return;
}
else
{
isMapLoaded = false;
}
//remove original filter_all button
$('#filter_all').remove();
filterImgs = $('#filterimgs');
filterImgs.prev().remove(); //Filters label removed
imgs = filterImgs[0].getElementsByTagName('img');
AddCategory("Myths", Mythologicals);
AddCategory("Retired Myths", RetiredMyths);
AddCategory("AlternaMyths", AlternaMyths);
AddCategory("Modern Myths", ModernMyths);
AddCategory("F.Flats", FancyFlats);
AddCategory("Phantoms", PhantomFlats);
AddCategory("Pouches", PouchCreations);
AddCategory("Zombies", ZombiePouchs);
AddCategory("Nomads", Nomads);
AddCategory("F.Stones", FunfinityStones);
AddCategory("MechZ", MechZBouncers);
AddCategory("Gnomes", GardenGnomes);
AddCategory("Destinations", Destinations);
AddCategory("EvoBouncers", EvoBouncers);
AddCategory("Scatters", Scatters);
AddCategory("UnCategorized");
filterImgs.empty();
filterImgs.html(filterHelper);
filterHelper = "";
//Add to all img the click eventListener
imgs = filterImgs[0].getElementsByTagName('img');
Array.from(imgs).forEach(function(img) {
img.addEventListener('click', FilterImgClick);
img.setAttribute("style", "cursor:pointer");
img.setAttribute("title", img.currentSrc.substring(img.currentSrc.lastIndexOf("/")+1,img.currentSrc.lastIndexOf(".")));
});
//Add to all category checkbox the click eventListener
filterimgcategchboxes = filterImgs[0].getElementsByClassName('filterimgcategchbox');
Array.from(filterimgcategchboxes).forEach(function(filterimgcategchbox) {
filterimgcategchbox.addEventListener('click', FilterImgCategChBoxClick);
});
//refresh
refreshMap();
}
function AddCategory(categName, array = null)
{
//Div
var categDIV = document.createElement('DIV');
categDIV.setAttribute("id", categName+"_Category");
categDIV.setAttribute("class", "filterImgDiv");
categDIV.setAttribute("style", "border: solid 1px darkgray; padding: 2px; display: inline-block; width: fit-content;");
//CheckBox show/hide all
var categChBox = document.createElement('INPUT');
categChBox.setAttribute("id", categName+'_ChBox');
categChBox.setAttribute("type", "checkbox");
categChBox.setAttribute("class", "filterimgcategchbox");
categChBox.setAttribute("checked", "checked");
//Label
var categLabel = document.createElement('LABEL');
categLabel.setAttribute("id", categName+'_Label');
categLabel.setAttribute("style", "padding-left: 10px");
categLabel.innerText = categName + ": ";
categDIV.appendChild(categChBox);
categDIV.appendChild(categLabel);
var addedAtLeatOne = false;
if (array != null)
{
for (let a = 0; a < array.length; a++)
{
for (let i = 0; i < imgs.length; i++)
{
if (imgs[i].src == imgPrefix + array[a] + ".png")
{
categDIV.appendChild(imgs[i]);
addedAtLeatOne = true;
}
}
}
}
else
{
for (let i = imgs.length-1; i >= 0; i--)
{
categDIV.appendChild(imgs[i]);
addedAtLeatOne = true;
}
}
if (addedAtLeatOne)
{
filterHelper += categDIV.outerHTML;
}
}
function FilterImgClick(sender)
{
if (sender.target.classList.contains("filterdisabled"))
{
enableFilter(sender.target);
}
else
{
disableFilter(sender.target);
}
if (needMapRefresh)
{
refreshMap();
}
}
function FilterImgCategChBoxClick(sender)
{
needMapRefresh = false;
imgs = sender.target.closest("div").getElementsByTagName('img');
if (sender.target.checked)
{
Array.from(imgs).forEach(function(img) {
if (img.classList.contains("filterdisabled"))
{
enableFilter(img);
}
});
}
else
{
Array.from(imgs).forEach(function(img) {
if (!img.classList.contains("filterdisabled"))
{
disableFilter(img);
}
});
}
needMapRefresh = true;
refreshMap();
}
function enableFilter(target)
{
target.classList.remove("filterdisabled");
var pos = disabledFilterImgs.indexOf(target.src);
if (pos >= 0)
{
disabledFilterImgs.splice(pos, 1);
}
}
function disableFilter(target)
{
target.classList.add("filterdisabled");
if (disabledFilterImgs.indexOf(target.src) < 0)
{
disabledFilterImgs.push(target.src);
}
}
function refreshMap()
{
for (var mID in mapMarkers)
{
if (disabledFilterImgs.indexOf(mapMarkers[mID].munzee_logo) == -1)
{
$( "[data-index='" + mID + "']" ).show();
}
else
{
$( "[data-index='" + mID + "']" ).hide();
}
}
}
$(document).ajaxSuccess(restructureImages);