forked from jialongl/WebsiteIP
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ip.js
31 lines (25 loc) · 969 Bytes
/
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
var chrome = window.chrome;
chrome.extension.sendMessage({name: 'isEnabled'}, function(isEnabled) {
// summary:
// only do stuff if enabled
if(!isEnabled) { return; }
chrome.extension.sendMessage({name: 'getIP'}, function(response) {
// summary:
// grab the ip
if(!response.ip || response.ip === '::') { return; }
var websiteip = document.createElement('websiteip');
websiteip.id = 'chrome_websiteIP';
websiteip.className = 'chrome_websiteIP_right';
websiteip.innerHTML = response.ip;
if(document && document.body) {
document.body.appendChild(websiteip);
}
websiteip.addEventListener('mouseover', function() {
if(this.className.indexOf('chrome_websiteIP_right') !== -1) {
this.className = this.className.replace('chrome_websiteIP_right', 'chrome_websiteIP_left');
} else {
this.className = this.className.replace('chrome_websiteIP_left', 'chrome_websiteIP_right');
}
}, false);
});});