-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathip.js
68 lines (58 loc) · 1.81 KB
/
ip.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
function placeIPDiv () {
// Show IP at the bottom left for these websites
var noRight = new Array(
"mail.google.com",
"www.google.com.*",
"www.facebook.com",
".*renren.com"
);
var div_align = "right";
for (var idx in noRight) {
if (window.location.host.match(noRight[idx])) {
div_align = "left";
break;
}
}
chrome.extension.sendMessage({op: "getip"}, function(response) {
var ip = response.ip;
chrome.extension.sendMessage({op: "is_enabled"}, function(response) {
var ext_enabled = response.ext_enabled;
if (ext_enabled == 1 || ext_enabled === undefined) {
$("body").append('<div id="chrome_websiteIP" class="chrome_websiteIP_' + div_align + '">' + ip + '</div>');
}
});
});
$("#chrome_websiteIP").live('mouseover', function() {
if ($(this).hasClass('chrome_websiteIP_right')) {
$(this).removeClass("chrome_websiteIP_right");
$(this).addClass("chrome_websiteIP_left");
}
else {
$(this).removeClass("chrome_websiteIP_left");
$(this).addClass("chrome_websiteIP_right");
}
});
}
$(document).ready(placeIPDiv);
window.lastKeyCode = 0;
window.lastHitTime = new Date();
$(document).keyup(function(e) {
// If the 'Esc' key is pressed before the HTML (yes, HTML only) could
// fully load, show the IP <div> as $(document).ready() doesn't execute.
if (document.getElementById('chrome_websiteIP') === null &&
e.keyCode == 27) {
placeIPDiv();
} else {
now = new Date();
timeDiff = now - window.lastHitTime;
window.lastHitTime = now;
if (e.keyCode == 113 &&
window.lastKeyCode == 113 && // 2 "F2" keystrokes
timeDiff < 900) { // within 900ms
window.lastKeyCode = 0;
window.prompt('IP of "' + window.location.host + '":',
document.getElementById('chrome_websiteIP').innerText);
}
}
window.lastKeyCode = e.keyCode;
});