Permalink
Browse files

handle ws better, handle housekeeping better

  • Loading branch information...
1 parent 43aff67 commit 959acb14dbb246c3d8dc2aad3ab6ef04cbf87a70 @coronin committed Apr 26, 2012
Showing with 47 additions and 25 deletions.
  1. +1 −1 README
  2. +43 −21 background.html
  3. +1 −1 manifest.json
  4. +2 −2 options.html
View
2 README
@@ -34,7 +34,7 @@ One more thing - we have a js client for "the Paper Link", working in all web br
Change Log:
- * v0.4.3.3 - bug fix
+ * v0.4.3.4 - bug fix
* v0.4.3.2 - web site "save it" will save to Dropbox (if connected)
* v0.4.3.1 - automatic update WebSocket server address
* v0.4.3 - use WebSocket to accept broadcasting
View
@@ -9,6 +9,7 @@
var DEBUG = false,
i, aKey, aVal, ws,
+ ws_addr = localStorage.getItem('ws_address') || 'husband.jit.su',
scholar_count = 0,
scholar_run = 0,
scholar_queue = [],
@@ -21,7 +22,13 @@
apikey, req_key, rev_proxy, base, pubmeder_apikey, pubmeder_email,
pubmeder_ok = 0,
broadcast_loaded = 0,
- ajax_pii_link = 1;
+ ajax_pii_link = 1,
+ currentTime = new Date(),
+ year = currentTime.getFullYear(),
+ month = currentTime.getMonth() + 1,
+ day = currentTime.getDate(),
+ date_str = 'day_' + year + '_' + month + '_' + day,
+ last_date = localStorage.getItem('last_date_str') || '';
function get_ws_address() {
@@ -31,6 +38,15 @@
function (ws_d) {
DEBUG && console.log('>> get_ws_address: ' + ws_d);
localStorage.setItem('ws_address', ws_d);
+ if (ws_d !== ws_addr) {
+ ws_addr = ws_d;
+ if (ws) {
+ ws.close();
+ broadcast_loaded = 0;
+ }
+ DEBUG && console.log('>> connect to the new ws server');
+ load_broadcast();
+ }
}
).error(function () {
DEBUG && console.log('>> get_ws_address, step 2 error');
@@ -426,25 +442,32 @@
base = 'http://0.pl4.me';
});
-for (i = 0; i < localStorage.length; i += 1) {
- aKey = localStorage.key(i);
- if (aKey && aKey.substr(0,6) === 'tabId:') {
- aVal = localStorage.getItem(aKey);
- if ( alldigi.test(aVal) ) {
- if (aVal !== '999999999' && init_found.indexOf(aVal) === -1) {
- old_id += ' ' + aVal;
+if (last_date !== date_str) {
+ localStorage.setItem('last_date_str', date_str);
+ DEBUG && console.log('>> a new day! start with some housekeeping tasks');
+ for (i = 0; i < localStorage.length; i += 1) {
+ aKey = localStorage.key(i);
+ if (aKey && aKey.substr(0,6) === 'tabId:') {
+ aVal = localStorage.getItem(aKey);
+ if ( alldigi.test(aVal) ) {
+ if (aVal !== '999999999' && init_found.indexOf(aVal) === -1) {
+ old_id += ' ' + aVal;
+ }
+ localStorage.removeItem(aKey);
}
+ } else if (aKey && aKey.substr(0,6) === 'email_') {
+ aVal = aKey.split('_');
+ email_abstract(aVal[1], aVal[2]);
+ } else if (aKey && aKey.substr(0,7) === 'pubmed_') {
+ aVal = aKey.split('_');
+ localStorage.removeItem(aKey);
+ saveIt_pubmeder(aVal[1]);
+ } else if (aKey && aKey.substr(0,8) === 'scholar_') {
localStorage.removeItem(aKey);
}
- } else if (aKey && aKey.substr(0,6) === 'email_') {
- aVal = aKey.split('_');
- email_abstract(aVal[1], aVal[2]);
- } else if (aKey && aKey.substr(0,7) === 'pubmed_') {
- aVal = aKey.split('_');
- localStorage.removeItem(aKey);
- saveIt_pubmeder(aVal[1]);
}
}
+
if (old_id) {
localStorage.setItem('id_found', init_found + ' ' + old_id);
}
@@ -560,9 +583,7 @@
if (!window.WebSocket) {
return;
}
- ws = new WebSocket('ws://' +
- (localStorage.getItem('ws_address') || 'husband.jit.su')
- );
+ ws = new WebSocket('ws://' + ws_addr);
ws.onopen = function () {
DEBUG && console.log('>> ws is established');
@@ -583,6 +604,7 @@
setTimeout(_self.start, 3000);
} else {
DEBUG && console.log('>> ws is closed');
+ return;
}
};
//setInterval(function() {
@@ -593,6 +615,7 @@
ws.onerror = function (err) {
DEBUG && console.log('>> ws error: ' + err);
+ return;
};
ws.onmessage = function (message) {
@@ -624,17 +647,16 @@
}
} catch (err) {
DEBUG && console.log('>> json parse error: ' + message.data);
- return;
}
};
}
_self.start();
}
$(document).ready(function () {
- if (localStorage.getItem('ws_items') === 'yes' && !broadcast_loaded) {
- get_ws_address();
+ if (!broadcast_loaded && localStorage.getItem('ws_items') !== 'no') {
load_broadcast();
+ get_ws_address();
}
});
//-->
View
@@ -1,6 +1,6 @@
{
"name": "__MSG_appName__",
- "version": "0.4.3.3",
+ "version": "0.4.3.4",
"minimum_chrome_version": "16",
"description": "__MSG_appDesc__",
"default_locale": "en",
View
@@ -68,7 +68,7 @@ <h3 style="color:#9f0000">"the Paper Link" API &ndash; required</h3>
</p>
<p><input type="checkbox" id="contextMenu_shown" /> You could check here to <b>disable</b> the context menu triggered by right mouse click.
</p>
- <p><input type="checkbox" id="ws_items" /> Testing: <b>enable</b> the <span style="color:red">bleeding</span> feature - display "cited by" count on <a href="http://www.thepaperlink.com" rel="external">http://www.thepaperlink.com</a>,
+ <p><input type="checkbox" id="ws_items" /> <b>Enable</b> the <span style="color:red">bleeding</span> feature - display "cited by" count on <a href="http://www.thepaperlink.com" rel="external">http://www.thepaperlink.com</a>,
<br/>your status on the website should be <u id="ws_items_status"></u>.
</p>
<p><input type="checkbox" id="ajax_pii_link" /> Testing: <b>enable</b> to solve missing links locally
@@ -156,7 +156,7 @@ <h3 style="color:#9f0000">"the Paper Link" API &ndash; required</h3>
if (localStorage.getItem('contextMenu_shown') === 'no') {
$('#contextMenu_shown').prop('checked', true);
}
- if (localStorage.getItem('ws_items') === 'yes') {
+ if (localStorage.getItem('ws_items') !== 'no') {
$('#ws_items').prop('checked', true);
}
if (localStorage.getItem('ajax_pii_link') !== 'no') {

0 comments on commit 959acb1

Please sign in to comment.