forked from barbushin/javascript-errors-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
54 lines (49 loc) · 972 Bytes
/
common.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
var request = parseUrl(window.location.href);
var isIFrame = window.top != window;
function parseUrl(url) {
var params = {};
var query = /\?(.*)/.exec(url);
if(query) {
var kvPairs = query[1].split('&');
for(var i in kvPairs) {
var kv = kvPairs[i].split('=');
params[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1]);
}
if(params.tabId) {
params.tabId = +params.tabId;
}
}
return params;
}
function sendMessage(data) {
data._fromJEN = true;
if(isIFrame) {
window.top.postMessage(data, '*');
}
else if(request.tabId) {
chrome.tabs.sendMessage(request.tabId, data);
}
}
function autoSize() {
if(isIFrame) {
sendMessage({
_resize: true,
width: document.body.scrollWidth + 10,
height: document.body.scrollHeight + 15
}, '*');
}
}
function closePopup(clear) {
sendMessage({
_closePopup: true
});
if(clear) {
sendMessage({
_clear: true
});
}
if(!isIFrame) {
window.close();
}
}
window.onload = autoSize;