-
Notifications
You must be signed in to change notification settings - Fork 25
/
globalpage.html
154 lines (130 loc) · 5.71 KB
/
globalpage.html
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE HTML>
<html>
<head>
<title>global page</title>
<script type="text/javascript">
var disabledSites = safari.extension.settings.disabledsites;
/* var tabActive = [];
var updating = false;
setInterval("update()", 100);
function update() {
if (!updating && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)] != undefined && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0] != undefined && parseInt(tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0]) != parseInt(safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ))) {
updateing = true;
changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("reset",true);
updating = false;
}
}
*/
String.prototype.trim = function () {
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
function disabledSitesHandler() {
if (disabledSites != undefined) {
disabledSitesArray = disabledSites.split(",");
for (var i=0; i < disabledSitesArray.length; i++) {
var ds = disabledSitesArray[i].trim();
currentSite = safari.application.activeBrowserWindow.activeTab.url;
dsm = ds.match(/([^\/.]+\.[^\/.]+(?=$|\/))/);
csm = currentSite.match(/([^\/.]+\.[^\/.]+(?=$|\/))/);
if (dsm != null && csm != null && dsm[0] == csm[0]) {
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("disable",true);
return;
}
}
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true);
} else {
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true);
}
}
function disabledSitesChanged(event) {
if (event.key == "disabledsites") {
disabledSites=event.newValue;
disabledSitesHandler();
}
}
safari.extension.settings.addEventListener("change", disabledSitesChanged, false);
function closeTab() {
safari.application.activeBrowserWindow.activeTab.close();
}
function closeWindow() {
safari.application.activeBrowserWindow.close();
}
function openTab(event) {
var url = event.message;
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (url != "") {
safari.application.activeBrowserWindow.openTab('foreground', ++index).url = url;
} else {
safari.application.activeBrowserWindow.openTab('foreground', ++index);
}
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
}
/* function changeTabActive() {
console.log(safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow ));
if (tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )] != undefined && tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] != undefined) {
tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][0] = tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1];
}
tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
}
*/
function respondToMessage(theMessageEvent) {
switch (theMessageEvent.name) {
case "closeTab":
closeTab();
break;
case "closeWindow":
closeWindow();
break;
case "openTab":
case "newTab":
openTab(theMessageEvent);
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;
case "prevTab":
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (index == 0) {
index = safari.application.activeBrowserWindow.tabs.length-1;
} else {
index--;
}
safari.application.activeBrowserWindow.tabs[index].activate();
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;
case "nextTab":
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (parseInt(theMessageEvent.message, 10) != 0) {
if (theMessageEvent.message == "last") {
index = parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1;
} else if (parseInt(theMessageEvent.message) < safari.application.activeBrowserWindow.tabs.length, 10) {
index = parseInt(theMessageEvent.message, 10)-1;
}
} else {
if (index == parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1) {
index = 0;
} else {
index++;
}
}
safari.application.activeBrowserWindow.tabs[index].activate();
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;
case "backTab":
if (tabActive[0] != undefined && safari.application.activeBrowserWindow.tabs[tabActive[0]]) {
safari.application.activeBrowserWindow.tabs[tabActive[0]].activate();
changeTabActive();
}
break;
case "disabledSites":
disabledSitesHandler();
break;
}
}
safari.application.addEventListener("message",respondToMessage,false);
</script>
</head>
<body> </body>
</html>