From 5c635badd240f3ad3cfd462bc443f9e562632b2a Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 25 Sep 2011 02:48:58 +0200 Subject: [PATCH] Clean options, keep it readable and organized. --- 4chan_x.user.js | 99 +++++++++++++++++++++++----- script.coffee | 169 +++++++++++++++++++++++++----------------------- 2 files changed, 172 insertions(+), 96 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 01e44fa2e..d407e9d91 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1117,15 +1117,78 @@ return $.replace(home, a); }, dialog: function() { - var arr, checked, description, dialog, hiddenNum, hiddenThreads, html, input, key, li, main, obj, overlay, ul, _i, _len, _ref, _ref2; - hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); - hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length; - html = "
| | |

    Backlink formatting
  • :
    Time formatting
  • :
  • Supported format specifiers:
  • Day: %a, %A, %d, %e
  • Month: %m, %b, %B
  • Year: %y
  • Hour: %k, %H, %l (lowercase L), %I (uppercase i), %p, %P
  • Minutes: %M
ActionsKeybinds
Close Options or QR
Quick spoiler
Open QR with post number inserted
Open QR without post number inserted
Submit post
Select next reply
Select previous reply
See next thread
See previous thread
Jump to the next page
Jump to the previous page
Jump to page 0
Open thread in current tab
Open thread in new tab
Expand thread
Watch thread
Hide thread
Expand selected image
Expand all images
Update now
Reset the unread count to 0
"; + var arr, back, checked, description, dialog, flavors, hiddenNum, hiddenThreads, input, key, li, obj, overlay, time, ul, _i, _len, _ref, _ref2; dialog = $.el('div', { id: 'options', - innerHTML: html + innerHTML: '\ +
\ +
\ +
\ + \ + | \ + | \ + | \ +
\ +
\ + 4chan X\ + | Support Throd\ + | GitHub\ + | Donate\ +
\ +
\ +
\ +
\ + \ +
\ + \ + \ + \ +
\ +
    \ + Backlink formatting\ +
  • :
  • \ +
\ +
    \ + Time formatting\ +
  • :
  • \ +
  • Supported format specifiers:
  • \ +
  • Day: %a, %A, %d, %e
  • \ +
  • Month: %m, %b, %B
  • \ +
  • Year: %y
  • \ +
  • Hour: %k, %H, %l (lowercase L), %I (uppercase i), %p, %P
  • \ +
  • Minutes: %M
  • \ +
\ +
\ + \ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
ActionsKeybinds
Close Options or QR
Quick spoiler
Open QR with post number inserted
Open QR without post number inserted
Submit post
Select next reply
Select previous reply
See next thread
See previous thread
Jump to the next page
Jump to the previous page
Jump to page 0
Open thread in current tab
Open thread in new tab
Expand thread
Watch thread
Hide thread
Expand selected image
Expand all images
Update now
Reset the unread count to 0
\ +
\ +
\ +
' }); - main = $('#main', dialog); _ref = config.main; for (key in _ref) { obj = _ref[key]; @@ -1142,19 +1205,25 @@ $.bind($('input', li), 'click', $.cb.checked); $.add(ul, li); } - $.add(main, ul); + $.add($('#main', dialog), ul); } + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); + hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length; li = $.el('li', { innerHTML: " : Forget all hidden posts. Useful if you accidentally hide a post and have `show stubs` disabled." }); $.bind($('button', li), 'click', options.clearHidden); $.add($('ul:nth-child(2)', dialog), li); - $.bind($('#flavors', dialog), 'change', $.cb.value); - $.bind($('input[name=time]', dialog), 'keyup', options.time); - $.bind($('input[name=backlink]', dialog), 'keyup', options.backlink); + (flavors = $('#flavors', dialog)).textContent = conf['flavors']; + $.bind(flavors, 'change', $.cb.value); + (back = $('[name=backlink]', dialog)).value = conf['backlink']; + (time = $('[name=time]', dialog)).value = conf['time']; + $.bind(back, 'keyup', options.backlink); + $.bind(time, 'keyup', options.time); _ref2 = $$('#keybinds input', dialog); for (_i = 0, _len = _ref2.length; _i < _len; _i++) { input = _ref2[_i]; + input.type = 'text'; input.value = conf[input.name]; $.bind(input, 'keydown', options.keybind); } @@ -1167,16 +1236,16 @@ overlay = $.el('div', { id: 'overlay' }); - $.add(overlay, dialog); - $.add(d.body, overlay); - options.time.call($('input[name=time]', dialog)); - options.backlink.call($('input[name=backlink]', dialog)); $.bind(overlay, 'click', function() { return $.rm(overlay); }); - return $.bind(dialog.firstElementChild, 'click', function(e) { + $.bind(dialog.firstElementChild, 'click', function(e) { return e.stopPropagation(); }); + $.add(overlay, dialog); + $.add(d.body, overlay); + options.time.call(time); + return options.backlink.call(back); }, clearHidden: function(e) { $["delete"]("hiddenReplies/" + g.BOARD + "/"); diff --git a/script.coffee b/script.coffee index dbdde85c1..e923f819d 100644 --- a/script.coffee +++ b/script.coffee @@ -796,79 +796,76 @@ options = $.replace home, a dialog: -> - hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} - hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length - html = " -
-
-
- | | | -
- -
-
-
- -
- - - -
-
    - Backlink formatting -
  • :
  • -
