forked from ninuxorg/nodesquit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodesquit-nodeshot.user.js
71 lines (51 loc) · 1.64 KB
/
nodesquit-nodeshot.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// ==UserScript==
// @name Nodesquit Nodeshot
// @namespace [email protected]
// @include http://map.ninux.org*
// @version 1
// @grant none
// ==/UserScript==
if(!window.jQuery) {
console.error('ERR: jQuery not loaded.');
} else {
function nodeLatLon(node, json) {
var r = []
$.each(json, function(index, value){
$.each(value, function(index, value){
if(value.name == node){
r = [value.lat, value.lng];
return false;
}
});
});
return r;
}
function parse(text) {
var node1 = text.substring(0, text.search(' - '));
var node2 = text.substring(text.search(' - ') + 3, text.search(': '));
return [node1, node2];
}
function appendBtn() {
$('div.distance-link').each(function(index, element){
if(!($(element).hasClass('squit'))){
var nodi = parse($(element).text());
var n = nodi[0];
var m = nodi[1];
$.get('http://map.ninux.org/nodes.json', function(data){
n = nodeLatLon(n, data);
m = nodeLatLon(m, data);
var hwt = 'http://www.heywhatsthat.com/profiler.html';
url = hwt+'?na='+n[0]+'&no='+n[1]+'&ma='+m[0]+'&mo='+m[1];
$(element).addClass('squit');
var btn = '<a class="link-hide" target="blank" href="'+url+'">profilo</a>';
$(element).children("span").append(btn);
}, 'json').fail(function(){
console.error('Failed to get nodes.json');
});
}
});
}
$(window).load(function(){
setInterval(appendBtn, 2000);
});
}