-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.js
45 lines (38 loc) · 1.08 KB
/
actions.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
function performCommand(event)
{
if (event.command === "OpenNewWindow") {
var newTabs = [];
event.target.browserWindow.activeTab.flag = true;
for (var i = event.target.browserWindow.tabs.length - 1; i >= 0; i--) {
tab = event.target.browserWindow.tabs[i];
tab.saveForLater = true;
if (tab.flag) {
break;
}
}
for (var i = event.target.browserWindow.tabs.length - 1; i >= 0; i--) {
tab = event.target.browserWindow.tabs[i];
if (tab.saveForLater) {
newTabs.push(tab.url);
tab.close();
}
}
var newWindow = safari.application.openBrowserWindow();
for (var i = newTabs.length - 1; i >= 0; i--) {
if (i == newTabs.length - 1) {
newWindow.activeTab.url = newTabs[i];
} else {
var newTab = newWindow.openTab();
newTab.url = newTabs[i];
}
}
}
}
function validateCommand(event)
{
if (event.command === "OpenNewWindow") {
event.target.disabled = event.target.browserWindow.tabs.length < 2;
}
}
safari.application.addEventListener("command", performCommand, false);
safari.application.addEventListener("validate", validateCommand, false);