-
Notifications
You must be signed in to change notification settings - Fork 20
/
smschrome.js
48 lines (46 loc) · 1.49 KB
/
smschrome.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 deviceId = getURLParameter("deviceId");
var contactParameter = null;
var hashIndex = window.location.href.indexOf("#");
if(hashIndex>=0){
contactParameter = window.location.href.substring(hashIndex+1);
}
var myWindow = window;
document.addEventListener('DOMContentLoaded', function() {
console.log(deviceId);
setFrameUrl();
chrome.extension.getBackgroundPage().smsWindow = window;
chrome.extension.getBackgroundPage().onSmsReceived = function(gcmNewSmsReceived){
var number = gcmNewSmsReceived.number;
var text = gcmNewSmsReceived.text;
if(!text){
var newUrl = myWindow.location.href;
var index = newUrl.indexOf("#");
if(index>0){
newUrl = newUrl.substring(0,index);
}
newUrl += "#" + number;
myWindow.location.href = newUrl;
console.log("New href: " + myWindow.location.href);
myWindow.location.reload();
}else{
sendMessageToFrame(gcmNewSmsReceived);
}
}
//frame.style.height = getURLParameter("height") + "px";
//frame.style.width = getURLParameter("width") + "px";
});
var setFrameUrl = function(){
var url = joinserverBase + "sms.html?refresh=false&deviceId="+deviceId;
var frame = document.getElementById("frame");
if(contactParameter){
url = url + "#"+contactParameter;
}
frame.src = url;
}
window.onbeforeunload = function(){
chrome.extension.getBackgroundPage().smsWindow = null;
chrome.extension.getBackgroundPage().onSmsReceived = null;
}
var sendMessageToFrame = function(obj){
window.frames[0].window.postMessage(JSON.stringify(obj),"*");
}