|
|
|
@ -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);
|
|
|
|
|