diff --git a/LICENSE b/LICENSE index 62139460f..cb025aab5 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.4.0 - 2014-02-28 +* 4chan X - Version 1.4.0 - 2014-03-01 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index ef2b25b64..3551d8856 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -24,7 +24,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.4.0 - 2014-02-28 +* 4chan X - Version 1.4.0 - 2014-03-01 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE @@ -2783,7 +2783,7 @@ } else if (e.altKey) { Index.togglePin(thread); } else { - return; + Navigate.navigate.call(this); } return e.preventDefault(); }, @@ -9676,7 +9676,7 @@ node: function() { ThreadUpdater.thread = this; ThreadUpdater.root = this.OP.nodes.root.parentNode; - ThreadUpdater.lastPost = +Object.keys(this.posts).sort().slice(-1)[0]; + ThreadUpdater.lastPost = +this.posts.keys[this.posts.keys.length - 1]; ThreadUpdater.cb.interval.call($.el('input', { value: Conf['Interval'] })); @@ -9923,17 +9923,8 @@ if (!count) { ThreadUpdater.set('status', null, null); ThreadUpdater.outdateCount++; - } else { - ThreadUpdater.set('status', "+" + count, 'new'); - ThreadUpdater.outdateCount = 0; - if (Conf['Beep'] && d.hidden && Unread.posts && !Unread.posts.length) { - if (!ThreadUpdater.audio) { - ThreadUpdater.audio = $.el('audio', { - src: ThreadUpdater.beep - }); - } - ThreadUpdater.audio.play(); - } + sendEvent(); + return; } ThreadUpdater.set('status', "+" + count, 'new'); ThreadUpdater.outdateCount = 0; @@ -12818,7 +12809,10 @@ delete g.THREADID; QR.link.textContent = 'Start a Thread'; $.off(d, 'ThreadUpdate', QR.statusCheck); - return $.on(d, 'IndexRefresh', QR.generatePostableThreadsList); + $.on(d, 'IndexRefresh', QR.generatePostableThreadsList); + if (Conf['Index Mode'] === 'catalog') { + return $.addClass(doc, 'catalog-mode'); + } }, thread: function() { g.THREADID = +window.location.pathname.split('/')[3]; @@ -12827,7 +12821,10 @@ } QR.link.textContent = 'Reply to Thread'; $.on(d, 'ThreadUpdate', QR.statusCheck); - return $.off(d, 'IndexRefresh', QR.generatePostableThreadsList); + $.off(d, 'IndexRefresh', QR.generatePostableThreadsList); + if (Conf['Index Mode'] === 'catalog') { + return $.rmClass(doc, 'catalog-mode'); + } } }[g.VIEW](); }, @@ -12885,7 +12882,7 @@ style = d.cookie.match(new RegExp("\b" + type + "\_style\=([^;]+);\b")); return ["" + type + "_style", (style ? style[1] : base)]; }; - style = findStyle.apply(null, (sfw ? ['ws', 'Yotsuba B New'] : ['nws', 'Yotsuba New'])); + style = sfw ? findStyle('ws', 'Yotsuba B New') : findStyle('nws', 'Yotsuba New'); $.globalEval("var style_group = '" + style[0] + "'"); $('link[title=switch]', d.head).href = $("link[title='" + style[1] + "']", d.head).href; return Main.setClass(); @@ -12899,16 +12896,15 @@ return $('.boardTitle').textContent = d.title = "/" + board + "/ - " + title; }, navigate: function(e) { - var boardID, indexMode, indexSort, load, pageNum, path, threadID, view, _ref; - if (this.hostname !== 'boards.4chan.org' || window.location.hostname === 'rs.4chan.org' || (e && (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0)))) { + var boardID, indexMode, indexSort, load, pageNum, path, threadID, view, _, _ref, _ref1; + if (this.hostname !== 'boards.4chan.org' || window.location.hostname === 'rs.4chan.org') { + return; + } + if (e && (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0))) { return; } $.addClass(Index.button, 'fa-spin'); - path = this.pathname.split('/'); - if (path[0] === '') { - path.shift(); - } - boardID = path[0], view = path[1], threadID = path[2]; + _ref = this.pathname.split('/'), _ = _ref[0], boardID = _ref[1], view = _ref[2], threadID = _ref[3]; if ('f' === boardID || 'f' === g.BOARD.ID) { return; } @@ -12917,6 +12913,7 @@ } Navigate.title = function() {}; delete Index.pageNum; + $.rmAll(Header.hover); path = this.pathname; if (this.hash) { path += this.hash; @@ -12931,17 +12928,13 @@ pageNum = view; view = 'index'; } - _ref = this.dataset, indexMode = _ref.indexMode, indexSort = _ref.indexSort; + _ref1 = this.dataset, indexMode = _ref1.indexMode, indexSort = _ref1.indexSort; if (indexMode && Conf['Index Mode'] !== indexMode) { - $.set('Index Mode', indexMode); - Conf['Index Mode'] = indexMode; - Index.selectMode.value = indexMode; + $.set('Index Mode', Conf['Index Mode'] = Index.selectMode.value = indexMode); Index.cb.mode(); } if (indexSort && Conf['Index Sort'] !== indexSort) { - $.set('Index Sort', indexSort); - Conf['Index Sort'] = indexSort; - Index.selectSort.value = indexSort; + $.set('Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort); Index.cb.sort(); } if (view === g.VIEW && boardID === g.BOARD.ID) { @@ -12966,19 +12959,18 @@ } if (view === 'index') { return Index.update(pageNum); - } else { - Navigate.updateSFW(Favicon.SFW); - load = Navigate.load; - Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", { - onabort: load, - onloadend: load - }); - return setTimeout((function() { - if (Navigate.req && !Navigate.notice) { - return Navigate.notice = new Notice('info', 'Loading thread...'); - } - }), 3 * $.SECOND); } + Navigate.updateSFW(Favicon.SFW); + load = Navigate.load; + Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", { + onabort: load, + onloadend: load + }); + return setTimeout((function() { + if (Navigate.req && !Navigate.notice) { + return Navigate.notice = new Notice('info', 'Loading thread...'); + } + }), 3 * $.SECOND); }, load: function(e) { var err, notice, req; diff --git a/builds/crx/script.js b/builds/crx/script.js index 76a14ddb7..f8540e9af 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.4.0 - 2014-02-28 +* 4chan X - Version 1.4.0 - 2014-03-01 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE @@ -2842,7 +2842,7 @@ } else if (e.altKey) { Index.togglePin(thread); } else { - return; + Navigate.navigate.call(this); } return e.preventDefault(); }, @@ -9691,7 +9691,7 @@ node: function() { ThreadUpdater.thread = this; ThreadUpdater.root = this.OP.nodes.root.parentNode; - ThreadUpdater.lastPost = +Object.keys(this.posts).sort().slice(-1)[0]; + ThreadUpdater.lastPost = +this.posts.keys[this.posts.keys.length - 1]; ThreadUpdater.cb.interval.call($.el('input', { value: Conf['Interval'] })); @@ -9938,17 +9938,8 @@ if (!count) { ThreadUpdater.set('status', null, null); ThreadUpdater.outdateCount++; - } else { - ThreadUpdater.set('status', "+" + count, 'new'); - ThreadUpdater.outdateCount = 0; - if (Conf['Beep'] && d.hidden && Unread.posts && !Unread.posts.length) { - if (!ThreadUpdater.audio) { - ThreadUpdater.audio = $.el('audio', { - src: ThreadUpdater.beep - }); - } - ThreadUpdater.audio.play(); - } + sendEvent(); + return; } ThreadUpdater.set('status', "+" + count, 'new'); ThreadUpdater.outdateCount = 0; @@ -12832,7 +12823,10 @@ delete g.THREADID; QR.link.textContent = 'Start a Thread'; $.off(d, 'ThreadUpdate', QR.statusCheck); - return $.on(d, 'IndexRefresh', QR.generatePostableThreadsList); + $.on(d, 'IndexRefresh', QR.generatePostableThreadsList); + if (Conf['Index Mode'] === 'catalog') { + return $.addClass(doc, 'catalog-mode'); + } }, thread: function() { g.THREADID = +window.location.pathname.split('/')[3]; @@ -12841,7 +12835,10 @@ } QR.link.textContent = 'Reply to Thread'; $.on(d, 'ThreadUpdate', QR.statusCheck); - return $.off(d, 'IndexRefresh', QR.generatePostableThreadsList); + $.off(d, 'IndexRefresh', QR.generatePostableThreadsList); + if (Conf['Index Mode'] === 'catalog') { + return $.rmClass(doc, 'catalog-mode'); + } } }[g.VIEW](); }, @@ -12899,7 +12896,7 @@ style = d.cookie.match(new RegExp("\b" + type + "\_style\=([^;]+);\b")); return ["" + type + "_style", (style ? style[1] : base)]; }; - style = findStyle.apply(null, (sfw ? ['ws', 'Yotsuba B New'] : ['nws', 'Yotsuba New'])); + style = sfw ? findStyle('ws', 'Yotsuba B New') : findStyle('nws', 'Yotsuba New'); $.globalEval("var style_group = '" + style[0] + "'"); $('link[title=switch]', d.head).href = $("link[title='" + style[1] + "']", d.head).href; return Main.setClass(); @@ -12913,16 +12910,15 @@ return $('.boardTitle').textContent = d.title = "/" + board + "/ - " + title; }, navigate: function(e) { - var boardID, indexMode, indexSort, load, pageNum, path, threadID, view, _ref; - if (this.hostname !== 'boards.4chan.org' || window.location.hostname === 'rs.4chan.org' || (e && (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0)))) { + var boardID, indexMode, indexSort, load, pageNum, path, threadID, view, _, _ref, _ref1; + if (this.hostname !== 'boards.4chan.org' || window.location.hostname === 'rs.4chan.org') { + return; + } + if (e && (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0))) { return; } $.addClass(Index.button, 'fa-spin'); - path = this.pathname.split('/'); - if (path[0] === '') { - path.shift(); - } - boardID = path[0], view = path[1], threadID = path[2]; + _ref = this.pathname.split('/'), _ = _ref[0], boardID = _ref[1], view = _ref[2], threadID = _ref[3]; if ('f' === boardID || 'f' === g.BOARD.ID) { return; } @@ -12931,6 +12927,7 @@ } Navigate.title = function() {}; delete Index.pageNum; + $.rmAll(Header.hover); path = this.pathname; if (this.hash) { path += this.hash; @@ -12945,17 +12942,13 @@ pageNum = view; view = 'index'; } - _ref = this.dataset, indexMode = _ref.indexMode, indexSort = _ref.indexSort; + _ref1 = this.dataset, indexMode = _ref1.indexMode, indexSort = _ref1.indexSort; if (indexMode && Conf['Index Mode'] !== indexMode) { - $.set('Index Mode', indexMode); - Conf['Index Mode'] = indexMode; - Index.selectMode.value = indexMode; + $.set('Index Mode', Conf['Index Mode'] = Index.selectMode.value = indexMode); Index.cb.mode(); } if (indexSort && Conf['Index Sort'] !== indexSort) { - $.set('Index Sort', indexSort); - Conf['Index Sort'] = indexSort; - Index.selectSort.value = indexSort; + $.set('Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort); Index.cb.sort(); } if (view === g.VIEW && boardID === g.BOARD.ID) { @@ -12980,19 +12973,18 @@ } if (view === 'index') { return Index.update(pageNum); - } else { - Navigate.updateSFW(Favicon.SFW); - load = Navigate.load; - Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", { - onabort: load, - onloadend: load - }); - return setTimeout((function() { - if (Navigate.req && !Navigate.notice) { - return Navigate.notice = new Notice('info', 'Loading thread...'); - } - }), 3 * $.SECOND); } + Navigate.updateSFW(Favicon.SFW); + load = Navigate.load; + Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", { + onabort: load, + onloadend: load + }); + return setTimeout((function() { + if (Navigate.req && !Navigate.notice) { + return Navigate.notice = new Notice('info', 'Loading thread...'); + } + }), 3 * $.SECOND); }, load: function(e) { var err, notice, req; diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 14c8b6dbc..ec7140da6 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -203,7 +203,7 @@ Index = else if e.altKey Index.togglePin thread else - return + Navigate.navigate.call @ e.preventDefault() onOver: (e) -> diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index dda50cee4..3cdaf56c2 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -3,7 +3,7 @@ Navigate = init: -> return if g.VIEW is 'catalog' or g.BOARD.ID is 'f' or !Conf['JSON Navigation'] - $.ready -> + $.ready -> # blink/webkit throw a popstate on page load. Not what we want. $.on window, 'popstate', Navigate.popstate @@ -38,7 +38,7 @@ Navigate = g.threads.forEach (thread) -> thread.collect() QuoteBacklink.containers = {} - $.rmAll $('.board') + $.rmAll $ '.board' features: [ ['Thread Excerpt', ThreadExcerpt] @@ -102,12 +102,14 @@ Navigate = QR.link.textContent = 'Start a Thread' $.off d, 'ThreadUpdate', QR.statusCheck $.on d, 'IndexRefresh', QR.generatePostableThreadsList + $.addClass doc, 'catalog-mode' if Conf['Index Mode'] is 'catalog' thread: -> g.THREADID = +window.location.pathname.split('/')[3] return if oldView is g.VIEW QR.link.textContent = 'Reply to Thread' $.on d, 'ThreadUpdate', QR.statusCheck $.off d, 'IndexRefresh', QR.generatePostableThreadsList + $.rmClass doc, 'catalog-mode' if Conf['Index Mode'] is 'catalog' }[g.VIEW]() updateBoard: (boardID) -> @@ -150,10 +152,10 @@ Navigate = style = d.cookie.match new RegExp "\b#{type}\_style\=([^;]+);\b" return ["#{type}_style", (if style then style[1] else base)] - style = findStyle (if sfw - ['ws', 'Yotsuba B New'] + style = if sfw + findStyle 'ws', 'Yotsuba B New' else - ['nws', 'Yotsuba New'])... + findStyle 'nws', 'Yotsuba New' $.globalEval "var style_group = '#{style[0]}'" @@ -166,20 +168,19 @@ Navigate = $('.boardTitle').textContent = d.title = "/#{board}/ - #{title}" navigate: (e) -> - return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org' or - (e and (e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0))) # Not simply a left click + return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org' + return if e and (e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0)) # Not simply a left click $.addClass Index.button, 'fa-spin' - path = @pathname.split '/' - path.shift() if path[0] is '' - [boardID, view, threadID] = path + [_, boardID, view, threadID] = @pathname.split '/' return if 'f' in [boardID, g.BOARD.ID] e.preventDefault() if e Navigate.title = -> return delete Index.pageNum + $.rmAll Header.hover path = @pathname path += @hash if @hash @@ -195,18 +196,16 @@ Navigate = {indexMode, indexSort} = @dataset if indexMode and Conf['Index Mode'] isnt indexMode - $.set 'Index Mode', indexMode - Conf['Index Mode'] = indexMode - Index.selectMode.value = indexMode + $.set 'Index Mode', Conf['Index Mode'] = Index.selectMode.value = indexMode Index.cb.mode() + if indexSort and Conf['Index Sort'] isnt indexSort - $.set 'Index Sort', indexSort - Conf['Index Sort'] = indexSort - Index.selectSort.value = indexSort + $.set 'Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort Index.cb.sort() if view is g.VIEW and boardID is g.BOARD.ID Navigate.updateContext view + else # We've navigated somewhere we weren't before! Navigate.disconnect() Navigate.updateContext view @@ -220,20 +219,19 @@ Navigate = Navigate.title = -> Navigate.updateBoard boardID if view is 'index' - Index.update pageNum - + return Index.update pageNum + # Moving from index to thread or thread to thread - else - Navigate.updateSFW Favicon.SFW - {load} = Navigate - Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/res/#{threadID}.json", - onabort: load - onloadend: load + Navigate.updateSFW Favicon.SFW + {load} = Navigate + Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/res/#{threadID}.json", + onabort: load + onloadend: load - setTimeout (-> - if Navigate.req and !Navigate.notice - Navigate.notice = new Notice 'info', 'Loading thread...' - ), 3 * $.SECOND + setTimeout (-> + if Navigate.req and !Navigate.notice + Navigate.notice = new Notice 'info', 'Loading thread...' + ), 3 * $.SECOND load: (e) -> $.rmClass Index.button, 'fa-spin' diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 9b001ecec..69853e52e 100755 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -95,7 +95,7 @@ ThreadUpdater = node: -> ThreadUpdater.thread = @ ThreadUpdater.root = @OP.nodes.root.parentNode - ThreadUpdater.lastPost = +Object.keys(@posts).sort()[-1..][0] + ThreadUpdater.lastPost = +@posts.keys[@posts.keys.length - 1] ThreadUpdater.cb.interval.call $.el 'input', value: Conf['Interval'] @@ -321,13 +321,8 @@ ThreadUpdater = unless count ThreadUpdater.set 'status', null, null ThreadUpdater.outdateCount++ - else - ThreadUpdater.set 'status', "+#{count}", 'new' - ThreadUpdater.outdateCount = 0 - if Conf['Beep'] and d.hidden and Unread.posts and !Unread.posts.length - unless ThreadUpdater.audio - ThreadUpdater.audio = $.el 'audio', src: ThreadUpdater.beep - ThreadUpdater.audio.play() + sendEvent() + return ThreadUpdater.set 'status', "+#{count}", 'new' ThreadUpdater.outdateCount = 0