Pause the thread updater when offline.

This commit is contained in:
Nicolas Stepien 2012-09-14 03:09:36 +02:00
parent 659bf231b4
commit b9f0aa47fc
3 changed files with 83 additions and 41 deletions

View File

@ -2407,27 +2407,47 @@
_ref1 = $$('input', dialog);
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
input = _ref1[_i];
switch (input.type) {
case 'checkbox':
$.on(input, 'click', this.cb.checkbox.bind(this));
input.dispatchEvent(new Event('click'));
$.on(input, 'click', $.cb.checked);
if (input.type === 'checkbox') {
$.on(input, 'click', this.cb.checkbox.bind(this));
input.dispatchEvent(new Event('click'));
}
switch (input.name) {
case 'Scroll BG':
$.on(input, 'click', this.cb.scrollBG.bind(this));
this.cb.scrollBG.call(this);
break;
case 'number':
case 'Auto Update This':
$.on(input, 'click', this.cb.autoUpdate.bind(this));
break;
case 'Interval':
$.on(input, 'change', this.cb.interval.bind(this));
input.dispatchEvent(new Event('change'));
break;
case 'button':
case 'Update Now':
$.on(input, 'click', this.update.bind(this));
}
}
$.on(window, 'online offline', this.cb.online.bind(this));
$.on(d, 'QRPostSuccessful', this.cb.post.bind(this));
$.on(d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', this.cb.visibility.bind(this));
this.set('timer', this.getInterval());
this.cb.online.call(this);
$.add(d.body, dialog);
}
_Class.prototype.cb = {
online: function() {
if (this.online = navigator.onLine) {
this.unsuccessfulFetchCount = 0;
this.set('timer', this.getInterval());
this.set('status', null);
this.status.className = null;
} else {
this.status.className = 'warning';
this.set('status', 'Offline');
this.set('timer', null);
}
return this.cb.autoUpdate.call(this);
},
post: function(e) {
if (!(this['Auto Update This'] && +e.detail.threadID === this.thread.ID)) {
return;
@ -2453,19 +2473,20 @@
input = e.target;
checked = input.checked, name = input.name;
this[name] = checked;
switch (name) {
case 'Scroll BG':
return this.scrollBG = checked ? function() {
return true;
} : function() {
return !(d.hidden || d.oHidden || d.mozHidden || d.webkitHidden);
};
case 'Auto Update This':
if (checked) {
return this.timeoutID = setTimeout(this.timeout.bind(this), 1000);
} else {
return clearTimeout(this.timeoutID);
}
return $.cb.checked.call(input);
},
scrollBG: function() {
return this.scrollBG = this['Scroll BG'] ? function() {
return true;
} : function() {
return !(d.hidden || d.oHidden || d.mozHidden || d.webkitHidden);
};
},
autoUpdate: function() {
if (this['Auto Update This'] && this.online) {
return this.timeoutID = setTimeout(this.timeout.bind(this), 1000);
} else {
return clearTimeout(this.timeoutID);
}
},
interval: function(e) {
@ -2548,6 +2569,9 @@
_Class.prototype.update = function() {
var url;
if (!this.online) {
return;
}
this.seconds = 0;
this.set('timer', '...');
if (this.req) {

View File

@ -1,5 +1,6 @@
alpha
- Mayhem
The Thread Updater will pause when offline, and resume when online.
Fix Chrome's install warning that 4chan X would execute on all domains.
Fix Quote Backlinks not affecting inlined quotes.
Fix Quote Highlighting not affecting inlined quotes.

View File

@ -2148,24 +2148,40 @@ ThreadUpdater =
@lastPost = +@threadRoot.lastElementChild.id[2..]
for input in $$ 'input', dialog
switch input.type
when 'checkbox'
$.on input, 'click', @cb.checkbox.bind @
input.dispatchEvent new Event 'click'
$.on input, 'click', $.cb.checked
when 'number'
if input.type is 'checkbox'
$.on input, 'click', @cb.checkbox.bind @
input.dispatchEvent new Event 'click'
switch input.name
when 'Scroll BG'
$.on input, 'click', @cb.scrollBG.bind @
@cb.scrollBG.call @
when 'Auto Update This'
$.on input, 'click', @cb.autoUpdate.bind @
when 'Interval'
$.on input, 'change', @cb.interval.bind @
input.dispatchEvent new Event 'change'
when 'button'
when 'Update Now'
$.on input, 'click', @update.bind @
$.on window, 'online offline', @cb.online.bind @
$.on d, 'QRPostSuccessful', @cb.post.bind @
$.on d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', @cb.visibility.bind @
@set 'timer', @getInterval()
@cb.online.call @
$.add d.body, dialog
cb:
online: ->
if @online = navigator.onLine
@unsuccessfulFetchCount = 0
@set 'timer', @getInterval()
@set 'status', null
@status.className = null
else
@status.className = 'warning'
@set 'status', 'Offline'
@set 'timer', null
@cb.autoUpdate.call @
post: (e) ->
return unless @['Auto Update This'] and +e.detail.threadID is @thread.ID
@unsuccessfulFetchCount = 0
@ -2181,18 +2197,18 @@ ThreadUpdater =
input = e.target
{checked, name} = input
@[name] = checked
switch name
when 'Scroll BG'
@scrollBG =
if checked
-> true
else
-> !(d.hidden or d.oHidden or d.mozHidden or d.webkitHidden)
when 'Auto Update This'
if checked
@timeoutID = setTimeout @timeout.bind(@), 1000
else
clearTimeout @timeoutID
$.cb.checked.call input
scrollBG: ->
@scrollBG =
if @['Scroll BG']
-> true
else
-> !(d.hidden or d.oHidden or d.mozHidden or d.webkitHidden)
autoUpdate: ->
if @['Auto Update This'] and @online
@timeoutID = setTimeout @timeout.bind(@), 1000
else
clearTimeout @timeoutID
interval: (e) ->
input = e.target
val = Math.max 5, parseInt input.value, 10
@ -2263,6 +2279,7 @@ ThreadUpdater =
@set 'timer', n
update: ->
return unless @online
@seconds = 0
@set 'timer', '...'
if @req