Browse Source

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

Abhinav Sarkar 13 years ago
parent
commit
b9d6c2f9a2

+ 1
- 1
chrome/content/TODO.txt View File

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

+ 37
- 33
chrome/content/diggsidebar.js View File

@@ -94,7 +94,7 @@ function populateMenu(e) {
94 94
         menupopup = document.createElement('menupopup');
95 95
         menupopup.setAttribute('id', topic.short_name + 'Popup');
96 96
 
97
-        ['All', 'Popular', 'Upcoming'].forEach(
97
+        ['All', 'Popular', 'Upcoming', 'Hot', 'Top'].forEach(
98 98
             function (label) {
99 99
                 menuitem = document.createElement('menuitem');
100 100
                 menuitem.setAttribute('label', label);
@@ -133,7 +133,7 @@ function populateMenu(e) {
133 133
         menupopup = document.createElement('menupopup');
134 134
         menupopup.setAttribute('id', filteredContainers.short_name[i] + 'Popup');
135 135
 
136
-        ['All', 'Popular', 'Upcoming'].forEach(
136
+        ['All', 'Popular', 'Upcoming', 'Hot', 'Top'].forEach(
137 137
             function (label) {
138 138
                 menuitem = document.createElement('menuitem');
139 139
                 menuitem.setAttribute('label', label);
@@ -162,7 +162,7 @@ function populateStoryList(e) {
162 162
     }
163 163
 
164 164
     var newStories = new Array();
165
-    Application.console.log(stories.length);
165
+    //Application.console.log(stories.length);
166 166
 
167 167
 	for (i=0; i<stories.length; i++) {
168 168
         story = stories[i];
@@ -194,34 +194,41 @@ function populateStoryList(e) {
194 194
 
195 195
     //Adaptive update interval code START
196 196
     sum = 0;
197
-    weights = [0.4, 0.3, 0.2, 0.1]
198
-    for (i=0; i<4; i++) {
199
-        if (stories[0].promote_date != null)
200
-            diff = stories[i].promote_date - stories[i+1].promote_date;
201
-        else
202
-            diff = stories[i].submit_date - stories[i+1].submit_date;
203
-
197
+    weights = [4, 3, 2, 1]
198
+    date = (stories[0].promote_date != null) ? 'promote_date' : 'submit_date';
199
+    stories.sort(function (a, b) {
200
+        if (a[date] > b[date]) return -1;
201
+        else if (a[date] < b[date]) return 1;
202
+        return 0;
203
+    });
204
+    for (i=0; i<Math.min(4, stories.length-1); i++) {
205
+        diff = stories[i][date] - stories[i+1][date];
204 206
         sum += weights[i]*diff;
205 207
     }
206
-    updateInterval = Math.round(sum*1000);
207
-
208
-    var prefs = Components.classes["@mozilla.org/preferences-service;1"].
209
-            getService(Components.interfaces.nsIPrefBranch);
208
+    updateInterval = Math.round(
209
+        sum*1000/weights
210
+        .splice(0,Math.min(4, stories.length-1))
211
+        .reduce(function(a, b){return a + b;})
212
+    );
213
+    //Application.console.log(updateInterval);
210 214
 
211
-    previousUpdateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
212
-    prefs.setIntPref("extensions.diggsidebar.updateinterval", updateInterval);
215
+    var prefs = Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs;
213 216
 
214
-    updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
217
+    if (updateInterval > 0) {
218
+        previousUpdateInterval = prefs.get("updateinterval").value;
219
+        prefs.get("updateinterval").value = updateInterval;
215 220
 
216
-    if (previousUpdateInterval == updateInterval)
217
-        prefs.setIntPref("extensions.diggsidebar.updateintervaldecay", (updateIntervalDecay + 1));
218
-    else
219
-        prefs.setIntPref("extensions.diggsidebar.updateintervaldecay", 0);
221
+        updateIntervalDecay = prefs.get("updateintervaldecay").value;
220 222
 
223
+        if (previousUpdateInterval == updateInterval)
224
+            prefs.get("updateintervaldecay").value = updateIntervalDecay + 1;
225
+        else
226
+            prefs.get("updateintervaldecay").value = 0;
227
+    }
221 228
     window.clearTimeout(gsti);
222 229
 
223
-    updateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
224
-    updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
230
+    updateInterval = prefs.get("updateinterval").value;
231
+    updateIntervalDecay = prefs.get("updateintervaldecay").value;
225 232
 
226 233
     timeout = Math.round(updateInterval*(Math.pow(1.5, updateIntervalDecay)));
227 234
     gsti = window.setTimeout(getStories, timeout);
@@ -317,9 +324,8 @@ function populateDescription(e) {
317 324
 }
318 325
 
319 326
 function getStories() {
320
-    var prefs = Components.classes["@mozilla.org/preferences-service;1"].
321
-            getService(Components.interfaces.nsIPrefBranch);
322
-    ep = prefs.getCharPref("extensions.diggsidebar.endpoint") || '';
327
+    var prefs = Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs;
328
+    ep = prefs.get("endpoint").value || '';
323 329
     $ei('diggEndPoint').value = "digg" + ep;
324 330
 
325 331
     fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') +
@@ -353,9 +359,8 @@ function openInTab(href) {
353 359
 }
354 360
 
355 361
 function setEndPoint(ep) {
356
-        var prefs = Components.classes["@mozilla.org/preferences-service;1"].
357
-                getService(Components.interfaces.nsIPrefBranch);
358
-        prefs.setCharPref("extensions.diggsidebar.endpoint", ep);
362
+        var prefs = Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs;
363
+        prefs.get("endpoint").value = ep;
359 364
         window.clearTimeout(gsti);
360 365
         //window.clearInterval(psi);
361 366
         getStories();
@@ -369,10 +374,9 @@ function togglePlayPause() {
369 374
                $ei('diggPlayPause').setAttribute("tooltiptext", "Click to Start autoupdate");
370 375
                playing = false;
371 376
         } else {
372
-                var prefs = Components.classes["@mozilla.org/preferences-service;1"].
373
-                        getService(Components.interfaces.nsIPrefBranch);
374
-                updateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
375
-                updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
377
+                var prefs = Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs;
378
+                updateInterval = prefs.get("extensions.diggsidebar.updateinterval").value;
379
+                updateIntervalDecay = prefs.get("extensions.diggsidebar.updateintervaldecay").value;
376 380
 
377 381
                 timeout = Math.round(updateInterval*(Math.pow(1.5, updateIntervalDecay)));
378 382
                 //newTimeout = Math.round(timeout*parseInt($ei("diggIndicator").getAttribute('value'))/100);

+ 33
- 29
chrome/content/diggsidebar.xul View File

@@ -18,6 +18,8 @@
18 18
                             <menuitem label="All" value="/all" oncommand="setEndPoint(this.value)" accesskey="A" />
19 19
                             <menuitem label="Popular" value="/popular" oncommand="setEndPoint(this.value)" accesskey="P" />
20 20
                             <menuitem label="Upcoming" value="/upcoming" oncommand="setEndPoint(this.value)" accesskey="U" />
21
+                            <menuitem label="Hot" value="/hot" oncommand="setEndPoint(this.value)" accesskey="H" />
22
+                            <menuitem label="Top" value="/top" oncommand="setEndPoint(this.value)" accesskey="T" />
21 23
                             <menuseparator />
22 24
                             <menu id="containerMenu" label="Containers" accesskey="C">
23 25
                                 <menupopup id="containerPopup">
@@ -38,8 +40,8 @@
38 40
             <toolbaritem>
39 41
                 <progressmeter flex="1" width="5" mode="undetermined" id="diggIndicator" style="height: 85% !important; width: 30% !important" />
40 42
             </toolbaritem>
41
-            
42
-        </toolbar>        
43
+
44
+        </toolbar>
43 45
     </hbox>
44 46
     <description id="diggEndPoint">digg</description>
45 47
     <richlistbox flex="1" id="storyList" onselect="getDescription(this.selectedItem.id.substr(6))"></richlistbox>
@@ -52,32 +54,34 @@
52 54
         </html:span>
53 55
     </html:div>
54 56
     <html:div id="storyDetailsFormat" style="display:none">
55
-	<html:div class="storyDetails">
56
-	    <html:div>
57
-		<html:span class="storyDate"></html:span>
58
-		<html:span class="storyStatus"></html:span>
59
-	    </html:div>
60
-	    <html:div>
61
-		<html:span class="storyContainer"></html:span> &gt; <html:span class="storyTopic"></html:span>
62
-	    </html:div>
63
-	    <html:div>
64
-		<html:span class="storyPopularity">
65
-		    <html:img src="chrome://diggsidebar/content/image/digg.png" width="15px" />
66
-		    <html:span class="storyDiggs"></html:span>
67
-		    <html:img src="chrome://diggsidebar/content/image/comments.png" width="15px" />
68
-		    <html:span class="storyComments"></html:span>
69
-		</html:span>
57
+        <html:div class="storyDetails">
58
+            <html:div>
59
+                <html:span class="storyContainer"></html:span> &gt;
60
+                <html:span class="storyTopic"></html:span> /
61
+                <html:span class="storyStatus"></html:span>
62
+            </html:div>
63
+            <html:div>
64
+                <html:span class="storyDesc"></html:span>
65
+                <html:a class="storyLink" onclick="openInTab(this.href); return false">
66
+                    <html:img src="chrome://diggsidebar/content/image/external.png" />
67
+                </html:a>
68
+            </html:div>
69
+            <html:div style="text-align:center;">
70
+                <html:a class="storyHref" onclick="openInTab(this.href); return false">Digg This</html:a>
71
+            </html:div>
72
+            <html:div>
73
+                <html:span class="storyPopularity">
74
+                    <html:img src="chrome://diggsidebar/content/image/digg.png" width="15px" />
75
+                    <html:span class="storyDiggs"></html:span>
76
+                    <html:img src="chrome://diggsidebar/content/image/comments.png" width="15px" />
77
+                    <html:span class="storyComments"></html:span>
78
+                </html:span>
79
+                by
70 80
                 <html:span class="storyUserLink">
71
-		    submitted by: <html:a class="storyUserName" onclick="openInTab(this.href); return false"></html:a>
72
-		</html:span>
73
-	    </html:div>
74
-	    <html:div class="storyDesc"></html:div>
75
-	    <html:div>
76
-                <html:img src="chrome://diggsidebar/content/image/external.png"  style="float: left" />
77
-		<html:a class="storyLink" onclick="openInTab(this.href); return false">Link to Article</html:a>
78
-		<html:a class="storyHref" onclick="openInTab(this.href); return false">Digg This</html:a>
79
-                <html:img src="chrome://diggsidebar/content/image/digg_this.png" width="15px" style="float: right" />
80
-	    </html:div>
81
-	</html:div>
81
+                   <html:a class="storyUserName" onclick="openInTab(this.href); return false"></html:a>
82
+                </html:span>
83
+                <html:span class="storyDate"></html:span>
84
+            </html:div>
85
+        </html:div>
82 86
     </html:div>
83
-</page>
87
+</page>

BIN
chrome/content/image/digg_this.png View File


+ 17
- 18
chrome/skin/diggsidebar.css View File

@@ -1,3 +1,11 @@
1
+a {
2
+    color: blue;
3
+    cursor: pointer;
4
+    padding: 1px;
5
+}
6
+a img {
7
+    border: none;
8
+}
1 9
 .storyList {
2 10
     margin: 1px;
3 11
     border-style: solid !important;
@@ -17,7 +25,6 @@
17 25
 }
18 26
 .storyDetails > div {
19 27
     clear: both;
20
-    height: 15px;
21 28
     padding: 1px 0px;
22 29
     font-size: x-small;
23 30
 }
@@ -26,31 +33,24 @@
26 33
     font-size: x-small;
27 34
     font-weight: bold;
28 35
 }
29
-.storyDate, .storyDate, .storyLink {
30
-    float: left;
31
-}
32
-
33
-.storyStatus, .storyNew, .storyRead, .storyPopularity, .storyHref {
36
+.storyNew, .storyRead, .storyPopularity {
34 37
     float: right;
35 38
 }
36
-
37 39
 .storyNew, .storyRead {
38 40
     padding: 0px 2px;
39 41
 }
42
+.storyHref {
43
+    font-weight: bold;
44
+    padding: 2px 3px;
45
+    vertical-align: middle;
46
+}
40 47
 .storyDesc {
41 48
     height: auto!important;
42 49
 }
43
-
44 50
 .storyHeader {
45 51
     cursor: pointer;
46 52
 }
47
-a {
48
-    color: blue;
49
-    cursor: pointer;
50
-    padding: 1px;
51
-}
52
-
53
-a:hover {
53
+.storyHref:hover, .storyUserName:hover {
54 54
     color: white;
55 55
     background-color: blue;
56 56
 }
@@ -60,7 +60,6 @@ richlistitem {
60 60
     padding-bottom: 3px;
61 61
     color: #000000!important;
62 62
 }
63
-
64 63
 richlistitem > div{
65 64
     width: 250px;
66 65
 }
@@ -72,8 +71,8 @@ richlistitem[selected="true"] .storyDetails {
72 71
     border-top: 1px dashed black;
73 72
     background-color: #FFFBF0;
74 73
 }
75
-    
74
+
76 75
 richlistitem .storyTitle:hover {
77 76
     background-color: green;
78 77
     color: white;
79
-}
78
+}

+ 3
- 3
defaults/preferences/defaults.js View File

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

Loading…
Cancel
Save