diff --git a/appchan-x.user.js b/appchan-x.user.js index ee61ce41d..575c8e63d 100644 --- a/appchan-x.user.js +++ b/appchan-x.user.js @@ -4878,7 +4878,7 @@ return reader.readAsText(file); }, save: function(theme) { - var name, userThemes; + var name; name = theme["Theme"]; if (Themes[name] && !Themes[name]["Deleted"]) { @@ -4890,15 +4890,19 @@ } Themes[name] = JSON.parse(JSON.stringify(theme)); delete Themes[name]["Theme"]; - userThemes = $.get("userThemes", {}); - userThemes[name] = Themes[name]; - $.set('userThemes', userThemes); - $.set("theme", Conf['theme'] = name); - return alert("Theme \"" + name + "\" saved."); + return $.get("userThemes", {}, function(item) { + var userThemes; + + userThemes = item["userThemes"]; + userThemes[name] = Themes[name]; + $.set('userThemes', userThemes); + $.set("theme", Conf['theme'] = name); + return alert("Theme \"" + name + "\" saved."); + }); }, close: function() { Conf['editMode'] = false; - $.rm($id('themeConf')); + $.rm($.id('themeConf')); Style.addStyle(); return Settings.open('themes'); } @@ -12700,8 +12704,15 @@ boards: {} }; } - $.get(Conf, Main.initFeatures); - return $.on(d, '4chanMainInit', Main.initStyle); + $.extend(Conf, { + 'userThemes': [], + 'userMascots': [], + 'Enabled Mascots': [], + 'Enabled Mascots sfw': [], + 'Enabled Mascots nsfw': [], + 'Deleted Mascots': [] + }); + return $.get(Conf, Main.initFeatures); }, initFeatures: function(items) { var initFeatures, pathname; @@ -12725,43 +12736,13 @@ if (['b', 'd', 'e', 'gif', 'h', 'hc', 'hm', 'hr', 'pol', 'r', 'r9k', 'rs', 's', 'soc', 't', 'u', 'y'].contains(g.BOARD)) { g.TYPE = 'nsfw'; } - $.get("userThemes", {}, function(item) { - var name, theme, _ref; - - _ref = item["userThemes"]; - for (name in _ref) { - theme = _ref[name]; - Themes[name] = theme; - } - }); - $.get("userMascots", {}, function(item) { - var mascot, name, _ref; - - _ref = item["userMascots"]; - for (name in _ref) { - mascot = _ref[name]; - Mascots[name] = mascot; - } - }); + $.extend(Themes, Conf["userThemes"]); + $.extend(Mascots, Conf["userMascots"]); if (Conf["NSFW/SFW Mascots"]) { g.MASCOTSTRING = "Enabled Mascots " + g.TYPE; } else { g.MASCOTSTRING = "Enabled Mascots"; } - items = { - 'Enabled Mascots': [], - 'Enabled Mascots sfw': [], - 'Enabled Mascots nsfw': [], - 'Deleted Mascots': [] - }; - $.get(items, function(items) { - var key, val; - - for (key in items) { - val = items[key]; - Conf[key] = val; - } - }); switch (location.hostname) { case 'sys.4chan.org': Report.init(); diff --git a/src/appchan.coffee b/src/appchan.coffee index a7523d7ac..f97562efa 100644 --- a/src/appchan.coffee +++ b/src/appchan.coffee @@ -1773,14 +1773,15 @@ ThemeTools = Themes[name] = JSON.parse(JSON.stringify(theme)) delete Themes[name]["Theme"] - userThemes = $.get "userThemes", {} - userThemes[name] = Themes[name] - $.set 'userThemes', userThemes - $.set "theme", Conf['theme'] = name - alert "Theme \"#{name}\" saved." + $.get "userThemes", {}, (item) -> + userThemes = item["userThemes"] + userThemes[name] = Themes[name] + $.set 'userThemes', userThemes + $.set "theme", Conf['theme'] = name + alert "Theme \"#{name}\" saved." close: -> Conf['editMode'] = false - $.rm $id 'themeConf' + $.rm $.id 'themeConf' Style.addStyle() Settings.open 'themes' \ No newline at end of file diff --git a/src/main.coffee b/src/main.coffee index 10e639a0c..ef8baf058 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -304,9 +304,15 @@ Main = flatten null, Config for db in DataBoards Conf[db] = boards: {} - $.get Conf, Main.initFeatures + $.extend Conf, + 'userThemes': [] + 'userMascots': [] + 'Enabled Mascots': [] + 'Enabled Mascots sfw': [] + 'Enabled Mascots nsfw': [] + 'Deleted Mascots': [] - $.on d, '4chanMainInit', Main.initStyle + $.get Conf, Main.initFeatures initFeatures: (items) -> Conf = items @@ -328,32 +334,15 @@ Main = if ['b', 'd', 'e', 'gif', 'h', 'hc', 'hm', 'hr', 'pol', 'r', 'r9k', 'rs', 's', 'soc', 't', 'u', 'y'].contains g.BOARD g.TYPE = 'nsfw' - $.get "userThemes", {}, (item) -> - for name, theme of item["userThemes"] - Themes[name] = theme - return - - $.get "userMascots", {}, (item) -> - for name, mascot of item["userMascots"] - Mascots[name] = mascot - return + + $.extend Themes, Conf["userThemes"] + $.extend Mascots, Conf["userMascots"] if Conf["NSFW/SFW Mascots"] g.MASCOTSTRING = "Enabled Mascots #{g.TYPE}" else g.MASCOTSTRING = "Enabled Mascots" - items = - 'Enabled Mascots': [] - 'Enabled Mascots sfw': [] - 'Enabled Mascots nsfw': [] - 'Deleted Mascots': [] - - $.get items, (items) -> - for key, val of items - Conf[key] = val - return - switch location.hostname when 'sys.4chan.org' Report.init()