Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis.gid committed May 14, 2010
0 parents commit b6c7113
Show file tree
Hide file tree
Showing 27 changed files with 4,295 additions and 0 deletions.
Empty file added .hgignore
Empty file.
10 changes: 10 additions & 0 deletions background.html
@@ -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>
Binary file added images/breadcrumbs_splitter.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/close.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/edit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon_16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon_20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sort_asc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sort_desc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/spinner.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tag.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tagged.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
174 changes: 174 additions & 0 deletions js/background.js
@@ -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');
}
});
});
93 changes: 93 additions & 0 deletions js/list.js
@@ -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;
}
});

0 comments on commit b6c7113

Please sign in to comment.