Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dennis.gid
committed
May 14, 2010
0 parents
commit b6c7113
Showing
27 changed files
with
4,295 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<head> | ||
<script src="js/mootools-1.2.4.js" type="text/javascript"></script> | ||
<script src="js/sha1.js" type="text/javascript"></script> | ||
<script src="js/OAuth.js" type="text/javascript"></script> | ||
<script src="js/background.js" type="text/javascript"></script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
var Delicious = new Class({ | ||
|
||
//Implements: Events, | ||
|
||
initialize: function(username, password, autosynch){ | ||
this.username = username; | ||
this.password = password; | ||
this.autosynch = Boolean(parseInt(localStorage.autosynch) || 0); | ||
this.lastUpdate = null; | ||
|
||
this.isWorking = false; | ||
this.autoUpdateInterval = 900000; //Update Every 15 minutes | ||
|
||
this.posts = []; | ||
this.tags = []; | ||
|
||
this.updateIn(this.autoUpdateInterval); | ||
}, | ||
|
||
onComplete: function(){ | ||
this.isWorking = false; | ||
}, | ||
|
||
cancel: function(){ | ||
if(this.currentRequest && this.currentRequest.running) | ||
this.currentRequest.cancel(); | ||
this.currentRequest = null; | ||
}, | ||
|
||
updateIn: function(time){ | ||
$clear(this.autoUpdateID); | ||
this.autoUpdateID = this.autoUpdate.delay(time, this); | ||
}, | ||
|
||
autoUpdate: function(){ | ||
if(this.autosynch){ | ||
this.update(); | ||
} | ||
this.updateIn(this.autoUpdateInterval); | ||
}, | ||
|
||
update: function(){ | ||
if(this.isWorking || !this.autosynch) | ||
return this; | ||
|
||
console.log('update'); | ||
this.cancel(); | ||
this.isWorking = true; | ||
var baseURL = 'https://' + this.username + ':' + this.password + '@api.del.icio.us/v1/'; | ||
var self = this; | ||
|
||
this.currentRequest = new Request({ | ||
method: 'get', | ||
onSuccess: function(responseText, responseXML){ | ||
var time = responseXML.getElementsByTagName('update')[0].getAttribute('time'); | ||
if(time > (localStorage['lastUpdate'] || '')){ | ||
self.load(); | ||
}else{ | ||
console.log('no update'); | ||
//self.fireEvent('noupdate'); | ||
chrome.extension.sendRequest('noupdate'); | ||
self.onComplete(); | ||
} | ||
}, | ||
onFailure: function(){ | ||
console.log('posts/update failed'); | ||
//self.fireEvent('error'); | ||
chrome.extension.sendRequest('error'); | ||
self.onComplete(); | ||
} | ||
}).send({'url': baseURL + 'posts/update'}); | ||
|
||
return this; | ||
}, | ||
|
||
load: function(){ | ||
this.cancel(); | ||
|
||
console.log('load'); | ||
this.isWorking = true; | ||
var baseURL = 'https://' + this.username + ':' + this.password + '@api.del.icio.us/v1/'; | ||
var self = this; | ||
|
||
this.currentRequest = new Request({ | ||
method: 'get', | ||
onSuccess: function(responseText, responseXML){ | ||
console.log('success'); | ||
|
||
var postsXML = responseXML.getElementsByTagName('post'); | ||
var a = []; | ||
var tagIndex = {}; | ||
var tags = []; | ||
|
||
for (var i = 0; i < postsXML.length; i++) { | ||
var postTags = postsXML[i].getAttribute('tag').split(' '); | ||
|
||
a.push({ | ||
title: postsXML[i].getAttribute('description'), | ||
url: postsXML[i].getAttribute('href'), | ||
time: postsXML[i].getAttribute('time'), | ||
tags: postTags, | ||
hash: postsXML[i].getAttribute('hash'), | ||
notes: postsXML[i].getAttribute('extended'), | ||
shared: postsXML[i].getAttribute('shared') | ||
}); | ||
|
||
postTags.each(function(item){ | ||
tagIndex[item] = (tagIndex[item] || 0) + 1; | ||
}); | ||
} | ||
|
||
$each(tagIndex, function(item, key){ | ||
tags.push({name: key, count: item}); | ||
}); | ||
|
||
localStorage['posts'] = JSON.encode(a); | ||
localStorage['tags'] = JSON.encode(tags); | ||
localStorage['lastUpdate'] = formatDate(new Date()); | ||
|
||
self.tags = tags; | ||
self.posts = a; | ||
self.onComplete(); | ||
//self.fireEvent('update'); | ||
chrome.extension.sendRequest('updated'); | ||
}, | ||
|
||
onFailure: function(xhr){ | ||
console.log('posts/all failed'); | ||
//self.fireEvent('error'); | ||
chrome.extension.sendRequest('error'); | ||
self.onComplete(); | ||
} | ||
}).send({url: baseURL + 'posts/all'}); | ||
|
||
return this; | ||
} | ||
}); | ||
|
||
function formatDate(d){ | ||
var pad = function(s){ | ||
return ('' + s).length < 2 ? '0' + s : '' + s; | ||
} | ||
|
||
return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) + '-' + pad(d.getUTCDate()) + 'T' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()) + 'Z'; | ||
} | ||
|
||
var delicious; | ||
|
||
document.addEvent('domready', function(){ | ||
delicious = new Delicious(localStorage.username, localStorage.password, localStorage.autosynch); | ||
|
||
delicious.posts = JSON.decode(localStorage.posts) || []; | ||
delicious.tags = JSON.decode(localStorage.tags) || []; | ||
|
||
delicious.update(); | ||
|
||
chrome.extension.onRequest.addListener(function(request){ | ||
if(request == 'update'){ | ||
delicious.update(); | ||
}else if(request == 'reload'){ | ||
delicious.load(); | ||
}else if(request == 'updateoptions'){ | ||
delicious.cancel(); | ||
if(delicious.username != localStorage.username){ | ||
delicious.username = localStorage.username; | ||
localStorage.lastUpdate = ''; | ||
} | ||
delicious.password = localStorage.password; | ||
delicious.autosynch = Boolean(parseInt(localStorage.autosynch) || 0); | ||
delicious.updateIn(10000); //Update Bookmarks 10 seconds after options changed | ||
console.log('options updated'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
var List = new Class({ | ||
initialize: function(el, options){ | ||
this.element = $(el); | ||
this.defaultSort = null; //todo: remove | ||
|
||
this.localStorageID = options.localStorageID || null; //store sort order in local storage using this id | ||
this.createElement = options.createElement || $empty; | ||
this.data = options.data || []; | ||
this.sortOrder = options.sortOrder || 'asc'; | ||
this.sorters = options.sorters || {}; | ||
this.currentSorter = options.currentSorter || ''; | ||
this.currentFilter = ''; | ||
|
||
//restore saved sort order | ||
if(localStorage[this.localStorageID + 'Order']){ | ||
var sort = localStorage[this.localStorageID + 'Order'].split(' '); | ||
this.currentSorter = sort[0]; | ||
this.sortOrder = sort[1]; | ||
} | ||
}, | ||
|
||
filter: function(q){ | ||
this.currentFilter = q; | ||
var regExp = new RegExp(q, 'i'); | ||
var children = this.element.getChildren(); | ||
var el; | ||
|
||
for(var i = children.length - 1; i >= 0; i--){ | ||
el = children[i]; | ||
if(!q || el.get('text').match(regExp)){ | ||
el.removeClass('hidden'); | ||
}else{ | ||
el.addClass('hidden'); | ||
} | ||
} | ||
|
||
return this; | ||
}, | ||
|
||
sort: function(sorter){ | ||
if(sorter){ | ||
this.currentSorter = sorter; | ||
this.storeSortOrder(); | ||
} | ||
|
||
this.data.sort(this.sorters[this.currentSorter]); | ||
if(this.sortOrder == 'desc') | ||
this.data.reverse(); | ||
|
||
this.update(); | ||
|
||
return this; | ||
}, | ||
|
||
toggleSortOrder: function(){ | ||
if(this.sortOrder == 'asc'){ | ||
this.sortOrder = 'desc'; | ||
}else{ | ||
this.sortOrder = 'asc'; | ||
} | ||
this.storeSortOrder(); | ||
this.data.reverse(); | ||
this.update(); | ||
}, | ||
|
||
storeSortOrder: function(){ | ||
if(this.localStorageID){ | ||
//store sort order in local storage | ||
localStorage[this.localStorageID + 'Order'] = this.currentSorter + ' ' + this.sortOrder; | ||
} | ||
}, | ||
|
||
update: function(){ | ||
//this.element.empty(); | ||
this.element.getChildren().dispose(); | ||
|
||
for(var i = 0; i < this.data.length; i++){ | ||
this.element.appendChild(this.createElement(this.data[i])); | ||
} | ||
|
||
if(this.currentFilter) | ||
this.filter(this.currentFilter); | ||
|
||
return this; | ||
}, | ||
|
||
setData: function(data){ | ||
this.data = data; | ||
this.currentFilter = ''; | ||
this.sort(); | ||
return this; | ||
} | ||
}); |
Oops, something went wrong.