diff --git a/nodelay.js b/nodelay.js index bb8b186..b0066a4 100644 --- a/nodelay.js +++ b/nodelay.js @@ -30,12 +30,26 @@ window.onload = function() { } // Start polling for JS when WebSocket and Flash aren't available +function receivePoll(json) { + processEdit(json); +} + +var polling = false; function startPolling() { + polling = true; var pollurl = "http://"+document.location.host+'/poll' + (Math.random() * 10000); //console.log('startPolling', pollurl); var self = this; + setTimeout(function() { + // check timeout, and start polling again + if (polling) { + self.startPolling(); + } + },60000) + utils.loadJSLib(pollurl, function() { setTimeout(function() { + polling = false; //console.log('loaded', pollurl); self.startPolling(); },1) @@ -87,11 +101,12 @@ function processEdit(data) { // Update user count usercountel = document.getElementById('updates'); - var usercounttext = commaSeparated(edit.usercount) + ' user' + (edit.usercount == 1 ? '' : 's') + ' from ' + commaSeparated(edit.uniqueips) + ' unique address' + (edit.uniqueips == 1 ? '' : 'es'); + var usercounttext = commaSeparated(edit.usercount) + ' user' + (edit.usercount == 1 ? '' : 's') + var uniqueiptext = ' from ' + commaSeparated(edit.uniqueips) + ' unique address' + (edit.uniqueips == 1 ? '' : 'es'); var editcounttext = commaSeparated(edit.editcount) + ' edit' + (edit.editcount == 1 ? '' : 's'); - var userstring = 'Nodelay has ' + usercounttext + ' and has served ' + editcounttext + '!'; + var userstring = 'Nodelay has served ' + editcounttext + ' to ' + usercounttext + uniqueiptext + '!'; usercountel.innerHTML = userstring; - top.document.title = userstring; + top.document.title = usercounttext + ' online now'; var queryurl = document.location.search; // Update languages table diff --git a/server.js b/server.js index 8990071..43c8de5 100644 --- a/server.js +++ b/server.js @@ -220,7 +220,7 @@ var lookInGoogle = function(returnobj, callback) { var clientip = uniqueips[Math.floor(Math.random() * uniqueips.length)] //console.log('found clientip', clientip, uniqueips); var url = "/ajax/services/search/web?v=1.0&key=ABQIAAAANJy59z-JG5ojQlRVP3myHBQazc0JSD0GCdkBcD0H4asbApndtBRNVqQ4MvCnn6oQF6lHyWk4Q9S5AA&userip=" + clientip + "&q='" + querystring.escape(title) + "'"; - console.log('google request', url); + //console.log('google request', url); var request = googleclient.request('GET', url, {'host': 'ajax.googleapis.com','referer': 'http://code.google.com/apis'}) request.end() @@ -236,7 +236,7 @@ var lookInGoogle = function(returnobj, callback) { // process when the response ends response.on('end', function () { - console.log('parsing: ' + url + ' for chunk ' + responsedata) + //console.log('parsing: ' + url + ' for chunk ' + responsedata) try { var data = JSON.parse(responsedata) if (data.responseData && data.responseData.results) { @@ -320,7 +320,7 @@ var loadMetadata = function(returnobj) { while (waitingclients.length) { var client = waitingclients.shift() // TODO: don't use a direct callback - client("processEdit('" + out.replace(/'/g,"\\'").replace(/"/g,'\\"') + "')") + client("receivePoll('" + out.replace(/'/g,"\\'").replace(/"/g,'\\"') + "')") } waitingclients = []; }