##// END OF EJS Templates
Updated urls list to be a plain list instead of 'patterns' method which is...
Updated urls list to be a plain list instead of 'patterns' method which is deprecated and will be removed in 1.10

File last commit:

r1463:437271ff default
r1486:c55955ce default
Show More
updates.js
53 lines | 1.3 KiB | application/javascript | JavascriptLexer
neko259
Use shared workers for favorites update script
r1463 var UPDATE_INTERVAL = 10000;
var ports = [];
var includePostBody = false;
function updateFavPosts() {
var url = '/api/new_posts/';
if (includePostBody) {
url += '?include_posts';
}
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status == 200 || xhr.status == 304) {
var data = xhr.responseText;
for (var i = 0; i < ports.length; i++) {
port = ports[i];
try {
port.postMessage(data);
} catch (error) {
// Assume the port was closed with the tab
var index = ports.indexOf(port);
ports.splice(index, 1);
}
}
}
}
}
xhr.open('GET', url);
xhr.send(null);
}
onconnect = function(e) {
var port = e.ports[0];
port.start();
port.onmessage = function(e) {
// FIXME For now we include body even if a panel was opened once
if (e.data.includePostBody) {
includePostBody = true;
}
updateFavPosts();
}
ports.push(port);
}
setInterval(function() {
updateFavPosts();
}, UPDATE_INTERVAL);