Refresh stale board index on tab/window focus
This commit is contained in:
parent
4f820ad8de
commit
c5d686ceb0
2
LICENSE
2
LICENSE
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 4chan X - Version 1.7.33 - 2014-05-11
|
||||
* 4chan X - Version 1.7.33 - 2014-05-16
|
||||
*
|
||||
* Licensed under the MIT license.
|
||||
* https://github.com/ccd0/4chan-x/blob/master/LICENSE
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
// ==/UserScript==
|
||||
|
||||
/*
|
||||
* 4chan X - Version 1.7.33 - 2014-05-11
|
||||
* 4chan X - Version 1.7.33 - 2014-05-16
|
||||
*
|
||||
* Licensed under the MIT license.
|
||||
* https://github.com/ccd0/4chan-x/blob/master/LICENSE
|
||||
@ -2651,6 +2651,7 @@
|
||||
className: 'navLinks',
|
||||
innerHTML: "<span id=\"index-menu\"><input type=\"search\" id=\"index-search\" class=\"field\" placeholder=\"Search\"><a id=\"index-search-clear\" class=\"fa fa-times-circle\" href=\"javascript:;\"></a> <time id=\"index-last-refresh\" title=\"Last index refresh\">...</time><span id=\"hidden-label\" hidden> — <span id=\"hidden-count\"></span> <span id=\"hidden-toggle\">[<a href=\"javascript:;\">Show</a>]</span></span><span style='flex: 1'></span><select id=\"index-mode\" name=\"Index Mode\"><option disabled>Index Mode</option><option value=\"paged\">Paged</option><option value=\"infinite\">Infinite Scrolling</option><option value=\"all pages\">All threads</option><option value=\"catalog\">Catalog</option></select><select id=\"index-sort\" name=\"Index Sort\"><option disabled>Index Sort</option><option value=\"bump\">Bump order</option><option value=\"lastreply\">Last reply</option><option value=\"birth\">Creation date</option><option value=\"replycount\">Reply count</option><option value=\"filecount\">File count</option></select><select id=\"index-size\" name=\"Index Size\"><option disabled>Image Size</option><option value=\"small\">Small</option><option value=\"large\">Large</option></select></span><span class=brackets-wrap id=returnlink><a href=.././>Return</a></span> <span class=brackets-wrap id=bottomlink><a href=\"#bottom\">Bottom</a></span> "
|
||||
});
|
||||
this.timeEl = $('time#index-last-refresh', this.navLinks);
|
||||
this.searchInput = $('#index-search', this.navLinks);
|
||||
this.searchTest(true);
|
||||
this.hideLabel = $('#hidden-label', this.navLinks);
|
||||
@ -2670,7 +2671,8 @@
|
||||
$.on(this.selectSort, 'change', this.cb.sort);
|
||||
$.on(this.selectSize, 'change', this.cb.size);
|
||||
this.currentPage = this.getCurrentPage();
|
||||
$.on(d, 'scroll', Index.scroll);
|
||||
$.on(d, 'scroll', this.scroll);
|
||||
$.on(window, 'focus', this.updateIfNeeded);
|
||||
$.on(this.pagelist, 'click', this.cb.pageNav);
|
||||
$.on($('#returnlink a', this.navLinks), 'click', function(e) {
|
||||
if (g.VIEW === 'index') {
|
||||
@ -3181,6 +3183,14 @@
|
||||
Index.hideLabel.hidden = false;
|
||||
return $('#hidden-count', Index.hideLabel).textContent = hiddenCount === 1 ? '1 hidden thread' : "" + hiddenCount + " hidden threads";
|
||||
},
|
||||
updateIfNeeded: function() {
|
||||
var needed, timeEl;
|
||||
timeEl = Index.timeEl;
|
||||
needed = g.VIEW === 'index' && !Index.req && timeEl.dataset.utc && timeEl.dataset.utc < Date.now() - (10 * $.MINUTE);
|
||||
if (needed) {
|
||||
return Index.update();
|
||||
}
|
||||
},
|
||||
update: function(pageNum) {
|
||||
var board, now, onload, sortedThreads, _ref, _ref1;
|
||||
if (!navigator.onLine) {
|
||||
@ -3278,7 +3288,7 @@
|
||||
}
|
||||
return;
|
||||
}
|
||||
timeEl = $('time#index-last-refresh', Index.navLinks);
|
||||
timeEl = Index.timeEl;
|
||||
timeEl.dataset.utc = Date.parse(req.getResponseHeader('Last-Modified'));
|
||||
RelativeDates.update(timeEl);
|
||||
return Index.scrollToIndex();
|
||||
@ -12956,7 +12966,7 @@
|
||||
}
|
||||
if (e) {
|
||||
if (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0)) {
|
||||
if ((e != null ? e.button : void 0) !== 2) {
|
||||
if (e.button !== 2) {
|
||||
Navigate.setMode(this);
|
||||
}
|
||||
return;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript
|
||||
/*
|
||||
* 4chan X - Version 1.7.33 - 2014-05-11
|
||||
* 4chan X - Version 1.7.33 - 2014-05-16
|
||||
*
|
||||
* Licensed under the MIT license.
|
||||
* https://github.com/ccd0/4chan-x/blob/master/LICENSE
|
||||
@ -2710,6 +2710,7 @@
|
||||
className: 'navLinks',
|
||||
innerHTML: "<span id=\"index-menu\"><input type=\"search\" id=\"index-search\" class=\"field\" placeholder=\"Search\"><a id=\"index-search-clear\" class=\"fa fa-times-circle\" href=\"javascript:;\"></a> <time id=\"index-last-refresh\" title=\"Last index refresh\">...</time><span id=\"hidden-label\" hidden> — <span id=\"hidden-count\"></span> <span id=\"hidden-toggle\">[<a href=\"javascript:;\">Show</a>]</span></span><span style='flex: 1'></span><select id=\"index-mode\" name=\"Index Mode\"><option disabled>Index Mode</option><option value=\"paged\">Paged</option><option value=\"infinite\">Infinite Scrolling</option><option value=\"all pages\">All threads</option><option value=\"catalog\">Catalog</option></select><select id=\"index-sort\" name=\"Index Sort\"><option disabled>Index Sort</option><option value=\"bump\">Bump order</option><option value=\"lastreply\">Last reply</option><option value=\"birth\">Creation date</option><option value=\"replycount\">Reply count</option><option value=\"filecount\">File count</option></select><select id=\"index-size\" name=\"Index Size\"><option disabled>Image Size</option><option value=\"small\">Small</option><option value=\"large\">Large</option></select></span><span class=brackets-wrap id=returnlink><a href=.././>Return</a></span> <span class=brackets-wrap id=bottomlink><a href=\"#bottom\">Bottom</a></span> "
|
||||
});
|
||||
this.timeEl = $('time#index-last-refresh', this.navLinks);
|
||||
this.searchInput = $('#index-search', this.navLinks);
|
||||
this.searchTest(true);
|
||||
this.hideLabel = $('#hidden-label', this.navLinks);
|
||||
@ -2729,7 +2730,8 @@
|
||||
$.on(this.selectSort, 'change', this.cb.sort);
|
||||
$.on(this.selectSize, 'change', this.cb.size);
|
||||
this.currentPage = this.getCurrentPage();
|
||||
$.on(d, 'scroll', Index.scroll);
|
||||
$.on(d, 'scroll', this.scroll);
|
||||
$.on(window, 'focus', this.updateIfNeeded);
|
||||
$.on(this.pagelist, 'click', this.cb.pageNav);
|
||||
$.on($('#returnlink a', this.navLinks), 'click', function(e) {
|
||||
if (g.VIEW === 'index') {
|
||||
@ -3240,6 +3242,14 @@
|
||||
Index.hideLabel.hidden = false;
|
||||
return $('#hidden-count', Index.hideLabel).textContent = hiddenCount === 1 ? '1 hidden thread' : "" + hiddenCount + " hidden threads";
|
||||
},
|
||||
updateIfNeeded: function() {
|
||||
var needed, timeEl;
|
||||
timeEl = Index.timeEl;
|
||||
needed = g.VIEW === 'index' && !Index.req && timeEl.dataset.utc && timeEl.dataset.utc < Date.now() - (10 * $.MINUTE);
|
||||
if (needed) {
|
||||
return Index.update();
|
||||
}
|
||||
},
|
||||
update: function(pageNum) {
|
||||
var board, now, onload, sortedThreads, _ref, _ref1;
|
||||
if (!navigator.onLine) {
|
||||
@ -3337,7 +3347,7 @@
|
||||
}
|
||||
return;
|
||||
}
|
||||
timeEl = $('time#index-last-refresh', Index.navLinks);
|
||||
timeEl = Index.timeEl;
|
||||
timeEl.dataset.utc = Date.parse(req.getResponseHeader('Last-Modified'));
|
||||
RelativeDates.update(timeEl);
|
||||
return Index.scrollToIndex();
|
||||
@ -12976,7 +12986,7 @@
|
||||
}
|
||||
if (e) {
|
||||
if (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0)) {
|
||||
if ((e != null ? e.button : void 0) !== 2) {
|
||||
if (e.button !== 2) {
|
||||
Navigate.setMode(this);
|
||||
}
|
||||
return;
|
||||
|
||||
@ -91,6 +91,7 @@ Index =
|
||||
@navLinks = $.el 'div',
|
||||
className: 'navLinks'
|
||||
innerHTML: <%= importHTML('Features/Index-navlinks') %>
|
||||
@timeEl = $ 'time#index-last-refresh', @navLinks
|
||||
|
||||
@searchInput = $ '#index-search', @navLinks
|
||||
|
||||
@ -112,7 +113,8 @@ Index =
|
||||
|
||||
@currentPage = @getCurrentPage()
|
||||
|
||||
$.on d, 'scroll', Index.scroll
|
||||
$.on d, 'scroll', @scroll
|
||||
$.on window, 'focus', @updateIfNeeded
|
||||
$.on @pagelist, 'click', @cb.pageNav
|
||||
$.on $('#returnlink a', @navLinks), 'click', (e) ->
|
||||
if g.VIEW is 'index'
|
||||
@ -488,6 +490,18 @@ Index =
|
||||
else
|
||||
"#{hiddenCount} hidden threads"
|
||||
|
||||
updateIfNeeded: ->
|
||||
{timeEl} = Index
|
||||
needed =
|
||||
# we're on the index,
|
||||
g.VIEW is 'index' and
|
||||
# not currently refreshing
|
||||
!Index.req and
|
||||
timeEl.dataset.utc and
|
||||
# more than 10 minutes have elapsed since the last refresh.
|
||||
timeEl.dataset.utc < Date.now() - (10 * $.MINUTE)
|
||||
Index.update() if needed
|
||||
|
||||
update: (pageNum) ->
|
||||
return unless navigator.onLine
|
||||
if g.VIEW is 'thread'
|
||||
@ -565,7 +579,7 @@ Index =
|
||||
new Notice 'error', 'Index refresh failed.', 1
|
||||
return
|
||||
|
||||
timeEl = $ 'time#index-last-refresh', Index.navLinks
|
||||
{timeEl} = Index
|
||||
timeEl.dataset.utc = Date.parse req.getResponseHeader 'Last-Modified'
|
||||
RelativeDates.update timeEl
|
||||
Index.scrollToIndex()
|
||||
|
||||
@ -202,8 +202,8 @@ Navigate =
|
||||
return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org'
|
||||
if e
|
||||
if e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0) # Not simply a left click
|
||||
Navigate.setMode @ unless e?.button is 2 # Right Click
|
||||
return
|
||||
Navigate.setMode @ unless e.button is 2 # Right Click
|
||||
return
|
||||
|
||||
if @pathname is Navigate.path
|
||||
if g.VIEW is 'thread'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user