-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
72 lines (64 loc) · 2.23 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function openEJWindow(newWindow, subUrl, URL)
{
var newURL = "https://www.yappy.im/web/";
var isOpen = false;
if(subUrl == null)
{
subUrl = "";
}
if (URL!= null)
{
newURL = URL;
}
// get the current window
chrome.windows.getAll({
populate: true
}, function (windows) {
var windowsLeft = windows.length;
for (var w = 0; w < windows.length; w++) {
// get an array of the tabs in the window
var myWindow = windows[w];
chrome.tabs.getAllInWindow(windows[w].id, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].url.toString().indexOf(newURL) > -1) {
var myTab = tabs[i];
isOpen = true;
windowsLeft += 1;
chrome.tabs.update(myTab.id, { highlighted: true});
var c = "var S = document.createElement('script');\
S.textContent = \"goToChat('" + subUrl + "');\";\
document.head.appendChild(S);"
chrome.tabs.executeScript(myTab.id, {code:c});
chrome.windows.update(myWindow.id, {
focused: true,
state: myWindow.state == "minimized" ? "normal" : myWindow.state
}, function () { windowsLeft -= 1;});
}
if (i == tabs.length - 1) {
windowsLeft -= 1;
}
}
});
}
var interval = setInterval(function () {
if (windowsLeft == 0) {
clearInterval(interval);
if (isOpen == false) {
if (newWindow == true) {
chrome.windows.create({
type: 'popup',
focused: true,
url: newURL + subUrl,
height: 600,
width: 1100
});
} else {
chrome.tabs.create({
url: newURL
});
}
}
}
}, 50);
});
}