diff --git a/chrome/content/TODO.txt b/chrome/content/TODO.txt new file mode 100644 index 0000000..5de5e70 --- /dev/null +++ b/chrome/content/TODO.txt @@ -0,0 +1,7 @@ +move to JSON data format +XBL -> Templates +format JS/refactor JS/Use FUEL +caching/db +threading +new UI +JQuery diff --git a/chrome/content/diggsidebar.js b/chrome/content/diggsidebar.js index 5ae6569..b7c40f3 100644 --- a/chrome/content/diggsidebar.js +++ b/chrome/content/diggsidebar.js @@ -28,7 +28,7 @@ function $ec(className, parentNode) { return elements[i]; } } - + } //Xpath function $xp(aNode, aExpr) { @@ -66,7 +66,7 @@ function fetchData(url, handler) { request.open("GET", url, true); request.send(null); //$ei('diggIndicator').style.display = ''; - + } function handleError(e) { @@ -75,191 +75,165 @@ function handleError(e) { } function populateMenu(e) { - XHR = e.target; - //myDump(XHR.responseText); - data = XHR.responseXML; - topics = $xp(data, "/topics/topic"); - while ($ei('topicPopup').firstChild) { - $ei('topicPopup').removeChild($ei('topicPopup').firstChild); + XHR = e.target; + data = decodeJson(XHR.responseText); + topics = data.topics; + containers = new Array(); + + while ($ei('topicPopup').firstChild) { + $ei('topicPopup').removeChild($ei('topicPopup').firstChild); + } + + for (i=0; i 0) && (min > 0)) ? - (hr + " hr " + min + " mins ago") : - ((hr == 0) && (min > 0)) ? - (min + " mins ago") : - ((hr == 0) && (min == 0)) ? - "just now" : ""; - storyStatus.innerHTML = $a(story, 'status').escapeEntities(); - //alert($a($et('container', story), 'name').escapeEntities()); - storyContainer.innerHTML = $a($et('container', story), 'name').escapeEntities(); - storyTopic.innerHTML = $a($et('topic', story), 'name').escapeEntities(); - storyUserName.href = "http://digg.com/users/" + $a($et('user', story), 'name').escapeEntities(); - storyUserName.innerHTML = $a($et('user', story), 'name').escapeEntities(); - storyDiggs.innerHTML = $a(story, 'diggs').escapeEntities(); - storyComments.innerHTML = $a(story, 'comments').escapeEntities(); - storyDesc.innerHTML = $et('description', story).textContent.escapeEntities(); - storyLink.href = $a(story, 'link'); - storyHref.href = $a(story, 'href'); - - storyCEIcon.src = "chrome://diggsidebar/content/image/down.jpg"; - storyRead.style.textDecoration = "line-through"; - storyRead.style.backgroundColor = "black"; - storyRead.style.color = "white"; - storyRead.title = "Read"; - storyNew.style.textDecoration = "line-through"; - storyNew.style.backgroundColor = "black"; - storyNew.style.color = "white"; - storyNew.title = "Old"; - + (hr + " hr " + min + " mins ago") : + ((hr == 0) && (min > 0)) ? + (min + " mins ago") : + ((hr == 0) && (min == 0)) ? + "just now" : ""; + storyStatus.innerHTML = story.status.escapeEntities(); + storyContainer.innerHTML = story.container.name.escapeEntities(); + storyTopic.innerHTML = story.topic.name.escapeEntities(); + storyUserName.href = "http://digg.com/users/" + story.user.name; + storyUserName.innerHTML = story.user.name.escapeEntities(); + storyDiggs.innerHTML = story.diggs; + storyComments.innerHTML = story.comments; + storyDesc.innerHTML = story.description.escapeEntities(); + storyLink.href = story.link; + storyHref.href = story.href; + + storyCEIcon.src = "chrome://diggsidebar/content/image/down.jpg"; + storyRead.style.textDecoration = "line-through"; + storyRead.style.backgroundColor = "black"; + storyRead.style.color = "white"; + storyRead.title = "Read"; + storyNew.style.textDecoration = "line-through"; + storyNew.style.backgroundColor = "black"; + storyNew.style.color = "white"; + storyNew.title = "Old"; + storyDetails.style.display = 'block'; - - $ei('diggIndicator').style.display = 'none'; + + $ei('diggIndicator').style.display = 'none'; } function getStories() { - //alert("inside getStories"); - var prefs = Components.classes["@mozilla.org/preferences-service;1"]. - getService(Components.interfaces.nsIPrefBranch); - ep = prefs.getCharPref("extensions.diggsidebar.endpoint") || ''; - //alert(ep); - $ei('diggEndPoint').value = "digg" + ep; - - //ep =''; - fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') + "?count=30" + + var prefs = Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefBranch); + ep = prefs.getCharPref("extensions.diggsidebar.endpoint") || ''; + $ei('diggEndPoint').value = "digg" + ep; + + fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') + + "?count=30" + "&type=json" + "&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"), populateStoryList); - //gsti = window.setTimeout(getStories, prefs.getIntPref("extensions.diggsidebar.updateinterval")); + //gsti = window.setTimeout(getStories, prefs.getIntPref("extensions.diggsidebar.updateinterval")); } function getDescription(storyId) { - myDump(storyId); - if (storyId == null) return; - fetchData("http://services.digg.com/story/" + storyId + - "?appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"), + if (storyId == null) return; + fetchData("http://services.digg.com/story/" + storyId + "?type=json" + + "&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"), populateDescription); } function createMenu() { - fetchData("http://services.digg.com/topics" + - "?appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"), + fetchData("http://services.digg.com/topics" + "?type=json" + + "&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"), populateMenu); } @@ -403,7 +373,7 @@ function togglePlayPause() { getService(Components.interfaces.nsIPrefBranch); updateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval") updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay"); - + timeout = Math.round(updateInterval*(Math.pow(1.5, updateIntervalDecay))); //newTimeout = Math.round(timeout*parseInt($ei("diggIndicator").getAttribute('value'))/100); gsti = window.setTimeout(getStories, timeout); @@ -415,13 +385,11 @@ function togglePlayPause() { } } - -function myDump(aMessage) { - var consoleService = Components.classes["@mozilla.org/consoleservice;1"] - .getService(Components.interfaces.nsIConsoleService); - consoleService.logStringMessage("Diggsidebar: " + aMessage); -} - +function decodeJson(string) { + var json = Components.classes["@mozilla.org/dom/json;1"] + .createInstance(Components.interfaces.nsIJSON); + return json.decode(string); +}; /*TODO preferences @@ -435,12 +403,12 @@ function myDump(aMessage) { added error notification added accesskeys added new story notification - + v0.2.1 adaptive polling interval promote_date pause/play - + v0.5 new ui -*/ \ No newline at end of file +*/