From 82646724e5f7aae807bb56ba271c4ff99e05bd67 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 14 Jan 2014 02:35:11 -0700 Subject: [PATCH] More bulk. --- builds/appchan-x.user.js | 50 +++++++++++++++++++++----------------- builds/crx/script.js | 50 +++++++++++++++++++++----------------- src/Theming/Mascots.coffee | 35 ++++++++++++++------------ 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 3c126e4e3..8d7a0872a 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -13143,11 +13143,12 @@ return Settings.open("Mascots"); }, importMascot: function() { - var file, reader; + var file, len, reader; file = this.files[0]; reader = new FileReader(); - reader.onload = function(e) { - var err, mascot, mascots, message, name, _i, _len; + len = Conf["Deleted Mascots"].length; + reader.onload = function() { + var err, mascots; try { mascots = JSON.parse(e.target.result); } catch (_error) { @@ -13155,24 +13156,35 @@ alert(err); return; } - if (name = mascots["Mascot"]) { - MascotTools.parse(mascots); - message = "" + name + " successfully imported!"; - } else if (mascots.length) { - for (_i = 0, _len = mascots.length; _i < _len; _i++) { - mascot = mascots[_i]; - MascotTools.parse(mascot); + $.get("userMascots", {}, function(_arg) { + var mascot, message, name, userMascots, _i, _len; + userMascots = _arg.userMascots; + if (name = mascots["Mascot"]) { + MascotTools.parse(mascots, userMascots); + return message = "" + name + " successfully imported!"; + } else if (mascots.length) { + for (_i = 0, _len = mascots.length; _i < _len; _i++) { + mascot = mascots[_i]; + MascotTools.parse(mascot, userMascots); + } + return message = "Mascots imported!"; + } else { + return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5); } - message = "Mascots imported!"; - } else { - return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5); + }); + $.set('userMascots', userMascots); + if (len !== Conf["Deleted Mascots"].length) { + $.set('Deleted Mascots', Conf['Deleted Mascots']); } new Notice('info', message, 10); - return Settings.open('Mascots'); + return Settings.openSection.call({ + open: Settings.mascots, + hyphenatedTitle: 'mascots' + }); }; return reader.readAsText(file); }, - parse: function(mascot) { + parse: function(mascot, userMascots) { var name; if (!(name = mascot["Mascot"])) { new Notice('warning', "Failed to import a mascot. Mascot has no name.", 5); @@ -13184,13 +13196,7 @@ return; } } - Mascots[name] = mascot; - return $.get("userMascots", {}, function(_arg) { - var userMascots; - userMascots = _arg.userMascots; - userMascots[name] = Mascots[name]; - return $.set('userMascots', userMascots); - }); + return userMascots[name] = Mascots[name] = mascot; }, position: function(mascot) { if (!Style.sheets.mascots) { diff --git a/builds/crx/script.js b/builds/crx/script.js index ced5466d5..487093b7e 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -13132,11 +13132,12 @@ return Settings.open("Mascots"); }, importMascot: function() { - var file, reader; + var file, len, reader; file = this.files[0]; reader = new FileReader(); - reader.onload = function(e) { - var err, mascot, mascots, message, name, _i, _len; + len = Conf["Deleted Mascots"].length; + reader.onload = function() { + var err, mascots; try { mascots = JSON.parse(e.target.result); } catch (_error) { @@ -13144,24 +13145,35 @@ alert(err); return; } - if (name = mascots["Mascot"]) { - MascotTools.parse(mascots); - message = "" + name + " successfully imported!"; - } else if (mascots.length) { - for (_i = 0, _len = mascots.length; _i < _len; _i++) { - mascot = mascots[_i]; - MascotTools.parse(mascot); + $.get("userMascots", {}, function(_arg) { + var mascot, message, name, userMascots, _i, _len; + userMascots = _arg.userMascots; + if (name = mascots["Mascot"]) { + MascotTools.parse(mascots, userMascots); + return message = "" + name + " successfully imported!"; + } else if (mascots.length) { + for (_i = 0, _len = mascots.length; _i < _len; _i++) { + mascot = mascots[_i]; + MascotTools.parse(mascot, userMascots); + } + return message = "Mascots imported!"; + } else { + return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5); } - message = "Mascots imported!"; - } else { - return new Notice('warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5); + }); + $.set('userMascots', userMascots); + if (len !== Conf["Deleted Mascots"].length) { + $.set('Deleted Mascots', Conf['Deleted Mascots']); } new Notice('info', message, 10); - return Settings.open('Mascots'); + return Settings.openSection.call({ + open: Settings.mascots, + hyphenatedTitle: 'mascots' + }); }; return reader.readAsText(file); }, - parse: function(mascot) { + parse: function(mascot, userMascots) { var name; if (!(name = mascot["Mascot"])) { new Notice('warning', "Failed to import a mascot. Mascot has no name.", 5); @@ -13173,13 +13185,7 @@ return; } } - Mascots[name] = mascot; - return $.get("userMascots", {}, function(_arg) { - var userMascots; - userMascots = _arg.userMascots; - userMascots[name] = Mascots[name]; - return $.set('userMascots', userMascots); - }); + return userMascots[name] = Mascots[name] = mascot; }, position: function(mascot) { if (!Style.sheets.mascots) { diff --git a/src/Theming/Mascots.coffee b/src/Theming/Mascots.coffee index b5bd1962b..f05a60aea 100644 --- a/src/Theming/Mascots.coffee +++ b/src/Theming/Mascots.coffee @@ -337,30 +337,37 @@ MascotTools = importMascot: -> file = @files[0] reader = new FileReader() + len = Conf["Deleted Mascots"].length - reader.onload = (e) -> + reader.onload = -> try mascots = JSON.parse e.target.result catch err alert err return - if name = mascots["Mascot"] - MascotTools.parse mascots - message = "#{name} successfully imported!" - else if mascots.length - MascotTools.parse mascot for mascot in mascots - message = "Mascots imported!" - else - return new Notice 'warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5 + $.get "userMascots", {}, ({userMascots}) -> + if name = mascots["Mascot"] + MascotTools.parse mascots, userMascots + message = "#{name} successfully imported!" + else if mascots.length + MascotTools.parse mascot, userMascots for mascot in mascots + message = "Mascots imported!" + else + return new Notice 'warning', "Failed to import mascot. Is file a properly formatted JSON file?", 5 + + $.set 'userMascots', userMascots + $.set 'Deleted Mascots', Conf['Deleted Mascots'] unless len is Conf["Deleted Mascots"].length new Notice 'info', message, 10 - Settings.open 'Mascots' + Settings.openSection.call + open: Settings.mascots + hyphenatedTitle: 'mascots' reader.readAsText file - parse: (mascot) -> + parse: (mascot, userMascots) -> unless name = mascot["Mascot"] new Notice 'warning', "Failed to import a mascot. Mascot has no name.", 5 return @@ -370,11 +377,7 @@ MascotTools = if Mascots[name] and not $.remove Conf["Deleted Mascots"], name return unless confirm "The mascot #{name} already exists? Would you like to overwrite it?" - Mascots[name] = mascot - - $.get "userMascots", {}, ({userMascots}) -> - userMascots[name] = Mascots[name] - $.set 'userMascots', userMascots + userMascots[name] = Mascots[name] = mascot position: (mascot) -> return unless Style.sheets.mascots