-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopupjs.js
136 lines (117 loc) · 3.94 KB
/
popupjs.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
var port;
var loc = {};
var added = {};
var autocomplete;
var place;
function updatehtmlLocs(mykey, myplace){//add geocode param
if (localStorage.getItem(mykey) != null) {
//console.log("existing key");
return;
}
if (mykey != null){
//console.log("addded", myKey);
//store the addresses geocoords and also its short name
localStorage.setItem(mykey, JSON.stringify([myplace["name"], myplace["geometry"]["location"]]));
}
//append all the stored locations to the doc
for (var key in localStorage){
if(key == "settings")
continue;
if(added[key] != true){
added[key] = true;
var node = document.createElement("LI");
var t = document.createTextNode(JSON.parse(localStorage.getItem(key))[0]);
node.appendChild(t);
node.classList.add('locationItem');
var button = document.createElement("button");
button.setAttribute("class", "btn btn-default btn-sm mybutton");
button.setAttribute("name", key);
button.addEventListener("click", function(e){
this.parentNode.parentNode.removeChild(this.parentNode);
localStorage.removeItem(this.name);
added[key] = false;
});
var span = document.createElement("span");
span.setAttribute("class", "glyphicon glyphicon-minus");
button.appendChild(span);
node.appendChild(button);
document.getElementById("locationHolder").appendChild(node);
}
}
//clear the input form
document.getElementById("locationInput").value = "";
}
window.onload = function() {
//document.getElementById("submitButton").addEventListener("click", submitEnter);
document.getElementById("locationInput").addEventListener("onFocus", geolocate);
updatehtmlLocs(null);
initAutocomplete();
port = chrome.extension.connect({name: "GPS"});
port.onMessage.addListener(function(msg) {
location["latitude"] = msg.latitude;
location["longitude"] = msg.longitude;
console.log(msg.latitude);
});
buttonLoad();
}
function buttonLoad(){
document.getElementById("muteall").addEventListener("click", function(){
port.postMessage({request: "mute"});
console.log("MuteAll request");
});
document.getElementById("unmuteall").addEventListener("click", function(){
port.postMessage({request: "unmute"});
console.log("Unmuteall Request");
});
document.getElementById("mutenew").addEventListener("click", function(){
var temp = JSON.parse(localStorage.getItem("settings"));
if (temp == null){
//default settings
temp = [false, 200, [,]];
temp[0] = "false";
}
else{
temp[0] = !temp[0];
}
//console.log(temp);
//console.log(JSON.stringify(temp));
localStorage.setItem("settings", JSON.stringify(temp));
});
};
function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.SearchBox(
/** @type {!HTMLInputElement} */
(document.getElementById('locationInput'))
//{types: ['geocode']}
);
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('places_changed', function() {
var places = autocomplete.getPlaces();
place = places[0];
if (places.length == 0){
window.alert("No search results retrieved");
return;
}
//console.log(place);
updatehtmlLocs(document.getElementById("locationInput").value, place);
console.log(place);
});
}
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}