-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelinka.js
178 lines (150 loc) · 5.85 KB
/
delinka.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Our cute delinka object
var delinka = {
// Properties
// The callback is called with the results after they're fetched from delicious
callback: null,
// Count determines the number of results to return
count: 10,
// Methods
// Gets the delicious hot list
getHotlist: function() {
delinka._fetchBookmarks(delinka.url);
},
// Gets the most recent global bookmarks
getRecentBookmarks: function() {
delinka._fetchBookmarks(delinka.url + 'recent/');
},
// Gets the most recent global bookmarks with the specified tags
// "tags" is an array of strings
getRecentBookmarksByTag: function(tags) {
delinka._fetchBookmarks(delinka.url + 'tag/' + delinka._getTagString(tags));
},
// Gets the most popular global bookmarks
getPopularBookmarks: function() {
delinka.getPopularBookmarksByTag(null);
},
// Gets the most popular global bookmarks with the specified tags
getPopularBookmarksByTag: function(tags) {
delinka._fetchBookmarks(delinka.url + 'popular/' + delinka._getTagString(tags));
},
// Gets delicious site alerts
getRecentSiteAlerts: function() {
delinka._fetchBookmarks(delinka.url + 'alerts/');
},
// Gets the public bookmarks for the specified user
getBookmarksForUser: function(user) {
delinka._fetchBookmarks(delinka.url + user);
},
// Gets the private bookmarks for the specified user and key
getPrivateBookmarksForUser: function(user, key) {
delinka._fetchBookmarks(delinka.url + user + '?private=' + key);
},
// Gets the public bookmarks for the specified user and tags
getBookmarksForUserByTag: function(user, tags) {
delinka._fetchBookmarks(delinka.url + user + '/' + delinka._getTagString(tags));
},
// Gets the tags for the specified user
getTagsForUser: function(user) {
delinka._fetchTags(delinka.url + 'tags/' + user);
},
// Gets the related tags for the user and tags specified
getRelatedTagsForUser: function(user, tags) {
var url = delinka.url + 'tags/' + user + '/' + delinka._getTagString(tags);
delinka._fetchTags(url);
},
// Gets the bookmarks for the specified user from their list of subscriptions
getBookmarksForUserFromSubscriptions: function(user) {
delinka._fetchBookmarks(delinka.url + 'subscriptions/' + user);
},
// Gets the user's network's members' bookmarks
getMemberNetworkBookmarksForUser: function(user) {
delinka._fetchBookmarks(delinka.url + 'network/' + user);
},
// Gets the user's network's members' bookmarks with the specified tags
getMemberNetworkBookmarksForUserByTag: function(user, tags) {
var url = delinka.url + 'network/' + user + '/' + delinka._getTagString(tags);
delinka._fetchBookmarks(url);
},
// There's some problem with the delicious interface which prevents
// the following functions from working properly. I'm in contact
// with the delicious support staff.
// Get the private bookmarks for the specified user and tags
getPrivateBookmarksForUserByTag: function(user, key, tags) {
var url = delinka.url + user + '/' + delinka._getTagString(tags)
+ '?private=' + key;
delinka._fetchBookmarks(url);
},
// Get the user's private network's members' bookmarks
getPrivateMemberNetworkBookmarksForUser: function(user, key) {
delinka._fetchBookmarks(delinka.url + 'network/' + user + '?private=' + key);
},
// Get the user's private network's members' bookmarks with the specified tags
getPrivateMemberNetworkBookmarksForUserByTag: function(user, key, tags) {
var url = delinka.url + 'network/' + user + '/' + delinka._getTagString(tags);
url += '?private=' + key;
delinka._fetchBookmarks(url);
},
//internal properties
thisVersion: 0.1,
deliciousVersion: 2.0,
url: 'http://feeds.delicious.com/v2/json/',
//internal methods
_getTagString: function(tags) {
var tagString = '';
if(tags != null)
{
for(i=0; i<tags.length; i++)
{
tagString += "+" + tags[i];
}
tagString = tagString.substring(1);
}
return tagString;
},
_fetchBookmarks: function(url) {
delinka._fetch(url, 'callback=delinka._bkCallback');
},
_fetchTags: function(url) {
delinka._fetch(url, 'callback=delinka._tagCallback');
},
_fetch: function(url, callback) {
var conjunction = '?';
var lastSlash = url.lastIndexOf(url, '/');
if(url.indexOf(conjunction, lastSlash) != -1)
{
conjunction = '&';
}
var newurl = url + conjunction + callback + '&count=' + delinka.count;
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = newurl;
head.appendChild(script);
},
_bkCallback: function(datalist) {
var richUrls = [];
for(var i=0; i<datalist.length; i++)
{
var richUrl = { url: datalist[i].u,
description: datalist[i].d,
date: datalist[i].dt,
tags: datalist[i].t
};
richUrls.push(richUrl);
}
//call the user callback
if(delinka.callback !== null)
delinka.callback(richUrls);
},
_tagCallback: function(datalist) {
var richTags = [];
for(var i in datalist)
{
var richTag = { tag: i, usedCount: datalist[i] };
richTags.push(richTag);
}
//call the user callback
if(delinka.callback != null)
delinka.callback(richTags);
}
};