Skip to content

Instantly share code, notes, and snippets.

@Err0r404
Last active January 28, 2018 10:24
Show Gist options
  • Save Err0r404/5709508524d7f2198459c70a49391fad to your computer and use it in GitHub Desktop.
Save Err0r404/5709508524d7f2198459c70a49391fad to your computer and use it in GitHub Desktop.
Highlight raids in selected gyms
// ==UserScript==
// @name Highlight raids in selected gyms in PokeMontpellier.fr
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Add a bouncing animation to the raids in selected gyms
// @author Err0r404
// @match https://www.pokemontpellier.fr/
// @grant none
// @downloadURL https://gist.githubusercontent.com/Err0r404/5709508524d7f2198459c70a49391fad/raw/
// @updateURL https://gist.githubusercontent.com/Err0r404/50575e1758fdd9f9c0c8836da1da3911/raw/
// ==/UserScript==
(function() {
'use strict';
// Vars
var id, name, lat, lng, level, start, expire, startAt, expireAt, date, $img;
var timeInterval = 30000; // 30 seconds
var confirmedGyms = [
{
"name": "Parc de la gare",
"lat": "43.605257",
"lng": "3.880134"
},
{
"name": "Parc Magnol",
"lat": "43.61756",
"lng": "3.862445"
},
{
"name": "Parc St Odile",
"lat": "43.62351",
"lng": "3.872589"
},
{
"name": "Bâteau pour enfants",
"lat": "43.610627",
"lng": "3.896554"
},
{
"name": "Parc Charpak",
"lat": "43.600484",
"lng": "3.902752"
},
{
"name": "Parc Rimbaud",
"lat": "43.617945",
"lng": "3.893718"
},
{
"name": "Korais",
"lat": "43.607552",
"lng": "3.887221"
},
{
"name": "Parc de la Lironde",
"lat": "43.608579",
"lng": "3.909183"
}
];
// Add libraries
$("head").append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" />');
$("body").append('<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>');
// Add animation to a Pokemon
var highlightRaid = function(expire, id){
$(".remaining_text_raids[data-expire="+expire+"]").each(function(){
$img = $(this).siblings(".raidimg").find("img");
if($img.attr("src") == "/static/monocle-icons/icons/"+id+".png"){
$img.addClass("animated infinite bounce raidMe");
}
});
};
var searchRaid = function(){
$(".raidMe").removeClass("animated infinite bounce raidMe");
$.ajax({
url : "https://www.pokemontpellier.fr/raids",
dataType : "JSON",
success : function(data){
console.clear();
// Loop trough all raids
for(var i in data){
// Some wrappers
id = data[i].pokemon_id;
name = data[i].pokemon_name;
lat = data[i].lat;
lng = data[i].lon;
level = data[i].level;
start = data[i].time_battle;
expire = data[i].time_end;
// Loop trough selected confirmedGyms
for(var j in confirmedGyms){
// Check if raid lat+lng if equal to one of our selected gym
if(lat == confirmedGyms[j].lat && lng == confirmedGyms[j].lng){
if(start*1000 > Date.now()){
startAt = moment.unix(start).format("HH:mm");
console.log("Raid "+level+" detected at "+confirmedGyms[j].name+" starts at "+startAt);
}
else{
expireAt = moment.unix(expire).format("HH:mm");
console.log("Raid "+level+" ("+name+") detected at "+confirmedGyms[j].name+" ends at "+expireAt);
}
highlightRaid(expire, id);
}
}
}
}
});
};
// Check raids regulary and starts immediatly
var checkIvInterval = setInterval(searchRaid, timeInterval);
searchRaid();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment