From 3fa7368b6b8a66fb0d5b7465dfc8e7d93934890c Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 16 Mar 2012 00:34:57 -0700 Subject: [PATCH] mv config flattening into Main.init --- 4chan_x.user.js | 34 ++++++++++++++++------------------ script.coffee | 26 +++++++++++++------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index acaa7eaa9..03db7fed6 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -73,7 +73,7 @@ */ (function() { - var $, $$, Anonymize, AutoGif, Conf, Config, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, ImageExpand, ImageHover, Keybinds, Main, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportButton, RevealSpoilers, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Threading, Time, TitlePost, UI, Unread, Updater, Watcher, flatten, _base; + var $, $$, Anonymize, AutoGif, Config, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, ImageExpand, ImageHover, Keybinds, Main, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportButton, RevealSpoilers, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Threading, Time, TitlePost, UI, Unread, Updater, Watcher, _base; Config = { main: { @@ -192,22 +192,6 @@ } }; - Conf = {}; - - (flatten = function(parent, obj) { - var key, val; - if (obj instanceof Array) { - Conf[parent] = obj[0]; - } else if (typeof obj === 'object') { - for (key in obj) { - val = obj[key]; - flatten(key, val); - } - } else { - Conf[parent] = obj; - } - })(null, Config); - UI = { dialog: function(id, position, html) { var el, saved; @@ -3790,7 +3774,21 @@ Main = { init: function() { - var cutoff, hiddenThreads, id, key, now, path, pathname, temp, timestamp, val, _ref; + var Conf, cutoff, flatten, hiddenThreads, id, key, now, path, pathname, temp, timestamp, val, _ref; + Conf = {}; + (flatten = function(parent, obj) { + var key, val; + if (obj instanceof Array) { + Conf[parent] = obj[0]; + } else if (typeof obj === 'object') { + for (key in obj) { + val = obj[key]; + flatten(key, val); + } + } else { + Conf[parent] = obj; + } + })(null, Config); path = location.pathname; pathname = path.slice(1).split('/'); Main.BOARD = pathname[0], temp = pathname[1]; diff --git a/script.coffee b/script.coffee index 0e7926152..52c9dfae5 100644 --- a/script.coffee +++ b/script.coffee @@ -154,19 +154,6 @@ Config = 'Auto Update': [true, 'Automatically fetch new posts'] 'Interval': 30 -# flatten the config -Conf = {} -(flatten = (parent, obj) -> - if obj instanceof Array - Conf[parent] = obj[0] - else if typeof obj is 'object' - for key, val of obj - flatten key, val - else # string or number - Conf[parent] = obj - return -) null, Config - UI = dialog: (id, position, html) -> el = $.d.createElement 'div' @@ -3153,6 +3140,19 @@ ImageExpand = Main = init: -> + # flatten the config + Conf = {} + (flatten = (parent, obj) -> + if obj instanceof Array + Conf[parent] = obj[0] + else if typeof obj is 'object' + for key, val of obj + flatten key, val + else # string or number + Conf[parent] = obj + return + ) null, Config + path = location.pathname pathname = path[1..].split '/' [Main.BOARD, temp] = pathname