4 <title>Delicious.safariextension</title>
5 <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
6 <script type="text/javascript">
7 var Delicious = window.Delicious = {
13 addBookmark: function(url, title) {
14 var deliciousURL = 'http://delicious.com/save?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&v=5&noui=1&jump=doclose';
15 if (!window.open(deliciousURL, 'deliciousuiv5', 'location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550')) {
16 var tab = safari.application.activeBrowserWindow.openTab();
17 tab.url = deliciousURL;
20 refreshBars: function() {
21 var bars = safari.extension.bars;
22 for (var i = 0; i < bars.length; i++) {
23 var bar = bars[i].contentWindow;
27 reloadBookmarksWithTag: function(tag) {
28 if (this.username && this.privateKey) {
31 $.getJSON('http://feeds.delicious.com/v2/json/' + this.username + '/' + tag + '?key=' + this.privateKey + '&callback=?', function(response) {
33 for (var i = 0; i < response.length; i++) {
34 var bookmark = response[i];
35 var bookmarkURL = bookmark['u'];
36 var bookmarkName = bookmark['d'];
37 self.bookmarks.push({url: bookmarkURL, name: bookmarkName});
39 self.currentTag = currentTag;
43 this.currentTag = null;
46 reloadBookmarks: function() {
47 this.currentTag = null;
48 if (this.username && this.privateKey) {
50 $.getJSON('http://feeds.delicious.com/v2/json/' + this.username + '?private=' + this.privateKey + '&callback=?', function(response) {
52 for (var i = 0; i < response.length; i++) {
53 var bookmark = response[i];
54 var bookmarkURL = bookmark['u'];
55 var bookmarkName = bookmark['d'];
56 self.bookmarks.push({url: bookmarkURL, name: bookmarkName});
64 reloadTags: function() {
65 if (this.username && this.privateKey) {
67 $.getJSON('http://feeds.delicious.com/v2/json/tags/' + this.username + '?key=' + this.privateKey + '&callback=?', function(response) {
69 for (var tag in response) {
70 var count = response[tag];
71 self.tags.push({tag: tag, count: count});
79 setupUser: function(privateRSSFeedURL) {
80 if (privateRSSFeedURL) {
81 var matches = /http:\/\/feeds\.delicious\.com\/v2\/rss\/(.+)\?private=(.+)&count=15/.exec(privateRSSFeedURL);
82 if (matches && matches.length == 3) {
83 this.username = matches[1];
84 this.privateKey = matches[2];
87 this.privateKey = null;
91 this.privateKey = null;
93 this.reloadBookmarks();
97 var privateRSSFeedURL = safari.extension.secureSettings.getItem('com.ithinksw.safariextensions.delicious.privateRSSFeedURL')
98 this.setupUser(privateRSSFeedURL);
101 safari.extension.secureSettings.addEventListener('change', function(event) {
102 if (event.key === 'com.ithinksw.safariextensions.delicious.privateRSSFeedURL') {
103 self.setupUser(event.newValue);
106 safari.application.addEventListener("command", function(event) {
107 if (event.command === "addbookmark") {
108 self.addBookmark(event.target.browserWindow.activeTab.url, event.target.browserWindow.activeTab.title);
111 safari.application.addEventListener("validate", function(event) {
112 if (event.command === "addbookmark") {
113 if (event.target.browserWindow.activeTab.url) {
115 event.target.disabled = false;
117 event.target.disabled = true;
120 event.target.disabled = true;