mirror of
https://github.com/MailHops/mailhops-plugin.git
synced 2025-05-29 03:50:09 -07:00
Fixed distance display, now calculates distance from last hop on the client
This commit is contained in:
parent
4a4079eca8
commit
981a02bcfe
@ -8,7 +8,7 @@ var mailHops =
|
|||||||
{
|
{
|
||||||
msgURI: null
|
msgURI: null
|
||||||
, isLoaded: false
|
, 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:[] }
|
, message: { secure:[] }
|
||||||
, client_location: null
|
, client_location: null
|
||||||
};
|
};
|
||||||
@ -363,6 +363,9 @@ mailHops.lookupRoute = function(header_route){
|
|||||||
if(mailHops.options.fkey != '')
|
if(mailHops.options.fkey != '')
|
||||||
lookupURL += '&fkey='+mailHops.options.fkey;
|
lookupURL += '&fkey='+mailHops.options.fkey;
|
||||||
|
|
||||||
|
if(mailHops.options.client_location != '')
|
||||||
|
lookupURL+='&c=0';
|
||||||
|
|
||||||
mailHops.LOG(lookupURL);
|
mailHops.LOG(lookupURL);
|
||||||
|
|
||||||
//check for cache
|
//check for cache
|
||||||
|
@ -302,8 +302,15 @@ var mailHopsDisplay =
|
|||||||
|
|
||||||
if(this.options.client_location){
|
if(this.options.client_location){
|
||||||
var client_location = JSON.parse(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)
|
//get distance from last route to client_location and add to response.distance.miles or kilometers
|
||||||
response.route.push(client_location.route[0]);
|
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++){
|
for(var i=0; i<response.route.length;i++){
|
||||||
@ -423,14 +430,14 @@ var mailHopsDisplay =
|
|||||||
displayText = first.countryName;
|
displayText = first.countryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(response.distance && response.distance.miles > 0){
|
if(response.distance){
|
||||||
if(this.options.unit=='mi')
|
if(this.options.unit=='km' && response.distance.kilometers > 0)
|
||||||
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
|
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
|
||||||
else
|
else if(response.distance.miles > 0)
|
||||||
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
|
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
|
||||||
}
|
}
|
||||||
else if(displayText=='')
|
else if(displayText=='')
|
||||||
displayText = ' Local message.';
|
displayText = ' Local message.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(header_route)
|
if(header_route)
|
||||||
|
@ -185,8 +185,15 @@ var mailHopsDisplay =
|
|||||||
|
|
||||||
if(this.options.client_location){
|
if(this.options.client_location){
|
||||||
var client_location = JSON.parse(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)
|
//get distance from last route to client_location and add to response.distance.miles or kilometers
|
||||||
response.route.push(client_location.route[0]);
|
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++){
|
for(var i=0; i<response.route.length;i++){
|
||||||
//get the first hop location
|
//get the first hop location
|
||||||
@ -284,11 +291,11 @@ var mailHopsDisplay =
|
|||||||
displayText = first.countryName;
|
displayText = first.countryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(response.distance && response.distance.miles > 0){
|
if(response.distance){
|
||||||
if(this.options.unit=='mi')
|
if(this.options.unit=='km' && response.distance.kilometers > 0)
|
||||||
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
|
|
||||||
else
|
|
||||||
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
|
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=='')
|
} else if(displayText=='')
|
||||||
displayText = ' Local message.';
|
displayText = ' Local message.';
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ dnsbl: function(result,abbr){
|
|||||||
case '127.0.0.3':
|
case '127.0.0.3':
|
||||||
if(abbr)
|
if(abbr)
|
||||||
return 'SBL';
|
return 'SBL';
|
||||||
else
|
else
|
||||||
return 'Static UBE sources, verified spam services and ROKSO spammers.';
|
return 'Static UBE sources, verified spam services and ROKSO spammers.';
|
||||||
|
|
||||||
case '127.0.0.4':
|
case '127.0.0.4':
|
||||||
@ -82,14 +82,14 @@ dnsbl: function(result,abbr){
|
|||||||
case '127.0.0.7':
|
case '127.0.0.7':
|
||||||
if(abbr)
|
if(abbr)
|
||||||
return 'XBL';
|
return 'XBL';
|
||||||
else
|
else
|
||||||
return 'Illegal 3rd party exploits, including proxies, worms and trojan exploits.';
|
return 'Illegal 3rd party exploits, including proxies, worms and trojan exploits.';
|
||||||
|
|
||||||
case '127.0.0.10':
|
case '127.0.0.10':
|
||||||
case '127.0.0.11':
|
case '127.0.0.11':
|
||||||
if(abbr)
|
if(abbr)
|
||||||
return 'PBL';
|
return 'PBL';
|
||||||
else
|
else
|
||||||
return 'IP ranges which should not be delivering unauthenticated SMTP email.';
|
return 'IP ranges which should not be delivering unauthenticated SMTP email.';
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -146,7 +146,7 @@ launchMap: function(route,options){
|
|||||||
if(options.map_provider)
|
if(options.map_provider)
|
||||||
lookupURL += '&mp='+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 hr = (new Date).getHours();
|
||||||
var time = (hr >= 4 && hr <= 18)?'day':'night';
|
var time = (hr >= 4 && hr <= 18)?'day':'night';
|
||||||
return 'chrome://mailhops/content/images/weather/'+forecast_icons[icon][time]+'.png';
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<Description about="urn:mozilla:install-manifest">
|
<Description about="urn:mozilla:install-manifest">
|
||||||
<em:type>2</em:type>
|
<em:type>2</em:type>
|
||||||
<em:id>thunderbird@mailhops.com</em:id>
|
<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: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>
|
<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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user