-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDeliciousGlobalsPage.html
38 lines (31 loc) · 1.19 KB
/
DeliciousGlobalsPage.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
<html>
<head>
</head>
<script>
function performCommand(event) {
if (event.command === "DeliciousToolbarItem") {
var currentWindow = safari.application.activeBrowserWindow;
var currentTab = currentWindow.activeTab;
var currentTabUrl = encodeURIComponent(currentTab.url);
var currentTabTitle = encodeURIComponent(currentTab.title);
var deliciousTab = currentWindow.openTab();
deliciousTab.url = 'https://www.delicious.com/save?url=' + currentTabUrl + '&title=' + currentTabTitle;
deliciousTab.addEventListener("beforeNavigate", function(event) {
// Close tab when bookmark saved or aborted and return user to original tab
if (!event.url.match('delicious.com/save|delicious.com/login')) {
currentTab.activate();
deliciousTab.close();
}
});
}
}
function validateCommand(event) {
if (event.command === "DeliciousToolbarItem") {
// Disable the button if there is no URL loaded in the tab.
event.target.disabled = !event.target.browserWindow.activeTab.url;
}
}
safari.application.addEventListener("command", performCommand, false);
safari.application.addEventListener("validate", validateCommand, false);
</script>
</html>