-
    - Time formatting -
  • :
  • -
  • Supported format specifiers:
  • -
  • Day: %a, %A, %d, %e
  • -
  • Month: %m, %b, %B
  • -
  • Year: %y
  • -
  • Hour: %k, %H, %l (lowercase L), %I (uppercase i), %p, %P
  • -
  • Minutes: %M
  • -
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - -
ActionsKeybinds
Close Options or QR
Quick spoiler
Open QR with post number inserted
Open QR without post number inserted
Submit post
Select next reply
Select previous reply
See next thread
See previous thread
Jump to the next page
Jump to the previous page
Jump to page 0
Open thread in current tab
Open thread in new tab
Expand thread
Watch thread
Hide thread
Expand selected image
Expand all images
Update now
Reset the unread count to 0
-
-
-
- " + dialog = $.el 'div', id: 'options', innerHTML: ' +
+
+
+ + | + | + | +
+ +
+
+
+ +
+ + + +
+
    + Backlink formatting +
  • :
  • +
+
    + Time formatting +
  • :
  • +
  • Supported format specifiers:
  • +
  • Day: %a, %A, %d, %e
  • +
  • Month: %m, %b, %B
  • +
  • Year: %y
  • +
  • Hour: %k, %H, %l (lowercase L), %I (uppercase i), %p, %P
  • +
  • Minutes: %M
  • +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
ActionsKeybinds
Close Options or QR
Quick spoiler
Open QR with post number inserted
Open QR without post number inserted
Submit post
Select next reply
Select previous reply
See next thread
See previous thread
Jump to the next page
Jump to the previous page
Jump to page 0
Open thread in current tab
Open thread in new tab
Expand thread
Watch thread
Hide thread
Expand selected image
Expand all images
Update now
Reset the unread count to 0
+
+
+
' - dialog = $.el 'div', id: 'options', innerHTML: html - main = $('#main', dialog) + #main for key, obj of config.main ul = $.el 'ul', textContent: key @@ -879,17 +876,28 @@ options = innerHTML: ": #{description}" $.bind $('input', li), 'click', $.cb.checked $.add ul, li - $.add main, ul + $.add $('#main', dialog), ul + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} + hiddenNum = Object.keys(g.hiddenReplies).length + Object.keys(hiddenThreads).length li = $.el 'li', innerHTML: " : Forget all hidden posts. Useful if you accidentally hide a post and have `show stubs` disabled." $.bind $('button', li), 'click', options.clearHidden $.add $('ul:nth-child(2)', dialog), li - $.bind $('#flavors', dialog), 'change', $.cb.value - $.bind $('input[name=time]', dialog), 'keyup', options.time - $.bind $('input[name=backlink]', dialog), 'keyup', options.backlink + #sauce + (flavors = $ '#flavors', dialog).textContent = conf['flavors'] + $.bind flavors, 'change', $.cb.value + + #rice + (back = $ '[name=backlink]', dialog).value = conf['backlink'] + (time = $ '[name=time]', dialog).value = conf['time'] + $.bind back, 'keyup', options.backlink + $.bind time, 'keyup', options.time + + #keybinds for input in $$ '#keybinds input', dialog + input.type = 'text' input.value = conf[input.name] $.bind input, 'keydown', options.keybind @@ -900,14 +908,13 @@ options = https://bugzilla.mozilla.org/show_bug.cgi?id=579776 ### overlay = $.el 'div', id: 'overlay' + $.bind overlay, 'click', -> $.rm overlay + $.bind dialog.firstElementChild, 'click', (e) -> e.stopPropagation() $.add overlay, dialog $.add d.body, overlay - options.time.call $('input[name=time]', dialog) - options.backlink.call $('input[name=backlink]', dialog) - - $.bind overlay, 'click', -> $.rm overlay - $.bind dialog.firstElementChild, 'click', (e) -> e.stopPropagation() + options.time.call time + options.backlink.call back clearHidden: (e) -> #'hidden' might be misleading; it's the number of IDs we're *looking* for,