1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-29 12:00:11 -07:00

Fixed distance display, now calculates distance from last hop on the client

This commit is contained in:
Andrew Van Tassel 2015-10-23 10:28:29 -06:00
parent 4a4079eca8
commit 981a02bcfe
5 changed files with 65 additions and 24 deletions

View File

@ -8,7 +8,7 @@ var mailHops =
{
msgURI: null
, isLoaded: false
, options: {'version':'MailHops Plugin 1.0.4','lan':'en','unit':'mi','api_url':'http://api.mailhops.com','debug':false}
, options: {'version':'MailHops Plugin 1.0.5','lan':'en','unit':'mi','api_url':'http://api.mailhops.com','debug':false}
, message: { secure:[] }
, client_location: null
};
@ -363,6 +363,9 @@ mailHops.lookupRoute = function(header_route){
if(mailHops.options.fkey != '')
lookupURL += '&fkey='+mailHops.options.fkey;
if(mailHops.options.client_location != '')
lookupURL+='&c=0';
mailHops.LOG(lookupURL);
//check for cache

View File

@ -302,8 +302,15 @@ var mailHopsDisplay =
if(this.options.client_location){
var client_location = JSON.parse(this.options.client_location);
if(response.route[response.route.length-1].ip != client_location.route[0].ip)
response.route.push(client_location.route[0]);
//get distance from last route to client_location and add to response.distance.miles or kilometers
if(!response.route[response.route.length-1]['private']){
if(this.options.unit=='km')
response.distance.kilometers += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit);
else
response.distance.miles += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit);
}
//push client location to the end of the route
response.route.push(client_location.route[0]);
}
for(var i=0; i<response.route.length;i++){
@ -423,14 +430,14 @@ var mailHopsDisplay =
displayText = first.countryName;
}
if(response.distance && response.distance.miles > 0){
if(this.options.unit=='mi')
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
else
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
}
else if(displayText=='')
displayText = ' Local message.';
if(response.distance){
if(this.options.unit=='km' && response.distance.kilometers > 0)
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
else if(response.distance.miles > 0)
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
}
else if(displayText=='')
displayText = ' Local message.';
}
if(header_route)

View File

@ -185,8 +185,15 @@ var mailHopsDisplay =
if(this.options.client_location){
var client_location = JSON.parse(this.options.client_location);
if(response.route[response.route.length-1].ip != client_location.route[0].ip)
response.route.push(client_location.route[0]);
//get distance from last route to client_location and add to response.distance.miles or kilometers
if(!response.route[response.route.length-1]['private']){
if(this.options.unit=='km')
response.distance.kilometers += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit);
else
response.distance.miles += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit);
}
//push client location to the end of the route
response.route.push(client_location.route[0]);
}
for(var i=0; i<response.route.length;i++){
//get the first hop location
@ -284,11 +291,11 @@ var mailHopsDisplay =
displayText = first.countryName;
}
if(response.distance && response.distance.miles > 0){
if(this.options.unit=='mi')
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
else
if(response.distance){
if(this.options.unit=='km' && response.distance.kilometers > 0)
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
else if(response.distance.miles > 0)
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
} else if(displayText=='')
displayText = ' Local message.';
}

View File

@ -73,7 +73,7 @@ dnsbl: function(result,abbr){
case '127.0.0.3':
if(abbr)
return 'SBL';
else
else
return 'Static UBE sources, verified spam services and ROKSO spammers.';
case '127.0.0.4':
@ -82,14 +82,14 @@ dnsbl: function(result,abbr){
case '127.0.0.7':
if(abbr)
return 'XBL';
else
else
return 'Illegal 3rd party exploits, including proxies, worms and trojan exploits.';
case '127.0.0.10':
case '127.0.0.11':
if(abbr)
return 'PBL';
else
else
return 'IP ranges which should not be delivering unauthenticated SMTP email.';
default:
@ -146,7 +146,7 @@ launchMap: function(route,options){
if(options.map_provider)
lookupURL += '&mp='+options.map_provider;
window.openDialog("chrome://mailhops/content/mailhopsMap.xul","MailHops",'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,close=yes,width=1024,height=768,resizable=yes', {src: lookupURL});
window.openDialog("chrome://mailhops/content/mailhopsMap.xul","MailHops",'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,close=yes,width=1024,height=768,resizable=yes', {src: lookupURL});
}
},
@ -177,6 +177,30 @@ getWeatherIcon: function(icon){
var hr = (new Date).getHours();
var time = (hr >= 4 && hr <= 18)?'day':'night';
return 'chrome://mailhops/content/images/weather/'+forecast_icons[icon][time]+'.png';
}
},
};
getDistance: function(from, to, unit) {
if(!from || !to || !from['lat'] || !to['lat'])
return 0;
lat = parseFloat(from['lat']);
lon1 = parseFloat(from['lng']);
lat2 = parseFloat(to['lat']);
lon2 = parseFloat(to['lng']);
unit = unit || 'mi';//mi or km
lat *= (Math.PI/180);
lon1 *= (Math.PI/180);
lat2 *= (Math.PI/180);
lon2 *= (Math.PI/180);
dist = 2*Math.asin(Math.sqrt( Math.pow((Math.sin((lat-lat2)/2)),2) + Math.cos(lat)*Math.cos(lat2)*Math.pow((Math.sin((lon1-lon2)/2)),2))) * 6378.137;
if (unit == 'mi') {
dist = (dist / 1.609344);
}
return dist;
}
};

View File

@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:type>2</em:type>
<em:id>thunderbird@mailhops.com</em:id>
<em:version>1.0.4</em:version>
<em:version>1.0.5</em:version>
<em:name>MailHops</em:name>
<em:description>MailHops maps the route an email traveled to get to you. Using GeoIP it also displays distance traveled along with the location (city, state and country) of the sender.</em:description>