diff --git a/LICENSE b/LICENSE index 7e39b7151..9a32c0ad7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* appchan x - Version 2.8.4 - 2014-01-13 +* appchan x - Version 2.8.4 - 2014-01-14 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 9b159efc2..52e697ae7 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -22,7 +22,7 @@ // ==/UserScript== /* -* appchan x - Version 2.8.4 - 2014-01-13 +* appchan x - Version 2.8.4 - 2014-01-14 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -13327,37 +13327,49 @@ file = this.files[0]; reader = new FileReader(); reader.onload = function(e) { - var err, imported, name; + var err, len, mascot, mascots, message, name, _i, _len; try { - imported = JSON.parse(e.target.result); + mascots = JSON.parse(e.target.result); } catch (_error) { err = _error; alert(err); return; } - if (!imported["Mascot"]) { - alert("Mascot file is invalid."); - } - name = imported["Mascot"]; - delete imported["Mascot"]; - if (Mascots[name] && !$.remove(Conf["Deleted Mascots"], name)) { - if (!confirm("A mascot with this name already exists. Would you like to over-write?")) { - return; + if (name = mascots["Mascot"]) { + MascotTools.parse(mascot); + } else { + for (_i = 0, _len = mascots.length; _i < _len; _i++) { + mascot = mascots[_i]; + MascotTools.parse(mascot); } } - Mascots[name] = imported; - $.get("userMascots", {}, function(_arg) { - var userMascots; - userMascots = _arg.userMascots; - userMascots[name] = Mascots[name]; - return $.set('userMascots', userMascots); - }); - alert("Mascot \"" + name + "\" imported!"); + message = (len = mascots.length) ? "Mascots imported!" : "" + name + " successfully imported!"; + new Notice('info', message, 10); $.rm($("#mascotContainer", d.body)); return Settings.open('Mascots'); }; return reader.readAsText(file); }, + parse: function(mascot) { + var name; + if (!(name = mascot["Mascot"])) { + new Notice('warning', "Failed to import a mascot. Mascot has no name.", 5); + return; + } + delete mascot["Mascot"]; + if (Mascots[name] && !$.remove(Conf["Deleted Mascots"], name)) { + if (!confirm("The mascot " + name + " already exists? Would you like to overwrite it?")) { + return; + } + } + Mascots[name] = imported; + return $.get("userMascots", {}, function(_arg) { + var userMascots; + userMascots = _arg.userMascots; + userMascots[name] = Mascots[name]; + return $.set('userMascots', userMascots); + }); + }, position: function(mascot) { if (!Style.sheets.mascots) { return; diff --git a/builds/crx/script.js b/builds/crx/script.js index 8f6dbb96b..38efbf7dc 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* appchan x - Version 2.8.4 - 2014-01-13 +* appchan x - Version 2.8.4 - 2014-01-14 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -13316,37 +13316,49 @@ file = this.files[0]; reader = new FileReader(); reader.onload = function(e) { - var err, imported, name; + var err, len, mascot, mascots, message, name, _i, _len; try { - imported = JSON.parse(e.target.result); + mascots = JSON.parse(e.target.result); } catch (_error) { err = _error; alert(err); return; } - if (!imported["Mascot"]) { - alert("Mascot file is invalid."); - } - name = imported["Mascot"]; - delete imported["Mascot"]; - if (Mascots[name] && !$.remove(Conf["Deleted Mascots"], name)) { - if (!confirm("A mascot with this name already exists. Would you like to over-write?")) { - return; + if (name = mascots["Mascot"]) { + MascotTools.parse(mascot); + } else { + for (_i = 0, _len = mascots.length; _i < _len; _i++) { + mascot = mascots[_i]; + MascotTools.parse(mascot); } } - Mascots[name] = imported; - $.get("userMascots", {}, function(_arg) { - var userMascots; - userMascots = _arg.userMascots; - userMascots[name] = Mascots[name]; - return $.set('userMascots', userMascots); - }); - alert("Mascot \"" + name + "\" imported!"); + message = (len = mascots.length) ? "Mascots imported!" : "" + name + " successfully imported!"; + new Notice('info', message, 10); $.rm($("#mascotContainer", d.body)); return Settings.open('Mascots'); }; return reader.readAsText(file); }, + parse: function(mascot) { + var name; + if (!(name = mascot["Mascot"])) { + new Notice('warning', "Failed to import a mascot. Mascot has no name.", 5); + return; + } + delete mascot["Mascot"]; + if (Mascots[name] && !$.remove(Conf["Deleted Mascots"], name)) { + if (!confirm("The mascot " + name + " already exists? Would you like to overwrite it?")) { + return; + } + } + Mascots[name] = imported; + return $.get("userMascots", {}, function(_arg) { + var userMascots; + userMascots = _arg.userMascots; + userMascots[name] = Mascots[name]; + return $.set('userMascots', userMascots); + }); + }, position: function(mascot) { if (!Style.sheets.mascots) { return; diff --git a/src/Theming/Mascots.coffee b/src/Theming/Mascots.coffee index 3bc0ffa23..4427e2123 100644 --- a/src/Theming/Mascots.coffee +++ b/src/Theming/Mascots.coffee @@ -339,33 +339,44 @@ MascotTools = reader.onload = (e) -> try - imported = JSON.parse e.target.result + mascots = JSON.parse e.target.result catch err alert err return - unless (imported["Mascot"]) - alert "Mascot file is invalid." + if name = mascots["Mascot"] + MascotTools.parse mascot + else + MascotTools.parse mascot for mascot in mascots - name = imported["Mascot"] - delete imported["Mascot"] + message = if len = mascots.length + "Mascots imported!" + else + "#{name} successfully imported!" - if Mascots[name] and not $.remove Conf["Deleted Mascots"], name - unless confirm "A mascot with this name already exists. Would you like to over-write?" - return + new Notice 'info', message, 10 - Mascots[name] = imported - - $.get "userMascots", {}, ({userMascots}) -> - userMascots[name] = Mascots[name] - $.set 'userMascots', userMascots - - alert "Mascot \"#{name}\" imported!" $.rm $ "#mascotContainer", d.body Settings.open 'Mascots' reader.readAsText file + parse: (mascot) -> + unless name = mascot["Mascot"] + new Notice 'warning', "Failed to import a mascot. Mascot has no name.", 5 + return + + delete mascot["Mascot"] + + 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] = imported + + $.get "userMascots", {}, ({userMascots}) -> + userMascots[name] = Mascots[name] + $.set 'userMascots', userMascots + position: (mascot) -> return unless Style.sheets.mascots mascot.image? or mascot = Mascots[Conf['mascot']] or {} # event