From 8e5c1e292fcaebd7410b636c97da243cbc829a95 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 13 Nov 2010 23:19:53 -0800 Subject: [PATCH] use `_i`, `_len` in thread nav loop --- 4chan_x.coffee | 41 ++++++++++++++++++----------------------- 4chan_x.js | 43 +++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/4chan_x.coffee b/4chan_x.coffee index edafa6b5d..cd6d21ecb 100644 --- a/4chan_x.coffee +++ b/4chan_x.coffee @@ -936,43 +936,38 @@ else #not reply $('form[name="post"]').addEventListener('submit', autoWatch, true) if getConfig 'Thread Navigation' - arr = $$('div > span.filesize, form > span.filesize') - i = 0 - l = arr.length - l1 = l + 1 - #should this be a while loop? + arr = $$ 'div > span.filesize, form > span.filesize' + l1 = arr.length - 1 for el in arr - if i isnt 0 + span = n 'span', + className: 'navlinks' + id: _i + if _i textContent = '▲' - href = "##{i}" - else if g.PAGENUM isnt 0 + href = "##{_i - 1}" + else if g.PAGENUM textContent = '◀' - href = "#{g.PAGENUM - 1}" + href = g.PAGENUM - 1 else textContent = '▲' href = "#navtop" - up = n 'a', className: 'pointer' textContent: textContent href: href - - span = n 'span', - className: 'navlinks' - id: ++i - i1 = i + 1 + if _i < l1 + textContent = '▼' + href = "##{_i + 1}" + else + textContent = '▶' + href = "#{g.PAGENUM + 1}#0" down = n 'a', className: 'pointer' - if i1 == l1 - down.textContent = '▶' - down.href = "#{g.PAGENUM + 1}#1" - else - down.textContent = '▼' - down.href = "##{i1}" - + textContent: textContent + href: href addTo span, up, tn(' '), down inBefore el, span - if location.hash is '#1' + if location.hash is '#0' window.location = window.location if getConfig 'Thread Expansion' diff --git a/4chan_x.js b/4chan_x.js index 2d44177ed..7b549fbfc 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1,5 +1,5 @@ (function() { - var $, $$, AEOS, DAY, _, _i, _len, _ref, _ref2, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, formSubmit, g, getConfig, getTime, hide, hideReply, hideThread, href, html, i, i1, id, iframe, iframeLoad, inAfter, inBefore, inputs, keyboardNav, l, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watcher, watcherUpdate, x; + var $, $$, AEOS, DAY, _, _i, _len, _ref, _ref2, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, formSubmit, g, getConfig, getTime, hide, hideReply, hideThread, href, html, id, iframe, iframeLoad, inAfter, inBefore, inputs, keyboardNav, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watcher, watcherUpdate, x; var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty; config = { 'Thread Hiding': [true, 'Hide entire threads'], @@ -1206,18 +1206,20 @@ } if (getConfig('Thread Navigation')) { arr = $$('div > span.filesize, form > span.filesize'); - i = 0; - l = arr.length; - l1 = l + 1; + l1 = arr.length - 1; _ref = arr; for (_i = 0, _len = _ref.length; _i < _len; _i++) { el = _ref[_i]; - if (i !== 0) { + span = n('span', { + className: 'navlinks', + id: _i + }); + if (_i) { textContent = '▲'; - href = ("#" + (i)); - } else if (g.PAGENUM !== 0) { + href = ("#" + (_i - 1)); + } else if (g.PAGENUM) { textContent = '◀'; - href = ("" + (g.PAGENUM - 1)); + href = g.PAGENUM - 1; } else { textContent = '▲'; href = "#navtop"; @@ -1227,25 +1229,22 @@ textContent: textContent, href: href }); - span = n('span', { - className: 'navlinks', - id: ++i - }); - i1 = i + 1; - down = n('a', { - className: 'pointer' - }); - if (i1 === l1) { - down.textContent = '▶'; - down.href = ("" + (g.PAGENUM + 1) + "#1"); + if (_i < l1) { + textContent = '▼'; + href = ("#" + (_i + 1)); } else { - down.textContent = '▼'; - down.href = ("#" + (i1)); + textContent = '▶'; + href = ("" + (g.PAGENUM + 1) + "#0"); } + down = n('a', { + className: 'pointer', + textContent: textContent, + href: href + }); addTo(span, up, tn(' '), down); inBefore(el, span); } - if (location.hash === '#1') { + if (location.hash === '#0') { window.location = window.location; } }