|
@@ -28,7 +28,7 @@ function $ec(className, parentNode) {
|
28
|
28
|
return elements[i];
|
29
|
29
|
}
|
30
|
30
|
}
|
31
|
|
-
|
|
31
|
+
|
32
|
32
|
}
|
33
|
33
|
//Xpath
|
34
|
34
|
function $xp(aNode, aExpr) {
|
|
@@ -66,7 +66,7 @@ function fetchData(url, handler) {
|
66
|
66
|
request.open("GET", url, true);
|
67
|
67
|
request.send(null);
|
68
|
68
|
//$ei('diggIndicator').style.display = '';
|
69
|
|
-
|
|
69
|
+
|
70
|
70
|
}
|
71
|
71
|
|
72
|
72
|
function handleError(e) {
|
|
@@ -75,191 +75,165 @@ function handleError(e) {
|
75
|
75
|
}
|
76
|
76
|
|
77
|
77
|
function populateMenu(e) {
|
78
|
|
- XHR = e.target;
|
79
|
|
- //myDump(XHR.responseText);
|
80
|
|
- data = XHR.responseXML;
|
81
|
|
- topics = $xp(data, "/topics/topic");
|
82
|
|
- while ($ei('topicPopup').firstChild) {
|
83
|
|
- $ei('topicPopup').removeChild($ei('topicPopup').firstChild);
|
84
|
|
- }
|
85
|
|
-
|
86
|
|
- for (i=0; i<topics.length; i++) {
|
87
|
|
- menu = document.createElement('menu');
|
88
|
|
- menu.setAttribute('id', $a(topics[i], 'short_name') + 'Menu');
|
89
|
|
- menu.setAttribute('label', $a(topics[i], 'name'));
|
90
|
|
- menu.setAttribute('accesskey', $a(topics[i], 'name').substring(0, 1));
|
91
|
|
-
|
92
|
|
- menupopup = document.createElement('menupopup');
|
93
|
|
- menupopup.setAttribute('id', $a(topics[i], 'short_name') + 'Popup');
|
94
|
|
-
|
95
|
|
- menuitem = document.createElement('menuitem');
|
96
|
|
- menuitem.setAttribute('label', 'All');
|
97
|
|
- menuitem.setAttribute('value', '/topic/' + $a(topics[i], 'short_name') + '/all');
|
98
|
|
- menuitem.setAttribute('accesskey', 'A');
|
99
|
|
- menuitem.setAttribute('oncommand', "setEndPoint(this.value)");
|
100
|
|
- menupopup.appendChild(menuitem);
|
101
|
|
-
|
102
|
|
- menuitem = document.createElement('menuitem');
|
103
|
|
- menuitem.setAttribute('label', 'Popular');
|
104
|
|
- menuitem.setAttribute('value', '/topic/' + $a(topics[i], 'short_name') + '/popular');
|
105
|
|
- menuitem.setAttribute('accesskey', 'P');
|
106
|
|
- menuitem.setAttribute('oncommand', "setEndPoint(this.value)");
|
107
|
|
- menupopup.appendChild(menuitem);
|
108
|
|
-
|
|
78
|
+ XHR = e.target;
|
|
79
|
+ data = decodeJson(XHR.responseText);
|
|
80
|
+ topics = data.topics;
|
|
81
|
+ containers = new Array();
|
|
82
|
+
|
|
83
|
+ while ($ei('topicPopup').firstChild) {
|
|
84
|
+ $ei('topicPopup').removeChild($ei('topicPopup').firstChild);
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ for (i=0; i<topics.length; i++) {
|
|
88
|
+ topic = topics[i];
|
|
89
|
+ menu = document.createElement('menu');
|
|
90
|
+ menu.setAttribute('id', topic.short_name + 'Menu');
|
|
91
|
+ menu.setAttribute('label', topic.name);
|
|
92
|
+ menu.setAttribute('accesskey', topic.name.charAt(0));
|
|
93
|
+
|
|
94
|
+ menupopup = document.createElement('menupopup');
|
|
95
|
+ menupopup.setAttribute('id', topic.short_name + 'Popup');
|
|
96
|
+
|
|
97
|
+ ['All', 'Popular', 'Upcoming'].forEach(
|
|
98
|
+ function (label) {
|
109
|
99
|
menuitem = document.createElement('menuitem');
|
110
|
|
- menuitem.setAttribute('label', 'Upcoming');
|
111
|
|
- menuitem.setAttribute('value', '/topic/' + $a(topics[i], 'short_name') + '/upcoming');
|
112
|
|
- menuitem.setAttribute('accesskey', 'U');
|
|
100
|
+ menuitem.setAttribute('label', label);
|
|
101
|
+ menuitem.setAttribute('value', '/topic/' + topic.short_name + '/' + label.toLowerCase());
|
|
102
|
+ menuitem.setAttribute('accesskey', label.charAt(0));
|
113
|
103
|
menuitem.setAttribute('oncommand', "setEndPoint(this.value)");
|
114
|
104
|
menupopup.appendChild(menuitem);
|
115
|
|
-
|
116
|
|
- menu.appendChild(menupopup);
|
117
|
|
-
|
118
|
|
- //alert($a(topics[i], 'name'));
|
119
|
|
- $ei('topicPopup').appendChild(menu);
|
120
|
|
- }
|
121
|
|
-
|
122
|
|
- containers = $xp(data, "/topics/topic/container");
|
123
|
|
- while ($ei('containerPopup').firstChild) {
|
124
|
|
- $ei('containerPopup').removeChild($ei('containerPopup').firstChild);
|
125
|
|
- }
|
126
|
|
-
|
127
|
|
- filteredContainers = {name: [], short_name: []};
|
128
|
|
- for (i=0; i<containers.length; i++) {
|
129
|
|
- name = $a(containers[i], 'name');
|
130
|
|
- short_name = $a(containers[i], 'short_name');
|
131
|
|
- if (filteredContainers.name.indexOf(name) == -1) {
|
132
|
|
- filteredContainers.name.push(name);
|
133
|
|
- filteredContainers.short_name.push(short_name);
|
134
|
|
- }
|
|
105
|
+ }
|
|
106
|
+ );
|
|
107
|
+ menu.appendChild(menupopup);
|
|
108
|
+ $ei('topicPopup').appendChild(menu);
|
|
109
|
+
|
|
110
|
+ containers.push(topic.container);
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ while ($ei('containerPopup').firstChild) {
|
|
114
|
+ $ei('containerPopup').removeChild($ei('containerPopup').firstChild);
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ filteredContainers = {name: [], short_name: []};
|
|
118
|
+ for (i=0; i<containers.length; i++) {
|
|
119
|
+ name = containers[i].name;
|
|
120
|
+ short_name = containers[i].short_name;
|
|
121
|
+ if (filteredContainers.name.indexOf(name) == -1) {
|
|
122
|
+ filteredContainers.name.push(name);
|
|
123
|
+ filteredContainers.short_name.push(short_name);
|
135
|
124
|
}
|
136
|
|
- //myDump(uneval(filteredContainers));
|
137
|
|
-
|
138
|
|
- for (i=0; i<filteredContainers.name.length; i++) {
|
139
|
|
- menu = document.createElement('menu');
|
140
|
|
- menu.setAttribute('id', filteredContainers.short_name[i] + 'Menu');
|
141
|
|
- menu.setAttribute('label', filteredContainers.name[i]);
|
142
|
|
- menu.setAttribute('accesskey', filteredContainers.name[i].substring(0, 1));
|
143
|
|
-
|
144
|
|
- menupopup = document.createElement('menupopup');
|
145
|
|
- menupopup.setAttribute('id', filteredContainers.short_name[i] + 'Popup');
|
146
|
|
-
|
147
|
|
- menuitem = document.createElement('menuitem');
|
148
|
|
- menuitem.setAttribute('label', 'All');
|
149
|
|
- menuitem.setAttribute('value', '/container/' + filteredContainers.short_name[i] + '/all');
|
150
|
|
- menuitem.setAttribute('accesskey', 'A');
|
151
|
|
- menuitem.setAttribute('oncommand', "setEndPoint(this.value)");
|
152
|
|
- menupopup.appendChild(menuitem);
|
153
|
|
-
|
154
|
|
- menuitem = document.createElement('menuitem');
|
155
|
|
- menuitem.setAttribute('label', 'Popular');
|
156
|
|
- menuitem.setAttribute('value', '/container/' + filteredContainers.short_name[i] + '/popular');
|
157
|
|
- menuitem.setAttribute('accesskey', 'P');
|
158
|
|
- menuitem.setAttribute('oncommand', "setEndPoint(this.value)");
|
159
|
|
- menupopup.appendChild(menuitem);
|
160
|
|
-
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+ for (i=0; i<filteredContainers.name.length; i++) {
|
|
128
|
+ menu = document.createElement('menu');
|
|
129
|
+ menu.setAttribute('id', filteredContainers.short_name[i] + 'Menu');
|
|
130
|
+ menu.setAttribute('label', filteredContainers.name[i]);
|
|
131
|
+ menu.setAttribute('accesskey', filteredContainers.name[i].charAt(0));
|
|
132
|
+
|
|
133
|
+ menupopup = document.createElement('menupopup');
|
|
134
|
+ menupopup.setAttribute('id', filteredContainers.short_name[i] + 'Popup');
|
|
135
|
+
|
|
136
|
+ ['All', 'Popular', 'Upcoming'].forEach(
|
|
137
|
+ function (label) {
|
161
|
138
|
menuitem = document.createElement('menuitem');
|
162
|
|
- menuitem.setAttribute('label', 'Upcoming');
|
163
|
|
- menuitem.setAttribute('value', '/container/' + filteredContainers.short_name[i] + '/upcoming');
|
164
|
|
- menuitem.setAttribute('accesskey', 'U');
|
|
139
|
+ menuitem.setAttribute('label', label);
|
|
140
|
+ menuitem.setAttribute('value', '/container/' +
|
|
141
|
+ filteredContainers.short_name[i] + '/' + label.toLowerCase());
|
|
142
|
+ menuitem.setAttribute('accesskey', label.charAt(0));
|
165
|
143
|
menuitem.setAttribute('oncommand', "setEndPoint(this.value)");
|
166
|
144
|
menupopup.appendChild(menuitem);
|
167
|
|
-
|
168
|
|
- menu.appendChild(menupopup);
|
169
|
|
-
|
170
|
|
- //alert($a(topics[i], 'name'));
|
171
|
|
- $ei('containerPopup').appendChild(menu);
|
172
|
|
- }
|
173
|
|
- $ei('diggIndicator').style.display = 'none';
|
|
145
|
+ }
|
|
146
|
+ );
|
|
147
|
+
|
|
148
|
+ menu.appendChild(menupopup);
|
|
149
|
+ $ei('containerPopup').appendChild(menu);
|
|
150
|
+ }
|
|
151
|
+ $ei('diggIndicator').style.display = 'none';
|
174
|
152
|
}
|
175
|
153
|
|
176
|
154
|
function populateStoryList(e) {
|
177
|
|
- //alert("inside populateStoryList");
|
178
|
155
|
XHR = e.target;
|
179
|
|
- //alert(XHR.responseText);
|
180
|
|
- data = XHR.responseXML;
|
181
|
|
- stories = $xp(data, "/stories/story");
|
182
|
|
- //alert(stories.length);
|
183
|
|
- //dumpProperties(titles[0]);
|
184
|
|
-
|
185
|
|
- //selectedItem = $ei('storyList').selectedItem;
|
186
|
|
-
|
187
|
|
- while ($ei('storyList').firstChild) {
|
188
|
|
- $ei('storyList').removeChild($ei('storyList').firstChild);
|
189
|
|
- }
|
190
|
|
-
|
191
|
|
-
|
192
|
|
- var newStories = new Array();
|
|
156
|
+ //Application.console.log(XHR.responseText);
|
|
157
|
+ data = decodeJson(XHR.responseText);
|
|
158
|
+ stories = data.stories;
|
|
159
|
+
|
|
160
|
+ while ($ei('storyList').firstChild) {
|
|
161
|
+ $ei('storyList').removeChild($ei('storyList').firstChild);
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ var newStories = new Array();
|
|
165
|
+ Application.console.log(stories.length);
|
|
166
|
+
|
193
|
167
|
for (i=0; i<stories.length; i++) {
|
194
|
|
- //alert(stories[i]);
|
195
|
|
- title = $et('title', stories[i]).textContent;
|
196
|
|
- id = $a(stories[i], 'id');
|
197
|
|
- newStories.push(id);
|
198
|
|
- //alert(title + " " + id);
|
199
|
|
- listitem = $ei('storyList').appendChild(document.createElement('richlistitem'));
|
200
|
|
- listitem.id = "story_" + id;
|
201
|
|
- htmllistitem = listitem.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml","html:div"));
|
202
|
|
- htmllistitem.innerHTML = $ei('storyTitleFormat').innerHTML;
|
203
|
|
- storyTitle = listitem.getElementsByAttribute('class', 'storyTitle')[0];
|
204
|
|
- storyTitle.appendChild(document.createTextNode(title));
|
205
|
|
-
|
206
|
|
- htmllistitem.innerHTML += $ei('storyDetailsFormat').innerHTML;
|
207
|
|
-
|
208
|
|
- storyNew= listitem.getElementsByAttribute('class', 'storyNew')[0];
|
209
|
|
-
|
210
|
|
- if (currentStories.indexOf(id) != -1) {
|
211
|
|
- storyNew.style.textDecoration = "line-through";
|
212
|
|
- storyNew.style.backgroundColor = "black";
|
213
|
|
- storyNew.style.color = "white";
|
214
|
|
- storyNew.title = "Old";
|
215
|
|
- }
|
216
|
|
- }
|
217
|
|
- currentStories = newStories;
|
218
|
|
- //$ei('diggIndicator').style.display = 'none';
|
219
|
|
-
|
220
|
|
- //Adaptive update interval code START
|
221
|
|
- sum = 0;
|
222
|
|
- weights = [0.4, 0.3, 0.2, 0.1]
|
223
|
|
- for (i=0; i<4; i++) {
|
224
|
|
- if ($a(stories[0], 'promote_date') != null)
|
225
|
|
- diff = parseInt($a(stories[i], 'promote_date')) - parseInt($a(stories[i+1], 'promote_date'));
|
226
|
|
- else
|
227
|
|
- diff = parseInt($a(stories[i], 'submit_date')) - parseInt($a(stories[i+1], 'submit_date'));
|
228
|
|
-
|
229
|
|
- sum += weights[i]*diff;
|
|
168
|
+ story = stories[i];
|
|
169
|
+ newStories.push(story.id);
|
|
170
|
+ //Application.console.log(i + " " + story.title + " " + story.id);
|
|
171
|
+
|
|
172
|
+ listitem = $ei('storyList').appendChild(document.createElement('richlistitem'));
|
|
173
|
+ listitem.id = "story_" + story.id;
|
|
174
|
+
|
|
175
|
+ htmllistitem = listitem.appendChild(
|
|
176
|
+ document.createElementNS("http://www.w3.org/1999/xhtml","html:div"));
|
|
177
|
+ htmllistitem.innerHTML = $ei('storyTitleFormat').innerHTML;
|
|
178
|
+
|
|
179
|
+ storyTitle = listitem.getElementsByAttribute('class', 'storyTitle')[0];
|
|
180
|
+ storyTitle.appendChild(document.createTextNode(story.title));
|
|
181
|
+
|
|
182
|
+ htmllistitem.innerHTML += $ei('storyDetailsFormat').innerHTML;
|
|
183
|
+
|
|
184
|
+ storyNew= listitem.getElementsByAttribute('class', 'storyNew')[0];
|
|
185
|
+
|
|
186
|
+ if (currentStories.indexOf(story.id) != -1) {
|
|
187
|
+ storyNew.style.textDecoration = "line-through";
|
|
188
|
+ storyNew.style.backgroundColor = "black";
|
|
189
|
+ storyNew.style.color = "white";
|
|
190
|
+ storyNew.title = "Old";
|
230
|
191
|
}
|
231
|
|
- updateInterval = Math.round(sum*1000);
|
232
|
|
-
|
233
|
|
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].
|
234
|
|
- getService(Components.interfaces.nsIPrefBranch);
|
235
|
|
-
|
236
|
|
- previousUpdateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
|
237
|
|
- prefs.setIntPref("extensions.diggsidebar.updateinterval", updateInterval);
|
238
|
|
-
|
239
|
|
- updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
|
240
|
|
-
|
241
|
|
- if (previousUpdateInterval == updateInterval)
|
242
|
|
- prefs.setIntPref("extensions.diggsidebar.updateintervaldecay", (updateIntervalDecay + 1));
|
|
192
|
+ }
|
|
193
|
+ currentStories = newStories;
|
|
194
|
+
|
|
195
|
+ //Adaptive update interval code START
|
|
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;
|
243
|
201
|
else
|
244
|
|
- prefs.setIntPref("extensions.diggsidebar.updateintervaldecay", 0);
|
245
|
|
-
|
246
|
|
- window.clearTimeout(gsti);
|
247
|
|
-
|
248
|
|
- updateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
|
249
|
|
- updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
|
250
|
|
-
|
251
|
|
- timeout = Math.round(updateInterval*(Math.pow(1.5, updateIntervalDecay)));
|
252
|
|
- gsti = window.setTimeout(getStories, timeout);
|
253
|
|
- //Adaptive update interval code END
|
254
|
|
-
|
255
|
|
- $ei('diggIndicator').style.display = 'none';
|
256
|
|
-
|
257
|
|
- //prefs.setIntPref("extensions.diggsidebar.progress", 100);
|
258
|
|
- //$ei("diggIndicator").setAttribute('mode', 'determined');
|
259
|
|
- //$ei("diggIndicator").setAttribute('value', 100);
|
260
|
|
- //psi = window.setInterval(showProgress, Math.round(timeout/100));
|
261
|
|
- //window.setTimeout("window.clearInterval(psi)", timeout);
|
262
|
|
-
|
|
202
|
+ diff = stories[i].submit_date - stories[i+1].submit_date;
|
|
203
|
+
|
|
204
|
+ sum += weights[i]*diff;
|
|
205
|
+ }
|
|
206
|
+ updateInterval = Math.round(sum*1000);
|
|
207
|
+
|
|
208
|
+ var prefs = Components.classes["@mozilla.org/preferences-service;1"].
|
|
209
|
+ getService(Components.interfaces.nsIPrefBranch);
|
|
210
|
+
|
|
211
|
+ previousUpdateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
|
|
212
|
+ prefs.setIntPref("extensions.diggsidebar.updateinterval", updateInterval);
|
|
213
|
+
|
|
214
|
+ updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
|
|
215
|
+
|
|
216
|
+ if (previousUpdateInterval == updateInterval)
|
|
217
|
+ prefs.setIntPref("extensions.diggsidebar.updateintervaldecay", (updateIntervalDecay + 1));
|
|
218
|
+ else
|
|
219
|
+ prefs.setIntPref("extensions.diggsidebar.updateintervaldecay", 0);
|
|
220
|
+
|
|
221
|
+ window.clearTimeout(gsti);
|
|
222
|
+
|
|
223
|
+ updateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
|
|
224
|
+ updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
|
|
225
|
+
|
|
226
|
+ timeout = Math.round(updateInterval*(Math.pow(1.5, updateIntervalDecay)));
|
|
227
|
+ gsti = window.setTimeout(getStories, timeout);
|
|
228
|
+ //Adaptive update interval code END
|
|
229
|
+
|
|
230
|
+ $ei('diggIndicator').style.display = 'none';
|
|
231
|
+
|
|
232
|
+ //prefs.setIntPref("extensions.diggsidebar.progress", 100);
|
|
233
|
+ //$ei("diggIndicator").setAttribute('mode', 'determined');
|
|
234
|
+ //$ei("diggIndicator").setAttribute('value', 100);
|
|
235
|
+ //psi = window.setInterval(showProgress, Math.round(timeout/100));
|
|
236
|
+ //window.setTimeout("window.clearInterval(psi)", timeout);
|
263
|
237
|
}
|
264
|
238
|
|
265
|
239
|
//function showProgress() {
|
|
@@ -267,108 +241,104 @@ function populateStoryList(e) {
|
267
|
241
|
// getService(Components.interfaces.nsIPrefBranch);
|
268
|
242
|
// progress = prefs.getIntPref("extensions.diggsidebar.progress");
|
269
|
243
|
// prefs.setIntPref("extensions.diggsidebar.progress", (progress - 1));
|
270
|
|
-//
|
|
244
|
+//
|
271
|
245
|
// $ei("diggIndicator").setAttribute('value', (parseInt($ei("diggIndicator").getAttribute('value')) - 1));
|
272
|
246
|
//}
|
273
|
|
-
|
|
247
|
+
|
274
|
248
|
function populateDescription(e) {
|
275
|
249
|
XHR = e.target;
|
276
|
|
- myDump(XHR.responseText);
|
277
|
|
- data = XHR.responseXML;
|
278
|
|
- story = $xp(data, "/stories/story")[0];
|
279
|
|
- //alert(story);
|
280
|
|
- now = new Date();
|
281
|
|
- if ($a(story, 'promote_date') != null)
|
282
|
|
- then = new Date(parseInt($a(story, 'promote_date').escapeEntities())*1000);
|
283
|
|
- else
|
284
|
|
- then = new Date(parseInt($a(story, 'submit_date').escapeEntities())*1000);
|
285
|
|
- diff = now - then;
|
286
|
|
- if (diff < 0) diff = 0;
|
287
|
|
-
|
288
|
|
- hr = Math.floor(diff/(1000*3600));
|
289
|
|
- min = Math.floor(diff/(1000*60)) - 60*hr;
|
290
|
|
-
|
291
|
|
- listitems = document.getElementsByTagName('richlistitem');
|
292
|
|
- for (i=0; i<listitems.length; i++) {
|
293
|
|
- listitems[i].getElementsByAttribute('class', 'storyDetails')[0].style.display = 'none';
|
294
|
|
- listitems[i].getElementsByAttribute('class', 'storyCEIcon')[0].src = "chrome://diggsidebar/content/image/up.jpg";
|
295
|
|
- }
|
296
|
|
-
|
297
|
|
- storyListItem = $ei('story_'+ $a(story, 'id'))
|
298
|
|
- storyDetails = storyListItem.getElementsByAttribute('class', 'storyDetails')[0];
|
299
|
|
- storyDate = storyListItem.getElementsByAttribute('class', 'storyDate')[0];
|
300
|
|
- storyStatus = storyListItem.getElementsByAttribute('class', 'storyStatus')[0];
|
301
|
|
- storyContainer = storyListItem.getElementsByAttribute('class', 'storyContainer')[0];
|
302
|
|
- storyTopic = storyListItem.getElementsByAttribute('class', 'storyTopic')[0];
|
303
|
|
- storyUserName = storyListItem.getElementsByAttribute('class', 'storyUserName')[0];
|
304
|
|
- storyDiggs = storyListItem.getElementsByAttribute('class', 'storyDiggs')[0];
|
305
|
|
- storyComments = storyListItem.getElementsByAttribute('class', 'storyComments')[0];
|
306
|
|
- storyDesc = storyListItem.getElementsByAttribute('class', 'storyDesc')[0];
|
307
|
|
- storyLink = storyListItem.getElementsByAttribute('class', 'storyLink')[0];
|
308
|
|
- storyHref = storyListItem.getElementsByAttribute('class', 'storyHref')[0];
|
309
|
|
-
|
310
|
|
- storyCEIcon = storyListItem.getElementsByAttribute('class', 'storyCEIcon')[0];
|
311
|
|
- storyRead = storyListItem.getElementsByAttribute('class', 'storyRead')[0];
|
312
|
|
-
|
|
250
|
+ //Application.console.log(XHR.responseText);
|
|
251
|
+ data = decodeJson(XHR.responseText);
|
|
252
|
+ story = data.stories[0];
|
|
253
|
+
|
|
254
|
+ now = new Date();
|
|
255
|
+ if (story.promote_date != null)
|
|
256
|
+ then = new Date(story.promote_date*1000);
|
|
257
|
+ else
|
|
258
|
+ then = new Date(story.submit_date*1000);
|
|
259
|
+ diff = Math.max(now - then, 0)
|
|
260
|
+
|
|
261
|
+ hr = Math.floor(diff/(1000*3600));
|
|
262
|
+ min = Math.floor(diff/(1000*60)) - 60*hr;
|
|
263
|
+
|
|
264
|
+ listitems = document.getElementsByTagName('richlistitem');
|
|
265
|
+ for (i=0; i<listitems.length; i++) {
|
|
266
|
+ listitems[i].getElementsByAttribute('class', 'storyDetails')[0].style.display = 'none';
|
|
267
|
+ listitems[i].getElementsByAttribute('class', 'storyCEIcon')[0].src =
|
|
268
|
+ "chrome://diggsidebar/content/image/up.jpg";
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ storyListItem = $ei('story_'+ story.id)
|
|
272
|
+ storyDetails = storyListItem.getElementsByAttribute('class', 'storyDetails')[0];
|
|
273
|
+ storyDate = storyListItem.getElementsByAttribute('class', 'storyDate')[0];
|
|
274
|
+ storyStatus = storyListItem.getElementsByAttribute('class', 'storyStatus')[0];
|
|
275
|
+ storyContainer = storyListItem.getElementsByAttribute('class', 'storyContainer')[0];
|
|
276
|
+ storyTopic = storyListItem.getElementsByAttribute('class', 'storyTopic')[0];
|
|
277
|
+ storyUserName = storyListItem.getElementsByAttribute('class', 'storyUserName')[0];
|
|
278
|
+ storyDiggs = storyListItem.getElementsByAttribute('class', 'storyDiggs')[0];
|
|
279
|
+ storyComments = storyListItem.getElementsByAttribute('class', 'storyComments')[0];
|
|
280
|
+ storyDesc = storyListItem.getElementsByAttribute('class', 'storyDesc')[0];
|
|
281
|
+ storyLink = storyListItem.getElementsByAttribute('class', 'storyLink')[0];
|
|
282
|
+ storyHref = storyListItem.getElementsByAttribute('class', 'storyHref')[0];
|
|
283
|
+
|
|
284
|
+ storyCEIcon = storyListItem.getElementsByAttribute('class', 'storyCEIcon')[0];
|
|
285
|
+ storyRead = storyListItem.getElementsByAttribute('class', 'storyRead')[0];
|
|
286
|
+
|
313
|
287
|
storyDate.innerHTML = ((hr > 0) && (min > 0)) ?
|
314
|
|
- (hr + " hr " + min + " mins ago") :
|
315
|
|
- ((hr == 0) && (min > 0)) ?
|
316
|
|
- (min + " mins ago") :
|
317
|
|
- ((hr == 0) && (min == 0)) ?
|
318
|
|
- "just now" : "";
|
319
|
|
- storyStatus.innerHTML = $a(story, 'status').escapeEntities();
|
320
|
|
- //alert($a($et('container', story), 'name').escapeEntities());
|
321
|
|
- storyContainer.innerHTML = $a($et('container', story), 'name').escapeEntities();
|
322
|
|
- storyTopic.innerHTML = $a($et('topic', story), 'name').escapeEntities();
|
323
|
|
- storyUserName.href = "http://digg.com/users/" + $a($et('user', story), 'name').escapeEntities();
|
324
|
|
- storyUserName.innerHTML = $a($et('user', story), 'name').escapeEntities();
|
325
|
|
- storyDiggs.innerHTML = $a(story, 'diggs').escapeEntities();
|
326
|
|
- storyComments.innerHTML = $a(story, 'comments').escapeEntities();
|
327
|
|
- storyDesc.innerHTML = $et('description', story).textContent.escapeEntities();
|
328
|
|
- storyLink.href = $a(story, 'link');
|
329
|
|
- storyHref.href = $a(story, 'href');
|
330
|
|
-
|
331
|
|
- storyCEIcon.src = "chrome://diggsidebar/content/image/down.jpg";
|
332
|
|
- storyRead.style.textDecoration = "line-through";
|
333
|
|
- storyRead.style.backgroundColor = "black";
|
334
|
|
- storyRead.style.color = "white";
|
335
|
|
- storyRead.title = "Read";
|
336
|
|
- storyNew.style.textDecoration = "line-through";
|
337
|
|
- storyNew.style.backgroundColor = "black";
|
338
|
|
- storyNew.style.color = "white";
|
339
|
|
- storyNew.title = "Old";
|
340
|
|
-
|
|
288
|
+ (hr + " hr " + min + " mins ago") :
|
|
289
|
+ ((hr == 0) && (min > 0)) ?
|
|
290
|
+ (min + " mins ago") :
|
|
291
|
+ ((hr == 0) && (min == 0)) ?
|
|
292
|
+ "just now" : "";
|
|
293
|
+ storyStatus.innerHTML = story.status.escapeEntities();
|
|
294
|
+ storyContainer.innerHTML = story.container.name.escapeEntities();
|
|
295
|
+ storyTopic.innerHTML = story.topic.name.escapeEntities();
|
|
296
|
+ storyUserName.href = "http://digg.com/users/" + story.user.name;
|
|
297
|
+ storyUserName.innerHTML = story.user.name.escapeEntities();
|
|
298
|
+ storyDiggs.innerHTML = story.diggs;
|
|
299
|
+ storyComments.innerHTML = story.comments;
|
|
300
|
+ storyDesc.innerHTML = story.description.escapeEntities();
|
|
301
|
+ storyLink.href = story.link;
|
|
302
|
+ storyHref.href = story.href;
|
|
303
|
+
|
|
304
|
+ storyCEIcon.src = "chrome://diggsidebar/content/image/down.jpg";
|
|
305
|
+ storyRead.style.textDecoration = "line-through";
|
|
306
|
+ storyRead.style.backgroundColor = "black";
|
|
307
|
+ storyRead.style.color = "white";
|
|
308
|
+ storyRead.title = "Read";
|
|
309
|
+ storyNew.style.textDecoration = "line-through";
|
|
310
|
+ storyNew.style.backgroundColor = "black";
|
|
311
|
+ storyNew.style.color = "white";
|
|
312
|
+ storyNew.title = "Old";
|
|
313
|
+
|
341
|
314
|
storyDetails.style.display = 'block';
|
342
|
|
-
|
343
|
|
- $ei('diggIndicator').style.display = 'none';
|
|
315
|
+
|
|
316
|
+ $ei('diggIndicator').style.display = 'none';
|
344
|
317
|
}
|
345
|
318
|
|
346
|
319
|
function getStories() {
|
347
|
|
- //alert("inside getStories");
|
348
|
|
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].
|
349
|
|
- getService(Components.interfaces.nsIPrefBranch);
|
350
|
|
- ep = prefs.getCharPref("extensions.diggsidebar.endpoint") || '';
|
351
|
|
- //alert(ep);
|
352
|
|
- $ei('diggEndPoint').value = "digg" + ep;
|
353
|
|
-
|
354
|
|
- //ep ='';
|
355
|
|
- fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') + "?count=30" +
|
|
320
|
+ var prefs = Components.classes["@mozilla.org/preferences-service;1"].
|
|
321
|
+ getService(Components.interfaces.nsIPrefBranch);
|
|
322
|
+ ep = prefs.getCharPref("extensions.diggsidebar.endpoint") || '';
|
|
323
|
+ $ei('diggEndPoint').value = "digg" + ep;
|
|
324
|
+
|
|
325
|
+ fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') +
|
|
326
|
+ "?count=30" + "&type=json" +
|
356
|
327
|
"&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
|
357
|
328
|
populateStoryList);
|
358
|
|
- //gsti = window.setTimeout(getStories, prefs.getIntPref("extensions.diggsidebar.updateinterval"));
|
|
329
|
+ //gsti = window.setTimeout(getStories, prefs.getIntPref("extensions.diggsidebar.updateinterval"));
|
359
|
330
|
}
|
360
|
331
|
|
361
|
332
|
function getDescription(storyId) {
|
362
|
|
- myDump(storyId);
|
363
|
|
- if (storyId == null) return;
|
364
|
|
- fetchData("http://services.digg.com/story/" + storyId +
|
365
|
|
- "?appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
|
|
333
|
+ if (storyId == null) return;
|
|
334
|
+ fetchData("http://services.digg.com/story/" + storyId + "?type=json" +
|
|
335
|
+ "&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
|
366
|
336
|
populateDescription);
|
367
|
337
|
}
|
368
|
338
|
|
369
|
339
|
function createMenu() {
|
370
|
|
- fetchData("http://services.digg.com/topics" +
|
371
|
|
- "?appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
|
|
340
|
+ fetchData("http://services.digg.com/topics" + "?type=json" +
|
|
341
|
+ "&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
|
372
|
342
|
populateMenu);
|
373
|
343
|
}
|
374
|
344
|
|
|
@@ -403,7 +373,7 @@ function togglePlayPause() {
|
403
|
373
|
getService(Components.interfaces.nsIPrefBranch);
|
404
|
374
|
updateInterval = prefs.getIntPref("extensions.diggsidebar.updateinterval")
|
405
|
375
|
updateIntervalDecay = prefs.getIntPref("extensions.diggsidebar.updateintervaldecay");
|
406
|
|
-
|
|
376
|
+
|
407
|
377
|
timeout = Math.round(updateInterval*(Math.pow(1.5, updateIntervalDecay)));
|
408
|
378
|
//newTimeout = Math.round(timeout*parseInt($ei("diggIndicator").getAttribute('value'))/100);
|
409
|
379
|
gsti = window.setTimeout(getStories, timeout);
|
|
@@ -415,13 +385,11 @@ function togglePlayPause() {
|
415
|
385
|
}
|
416
|
386
|
}
|
417
|
387
|
|
418
|
|
-
|
419
|
|
-function myDump(aMessage) {
|
420
|
|
- var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
|
421
|
|
- .getService(Components.interfaces.nsIConsoleService);
|
422
|
|
- consoleService.logStringMessage("Diggsidebar: " + aMessage);
|
423
|
|
-}
|
424
|
|
-
|
|
388
|
+function decodeJson(string) {
|
|
389
|
+ var json = Components.classes["@mozilla.org/dom/json;1"]
|
|
390
|
+ .createInstance(Components.interfaces.nsIJSON);
|
|
391
|
+ return json.decode(string);
|
|
392
|
+};
|
425
|
393
|
|
426
|
394
|
/*TODO
|
427
|
395
|
preferences
|
|
@@ -435,12 +403,12 @@ function myDump(aMessage) {
|
435
|
403
|
added error notification
|
436
|
404
|
added accesskeys
|
437
|
405
|
added new story notification
|
438
|
|
-
|
|
406
|
+
|
439
|
407
|
v0.2.1
|
440
|
408
|
adaptive polling interval
|
441
|
409
|
promote_date
|
442
|
410
|
pause/play
|
443
|
|
-
|
|
411
|
+
|
444
|
412
|
v0.5
|
445
|
413
|
new ui
|
446
|
|
-*/
|
|
414
|
+*/
|