diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 8d7a0872a..606c5b11f 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -2983,15 +2983,14 @@ }; })(); - $.remove = function(array, value) { + $.remove = function(arr, value) { var i; - i = array.indexOf(value); - if (i > -1) { - array.splice(i, 1); - return true; - } else { + i = arr.indexOf(value); + if (i === -1) { return false; } + arr.splice(i, 1); + return true; }; $$ = function(selector, root) { @@ -13143,11 +13142,10 @@ return Settings.open("Mascots"); }, importMascot: function() { - var file, len, reader; + var file, reader; file = this.files[0]; reader = new FileReader(); - len = Conf["Deleted Mascots"].length; - reader.onload = function() { + reader.onload = function(e) { var err, mascots; try { mascots = JSON.parse(e.target.result); @@ -13156,34 +13154,39 @@ alert(err); return; } - $.get("userMascots", {}, function(_arg) { - var mascot, message, name, userMascots, _i, _len; + return $.get("userMascots", {}, function(_arg) { + var userMascots; 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); - } - }); - $.set('userMascots', userMascots); - if (len !== Conf["Deleted Mascots"].length) { - $.set('Deleted Mascots', Conf['Deleted Mascots']); - } - new Notice('info', message, 10); - return Settings.openSection.call({ - open: Settings.mascots, - hyphenatedTitle: 'mascots' + return MascotTools.load(mascots, userMascots); }); }; return reader.readAsText(file); }, + load: function(mascots, userMascots) { + var len, mascot, message, name, _i, _len; + len = Conf["Deleted Mascots"].length; + if (name = mascots["Mascot"]) { + MascotTools.parse(mascots, userMascots); + message = "" + name + " successfully imported!"; + } else if (mascots.length) { + for (_i = 0, _len = mascots.length; _i < _len; _i++) { + mascot = mascots[_i]; + MascotTools.parse(mascot, userMascots); + } + 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.openSection.call({ + open: Settings.mascots, + hyphenatedTitle: 'mascots' + }); + }, parse: function(mascot, userMascots) { var name; if (!(name = mascot["Mascot"])) { diff --git a/builds/crx/script.js b/builds/crx/script.js index 487093b7e..35e34d9eb 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -2988,15 +2988,14 @@ }; })(); - $.remove = function(array, value) { + $.remove = function(arr, value) { var i; - i = array.indexOf(value); - if (i > -1) { - array.splice(i, 1); - return true; - } else { + i = arr.indexOf(value); + if (i === -1) { return false; } + arr.splice(i, 1); + return true; }; $$ = function(selector, root) { @@ -13132,11 +13131,10 @@ return Settings.open("Mascots"); }, importMascot: function() { - var file, len, reader; + var file, reader; file = this.files[0]; reader = new FileReader(); - len = Conf["Deleted Mascots"].length; - reader.onload = function() { + reader.onload = function(e) { var err, mascots; try { mascots = JSON.parse(e.target.result); @@ -13145,34 +13143,39 @@ alert(err); return; } - $.get("userMascots", {}, function(_arg) { - var mascot, message, name, userMascots, _i, _len; + return $.get("userMascots", {}, function(_arg) { + var userMascots; 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); - } - }); - $.set('userMascots', userMascots); - if (len !== Conf["Deleted Mascots"].length) { - $.set('Deleted Mascots', Conf['Deleted Mascots']); - } - new Notice('info', message, 10); - return Settings.openSection.call({ - open: Settings.mascots, - hyphenatedTitle: 'mascots' + return MascotTools.load(mascots, userMascots); }); }; return reader.readAsText(file); }, + load: function(mascots, userMascots) { + var len, mascot, message, name, _i, _len; + len = Conf["Deleted Mascots"].length; + if (name = mascots["Mascot"]) { + MascotTools.parse(mascots, userMascots); + message = "" + name + " successfully imported!"; + } else if (mascots.length) { + for (_i = 0, _len = mascots.length; _i < _len; _i++) { + mascot = mascots[_i]; + MascotTools.parse(mascot, userMascots); + } + 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.openSection.call({ + open: Settings.mascots, + hyphenatedTitle: 'mascots' + }); + }, parse: function(mascot, userMascots) { var name; if (!(name = mascot["Mascot"])) { diff --git a/src/General/lib/$.coffee b/src/General/lib/$.coffee index d8d0cfd22..3e45ed12a 100755 --- a/src/General/lib/$.coffee +++ b/src/General/lib/$.coffee @@ -404,13 +404,11 @@ $.set = do -> return <% } %> -$.remove = (array, value) -> - i = array.indexOf value - if i > -1 - array.splice i, 1 - true - else - false +$.remove = (arr, value) -> + i = arr.indexOf value + return false if i is -1 + arr.splice i, 1 + true $$ = (selector, root=d.body) -> [root.querySelectorAll(selector)...] diff --git a/src/Theming/Mascots.coffee b/src/Theming/Mascots.coffee index f05a60aea..bb54fbdf6 100644 --- a/src/Theming/Mascots.coffee +++ b/src/Theming/Mascots.coffee @@ -337,9 +337,8 @@ MascotTools = importMascot: -> file = @files[0] reader = new FileReader() - len = Conf["Deleted Mascots"].length - reader.onload = -> + reader.onload = (e) -> try mascots = JSON.parse e.target.result catch err @@ -347,26 +346,30 @@ MascotTools = return $.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.openSection.call - open: Settings.mascots - hyphenatedTitle: 'mascots' + MascotTools.load mascots, userMascots reader.readAsText file + load: (mascots, userMascots) -> + len = Conf["Deleted Mascots"].length + 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.openSection.call + open: Settings.mascots + hyphenatedTitle: 'mascots' + parse: (mascot, userMascots) -> unless name = mascot["Mascot"] new Notice 'warning', "Failed to import a mascot. Mascot has no name.", 5