-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
49 lines (39 loc) · 1.08 KB
/
content.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
var currentURL = window.location.href,
protocol = window.location.protocol,
localPath = '';
function isEmptyObject( obj ) {
for (var name in obj ) {
return false;
}
return true;
}
function getAddresses() {
chrome.storage.sync.get({ localhostAddresses: []}, function(response){
var addressesArr = response.localhostAddresses;
for(var i in addressesArr) {
if(protocol == 'file:' && currentURL.indexOf(addressesArr[i].localDirectory) > -1) {
var newhref = currentURL.replace(addressesArr[i].localDirectory, addressesArr[i].httpAddress);
newhref = newhref.replace('file:///', 'http://');
window.location.href = newhref;
}
}
});
}
chrome.storage.sync.get('localhost_path', function(response){
if(isEmptyObject(response)) {
getAddresses();
}
else {
var oldPath = response.localhost_path,
newArr = [];
chrome.storage.sync.remove('localhost_path', function(){
newArr.push({
localDirectory: oldPath,
httpAddress: 'localhost'
});
chrome.storage.sync.set({ localhostAddresses: newArr }, function(){
getAddresses();
});
});
}
});