Allow multiple mascots to be imported at the same time
This commit is contained in:
parent
141f9b6dd3
commit
0e184ec153
2
LICENSE
2
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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user