Use the Page Visibility API for Scroll BG, close #266
This commit is contained in:
parent
d95764e87a
commit
0383a3629a
@ -852,7 +852,6 @@
|
|||||||
},
|
},
|
||||||
keydown: function(e) {
|
keydown: function(e) {
|
||||||
var o, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2, _ref3;
|
var o, range, selEnd, selStart, ta, thread, valEnd, valMid, valStart, value, _ref, _ref2, _ref3;
|
||||||
updater.focus = true;
|
|
||||||
if (((_ref = e.target.nodeName) === 'TEXTAREA' || _ref === 'INPUT') && !e.altKey && !e.ctrlKey && !(e.keyCode === 27)) {
|
if (((_ref = e.target.nodeName) === 'TEXTAREA' || _ref === 'INPUT') && !e.altKey && !e.ctrlKey && !(e.keyCode === 27)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1890,18 +1889,6 @@
|
|||||||
updater = {
|
updater = {
|
||||||
init: function() {
|
init: function() {
|
||||||
var checkbox, checked, dialog, html, input, name, title, _i, _len, _ref;
|
var checkbox, checked, dialog, html, input, name, title, _i, _len, _ref;
|
||||||
if (conf['Scrolling']) {
|
|
||||||
if (conf['Scroll BG']) {
|
|
||||||
updater.focus = true;
|
|
||||||
} else {
|
|
||||||
$.bind(window, 'focus', (function() {
|
|
||||||
return updater.focus = true;
|
|
||||||
}));
|
|
||||||
$.bind(window, 'blur', (function() {
|
|
||||||
return updater.focus = false;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
html = "<div class=move><span id=count></span> <span id=timer>-" + conf['Interval'] + "</span></div>";
|
html = "<div class=move><span id=count></span> <span id=timer>-" + conf['Interval'] + "</span></div>";
|
||||||
checkbox = config.updater.checkbox;
|
checkbox = config.updater.checkbox;
|
||||||
for (name in checkbox) {
|
for (name in checkbox) {
|
||||||
@ -1923,7 +1910,10 @@
|
|||||||
$.bind(input, 'click', function() {
|
$.bind(input, 'click', function() {
|
||||||
return conf[this.name] = this.checked;
|
return conf[this.name] = this.checked;
|
||||||
});
|
});
|
||||||
if (input.name === 'Verbose') {
|
if (input.name === 'Scroll BG') {
|
||||||
|
$.bind(input, 'click', updater.cb.scrollBG);
|
||||||
|
updater.cb.scrollBG.call(input);
|
||||||
|
} else if (input.name === 'Verbose') {
|
||||||
$.bind(input, 'click', updater.cb.verbose);
|
$.bind(input, 'click', updater.cb.verbose);
|
||||||
updater.cb.verbose.call(input);
|
updater.cb.verbose.call(input);
|
||||||
} else if (input.name === 'Auto Update This') {
|
} else if (input.name === 'Auto Update This') {
|
||||||
@ -1961,6 +1951,21 @@
|
|||||||
return clearTimeout(updater.timeoutID);
|
return clearTimeout(updater.timeoutID);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
scrollBG: function() {
|
||||||
|
return updater.scrollBG = this.checked ? function() {
|
||||||
|
return true;
|
||||||
|
} : d.visibilityState ? function() {
|
||||||
|
return !d.hidden;
|
||||||
|
} : d.oVisibilityState ? function() {
|
||||||
|
return !d.oHidden;
|
||||||
|
} : d.mozVisibilityState ? function() {
|
||||||
|
return !d.mozHidden;
|
||||||
|
} : d.webkitVisibilityState ? function() {
|
||||||
|
return !d.webkitHidden;
|
||||||
|
} : function() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
},
|
||||||
update: function() {
|
update: function() {
|
||||||
var arr, body, id, input, replies, reply, scroll, _i, _len, _ref, _ref2;
|
var arr, body, id, input, replies, reply, scroll, _i, _len, _ref, _ref2;
|
||||||
if (this.status === 404) {
|
if (this.status === 404) {
|
||||||
@ -1989,12 +1994,12 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
replies = $$('.reply', body);
|
replies = $$('.reply', body);
|
||||||
id = Number(((_ref2 = $('td[id]', updater.br.previousElementSibling)) != null ? _ref2.id : void 0) || 0);
|
id = Number(((_ref2 = $('td[id]', updater.br.previousSibling)) != null ? _ref2.id : void 0) || 0);
|
||||||
arr = [];
|
arr = [];
|
||||||
while ((reply = replies.pop()) && (reply.id > id)) {
|
while ((reply = replies.pop()) && (reply.id > id)) {
|
||||||
arr.push(reply.parentNode.parentNode.parentNode);
|
arr.push(reply.parentNode.parentNode.parentNode);
|
||||||
}
|
}
|
||||||
scroll = conf['Scrolling'] && updater.focus && arr.length && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20);
|
scroll = conf['Scrolling'] && updater.scrollBG() && arr.length && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20);
|
||||||
if (conf['Verbose']) {
|
if (conf['Verbose']) {
|
||||||
updater.count.textContent = '+' + arr.length;
|
updater.count.textContent = '+' + arr.length;
|
||||||
if (arr.length === 0) {
|
if (arr.length === 0) {
|
||||||
@ -2007,7 +2012,7 @@
|
|||||||
$.before(updater.br, reply);
|
$.before(updater.br, reply);
|
||||||
}
|
}
|
||||||
if (scroll) {
|
if (scroll) {
|
||||||
return scrollTo(0, d.body.scrollHeight);
|
return updater.br.previousSibling.scrollIntoView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2661,7 +2666,6 @@
|
|||||||
},
|
},
|
||||||
scroll: function(e) {
|
scroll: function(e) {
|
||||||
var bottom, height, i, reply, _len, _ref;
|
var bottom, height, i, reply, _len, _ref;
|
||||||
updater.focus = true;
|
|
||||||
height = d.body.clientHeight;
|
height = d.body.clientHeight;
|
||||||
_ref = unread.replies;
|
_ref = unread.replies;
|
||||||
for (i = 0, _len = _ref.length; i < _len; i++) {
|
for (i = 0, _len = _ref.length; i < _len; i++) {
|
||||||
|
|||||||
@ -608,7 +608,6 @@ keybinds =
|
|||||||
$.bind d, 'keydown', keybinds.keydown
|
$.bind d, 'keydown', keybinds.keydown
|
||||||
|
|
||||||
keydown: (e) ->
|
keydown: (e) ->
|
||||||
updater.focus = true
|
|
||||||
return if e.target.nodeName in ['TEXTAREA', 'INPUT'] and not e.altKey and not e.ctrlKey and not (e.keyCode is 27)
|
return if e.target.nodeName in ['TEXTAREA', 'INPUT'] and not e.altKey and not e.ctrlKey and not (e.keyCode is 27)
|
||||||
return unless key = keybinds.keyCode e
|
return unless key = keybinds.keyCode e
|
||||||
|
|
||||||
@ -1422,12 +1421,6 @@ threadHiding =
|
|||||||
|
|
||||||
updater =
|
updater =
|
||||||
init: ->
|
init: ->
|
||||||
if conf['Scrolling']
|
|
||||||
if conf['Scroll BG']
|
|
||||||
updater.focus = true
|
|
||||||
else
|
|
||||||
$.bind window, 'focus', (-> updater.focus = true)
|
|
||||||
$.bind window, 'blur', (-> updater.focus = false)
|
|
||||||
html = "<div class=move><span id=count></span> <span id=timer>-#{conf['Interval']}</span></div>"
|
html = "<div class=move><span id=count></span> <span id=timer>-#{conf['Interval']}</span></div>"
|
||||||
{checkbox} = config.updater
|
{checkbox} = config.updater
|
||||||
for name of checkbox
|
for name of checkbox
|
||||||
@ -1451,7 +1444,10 @@ updater =
|
|||||||
if input.type is 'checkbox'
|
if input.type is 'checkbox'
|
||||||
$.bind input, 'click', $.cb.checked
|
$.bind input, 'click', $.cb.checked
|
||||||
$.bind input, 'click', -> conf[@name] = @checked
|
$.bind input, 'click', -> conf[@name] = @checked
|
||||||
if input.name is 'Verbose'
|
if input.name is 'Scroll BG'
|
||||||
|
$.bind input, 'click', updater.cb.scrollBG
|
||||||
|
updater.cb.scrollBG.call input
|
||||||
|
else if input.name is 'Verbose'
|
||||||
$.bind input, 'click', updater.cb.verbose
|
$.bind input, 'click', updater.cb.verbose
|
||||||
updater.cb.verbose.call input
|
updater.cb.verbose.call input
|
||||||
else if input.name is 'Auto Update This'
|
else if input.name is 'Auto Update This'
|
||||||
@ -1480,6 +1476,21 @@ updater =
|
|||||||
updater.timeoutID = setTimeout updater.timeout, 1000
|
updater.timeoutID = setTimeout updater.timeout, 1000
|
||||||
else
|
else
|
||||||
clearTimeout updater.timeoutID
|
clearTimeout updater.timeoutID
|
||||||
|
scrollBG: ->
|
||||||
|
updater.scrollBG =
|
||||||
|
if @checked
|
||||||
|
-> true
|
||||||
|
else
|
||||||
|
if d.visibilityState
|
||||||
|
-> !d.hidden
|
||||||
|
else if d.oVisibilityState
|
||||||
|
-> !d.oHidden
|
||||||
|
else if d.mozVisibilityState
|
||||||
|
-> !d.mozHidden
|
||||||
|
else if d.webkitVisibilityState
|
||||||
|
-> !d.webkitHidden
|
||||||
|
else
|
||||||
|
-> true
|
||||||
update: ->
|
update: ->
|
||||||
if @status is 404
|
if @status is 404
|
||||||
updater.timer.textContent = ''
|
updater.timer.textContent = ''
|
||||||
@ -1505,12 +1516,12 @@ updater =
|
|||||||
return
|
return
|
||||||
|
|
||||||
replies = $$ '.reply', body
|
replies = $$ '.reply', body
|
||||||
id = Number $('td[id]', updater.br.previousElementSibling)?.id or 0
|
id = Number $('td[id]', updater.br.previousSibling)?.id or 0
|
||||||
arr = []
|
arr = []
|
||||||
while (reply = replies.pop()) and (reply.id > id)
|
while (reply = replies.pop()) and (reply.id > id)
|
||||||
arr.push reply.parentNode.parentNode.parentNode #table
|
arr.push reply.parentNode.parentNode.parentNode #table
|
||||||
|
|
||||||
scroll = conf['Scrolling'] && updater.focus && arr.length && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20)
|
scroll = conf['Scrolling'] && updater.scrollBG() && arr.length && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20)
|
||||||
if conf['Verbose']
|
if conf['Verbose']
|
||||||
updater.count.textContent = '+' + arr.length
|
updater.count.textContent = '+' + arr.length
|
||||||
if arr.length is 0
|
if arr.length is 0
|
||||||
@ -1522,7 +1533,7 @@ updater =
|
|||||||
while reply = arr.pop()
|
while reply = arr.pop()
|
||||||
$.before updater.br, reply
|
$.before updater.br, reply
|
||||||
if scroll
|
if scroll
|
||||||
scrollTo 0, d.body.scrollHeight
|
updater.br.previousSibling.scrollIntoView()
|
||||||
|
|
||||||
timeout: ->
|
timeout: ->
|
||||||
updater.timeoutID = setTimeout updater.timeout, 1000
|
updater.timeoutID = setTimeout updater.timeout, 1000
|
||||||
@ -1966,7 +1977,6 @@ unread =
|
|||||||
Favicon.update()
|
Favicon.update()
|
||||||
|
|
||||||
scroll: (e) ->
|
scroll: (e) ->
|
||||||
updater.focus = true
|
|
||||||
height = d.body.clientHeight
|
height = d.body.clientHeight
|
||||||
for reply, i in unread.replies
|
for reply, i in unread.replies
|
||||||
{bottom} = reply.getBoundingClientRect()
|
{bottom} = reply.getBoundingClientRect()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user