mirror of
https://github.com/Threnklyn/MinecraftChat.git
synced 2026-06-01 18:58:27 +02:00
My Servers Feature
Store your favorite servers to easily select them when connecting
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
module.exports = function() {
|
||||
|
||||
// function to save servers into localStorage
|
||||
function save() {
|
||||
localStorage.servers = JSON.stringify(servers);
|
||||
}
|
||||
|
||||
|
||||
// default servers
|
||||
var defaultServers = [
|
||||
{name: 'LattyCraft', ip: 'us.latty.info', port: 25565}
|
||||
];
|
||||
|
||||
|
||||
// load servers from localstorage
|
||||
var servers = JSON.parse(localStorage.servers);
|
||||
|
||||
if (!servers || servers.length === 0) {
|
||||
servers = defaultServers;
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
get: function() {
|
||||
return servers;
|
||||
},
|
||||
select: function(id) {
|
||||
return servers[id];
|
||||
},
|
||||
add: function(server) {
|
||||
servers.push(server);
|
||||
save();
|
||||
},
|
||||
delete: function(index) {
|
||||
servers.splice(index, 1);
|
||||
save();
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user