git-svn-id: file:///tmp/snv/trunk@6 12951d8a-c33d-4b7c-b961-822215c816e1

master
Abhinav Sarkar 14 years ago
parent a72ed0292c
commit b9d6c2f9a2
  1. 2
      chrome/content/TODO.txt
  2. 70
      chrome/content/diggsidebar.js
  3. 62
      chrome/content/diggsidebar.xul
  4. BIN
      chrome/content/image/digg_this.png
  5. 35
      chrome/skin/diggsidebar.css
  6. 6
      defaults/preferences/defaults.js

@ -1,4 +1,4 @@
move to JSON data format
move to JSON data format -- done
XBL -> Templates
format JS/refactor JS/Use FUEL
caching/db

@ -94,7 +94,7 @@ function populateMenu(e) {
menupopup = document.createElement('menupopup');
menupopup.setAttribute('id', topic.short_name + 'Popup');
['All', 'Popular', 'Upcoming'].forEach(
['All', 'Popular', 'Upcoming', 'Hot', 'Top'].forEach(
function (label) {
menuitem = document.createElement('menuitem');
menuitem.setAttribute('label', label);
@ -133,7 +133,7 @@ function populateMenu(e) {
menupopup = document.createElement('menupopup');
menupopup.setAttribute('id', filteredContainers.short_name[i] + 'Popup');
['All', 'Popular', 'Upcoming'].forEach(
['All', 'Popular', 'Upcoming', 'Hot', 'Top'].forEach(
function (label) {
menuitem = document.createElement('menuitem');
menuitem.setAttribute('label', label);
@ -162,7 +162,7 @@ function populateStoryList(e) {
}
var newStories = new Array();
Application.console.log(stories.length);
//Application.console.log(stories.length);
for (i=0; i<stories.length; i++) {
story = stories[i];
@ -194,34 +194,41 @@ function populateStoryList(e) {
//Adaptive update interval code START
sum = 0;
weights = [0.4, 0.3, 0.2, 0.1]
for (i=0; i<4; i++) {
if (stories[0].promote_date != null)
diff = stories[i].promote_date - stories[i+1].promote_date;
else
diff = stories[i].submit_date - stories[i+1].submit_date;
weights = [4, 3, 2, 1]
date = (stories[0].promote_date != null) ? 'promote_date' : 'submit_date';
stories.sort(function (a, b) {
if (a[date] > b[date]) return -1;
else if (a[date] < b[date]) return 1;
return 0;
});
for (i=0; i<Math.min(4, stories.length-1); i++) {
diff = stories[i][date] - stories[i+1][date];
sum += weights[i]*diff;
}
updateInterval = Math.round(sum*1000);
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
updateInterval = Math.round(
sum*1000/weights
.splice(0,Math.min(4, stories.length-1))
.reduce(function(a, b){return a + b;})
);
//Application.console.log(updateInterval);
previousUpdateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
prefs.setIntPref("extensions.diggsidebar.updateinterval", updateInterval);
var prefs = Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs;
updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
if (updateInterval > 0) {
previousUpdateInterval = prefs.get("updateinterval").value;
prefs.get("updateinterval").value = updateInterval;
if (previousUpdateInterval == updateInterval)
prefs.setIntPref("extensions.diggsidebar.updateintervaldecay", (updateIntervalDecay + 1));
else
prefs.setIntPref("extensions.diggsidebar.updateintervaldecay", 0);
updateIntervalDecay = prefs.get("updateintervaldecay").value;
if (previousUpdateInterval == updateInterval)
prefs.get("updateintervaldecay").value = updateIntervalDecay + 1;
else
prefs.get("updateintervaldecay").value = 0;
}
window.clearTimeout(gsti);
updateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
updateInterval = prefs.get("updateinterval").value;
updateIntervalDecay = prefs.get("updateintervaldecay").value;
timeout = Math.round(updateInterval*(Math.pow(1.5, updateIntervalDecay)));
gsti = window.setTimeout(getStories, timeout);
@ -317,9 +324,8 @@ function populateDescription(e) {
}
function getStories() {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
ep = prefs.getCharPref("extensions.diggsidebar.endpoint") || '';
var prefs = Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs;
ep = prefs.get("endpoint").value || '';
$ei('diggEndPoint').value = "digg" + ep;
fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') +
@ -353,9 +359,8 @@ function openInTab(href) {
}
function setEndPoint(ep) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref("extensions.diggsidebar.endpoint", ep);
var prefs = Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs;
prefs.get("endpoint").value = ep;
window.clearTimeout(gsti);
//window.clearInterval(psi);
getStories();
@ -369,10 +374,9 @@ function togglePlayPause() {
$ei('diggPlayPause').setAttribute("tooltiptext", "Click to Start autoupdate");
playing = false;
} else {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
updateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
var prefs = Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs;
updateInterval = prefs.get("extensions.diggsidebar.updateinterval").value;
updateIntervalDecay = prefs.get("extensions.diggsidebar.updateintervaldecay").value;
timeout = Math.round(updateInterval*(Math.pow(1.5, updateIntervalDecay)));
//newTimeout = Math.round(timeout*parseInt($ei("diggIndicator").getAttribute('value'))/100);

@ -18,6 +18,8 @@
<menuitem label="All" value="/all" oncommand="setEndPoint(this.value)" accesskey="A" />
<menuitem label="Popular" value="/popular" oncommand="setEndPoint(this.value)" accesskey="P" />
<menuitem label="Upcoming" value="/upcoming" oncommand="setEndPoint(this.value)" accesskey="U" />
<menuitem label="Hot" value="/hot" oncommand="setEndPoint(this.value)" accesskey="H" />
<menuitem label="Top" value="/top" oncommand="setEndPoint(this.value)" accesskey="T" />
<menuseparator />
<menu id="containerMenu" label="Containers" accesskey="C">
<menupopup id="containerPopup">
@ -38,8 +40,8 @@
<toolbaritem>
<progressmeter flex="1" width="5" mode="undetermined" id="diggIndicator" style="height: 85% !important; width: 30% !important" />
</toolbaritem>
</toolbar>
</toolbar>
</hbox>
<description id="diggEndPoint">digg</description>
<richlistbox flex="1" id="storyList" onselect="getDescription(this.selectedItem.id.substr(6))"></richlistbox>
@ -52,32 +54,34 @@
</html:span>
</html:div>
<html:div id="storyDetailsFormat" style="display:none">
<html:div class="storyDetails">
<html:div>
<html:span class="storyDate"></html:span>
<html:span class="storyStatus"></html:span>
</html:div>
<html:div>
<html:span class="storyContainer"></html:span> &gt; <html:span class="storyTopic"></html:span>
</html:div>
<html:div>
<html:span class="storyPopularity">
<html:img src="chrome://diggsidebar/content/image/digg.png" width="15px" />
<html:span class="storyDiggs"></html:span>
<html:img src="chrome://diggsidebar/content/image/comments.png" width="15px" />
<html:span class="storyComments"></html:span>
</html:span>
<html:div class="storyDetails">
<html:div>
<html:span class="storyContainer"></html:span> &gt;
<html:span class="storyTopic"></html:span> /
<html:span class="storyStatus"></html:span>
</html:div>
<html:div>
<html:span class="storyDesc"></html:span>
<html:a class="storyLink" onclick="openInTab(this.href); return false">
<html:img src="chrome://diggsidebar/content/image/external.png" />
</html:a>
</html:div>
<html:div style="text-align:center;">
<html:a class="storyHref" onclick="openInTab(this.href); return false">Digg This</html:a>
</html:div>
<html:div>
<html:span class="storyPopularity">
<html:img src="chrome://diggsidebar/content/image/digg.png" width="15px" />
<html:span class="storyDiggs"></html:span>
<html:img src="chrome://diggsidebar/content/image/comments.png" width="15px" />
<html:span class="storyComments"></html:span>
</html:span>
by
<html:span class="storyUserLink">
submitted by: <html:a class="storyUserName" onclick="openInTab(this.href); return false"></html:a>
</html:span>
</html:div>
<html:div class="storyDesc"></html:div>
<html:div>
<html:img src="chrome://diggsidebar/content/image/external.png" style="float: left" />
<html:a class="storyLink" onclick="openInTab(this.href); return false">Link to Article</html:a>
<html:a class="storyHref" onclick="openInTab(this.href); return false">Digg This</html:a>
<html:img src="chrome://diggsidebar/content/image/digg_this.png" width="15px" style="float: right" />
</html:div>
</html:div>
<html:a class="storyUserName" onclick="openInTab(this.href); return false"></html:a>
</html:span>
<html:span class="storyDate"></html:span>
</html:div>
</html:div>
</html:div>
</page>
</page>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -1,3 +1,11 @@
a {
color: blue;
cursor: pointer;
padding: 1px;
}
a img {
border: none;
}
.storyList {
margin: 1px;
border-style: solid !important;
@ -17,7 +25,6 @@
}
.storyDetails > div {
clear: both;
height: 15px;
padding: 1px 0px;
font-size: x-small;
}
@ -26,31 +33,24 @@
font-size: x-small;
font-weight: bold;
}
.storyDate, .storyDate, .storyLink {
float: left;
}
.storyStatus, .storyNew, .storyRead, .storyPopularity, .storyHref {
.storyNew, .storyRead, .storyPopularity {
float: right;
}
.storyNew, .storyRead {
padding: 0px 2px;
}
.storyHref {
font-weight: bold;
padding: 2px 3px;
vertical-align: middle;
}
.storyDesc {
height: auto!important;
}
.storyHeader {
cursor: pointer;
}
a {
color: blue;
cursor: pointer;
padding: 1px;
}
a:hover {
.storyHref:hover, .storyUserName:hover {
color: white;
background-color: blue;
}
@ -60,7 +60,6 @@ richlistitem {
padding-bottom: 3px;
color: #000000!important;
}
richlistitem > div{
width: 250px;
}
@ -72,8 +71,8 @@ richlistitem[selected="true"] .storyDetails {
border-top: 1px dashed black;
background-color: #FFFBF0;
}
richlistitem .storyTitle:hover {
background-color: green;
color: white;
}
}

@ -1,3 +1,3 @@
pref("extensions.diggsidebar.endpoint", "");
pref("extensions.diggsidebar.updateinterval", 30000);
pref("extensions.diggsidebar.updateintervaldecay", 0);
pref("extensions.diggsidebar@abhinavsarkar.net.endpoint", "");
pref("extensions.diggsidebar@abhinavsarkar.net.updateinterval", 30000);
pref("extensions.diggsidebar@abhinavsarkar.net.updateintervaldecay", 0);

Loading…
Cancel
Save