mirror of
https://github.com/Threnklyn/MinecraftChat.git
synced 2026-05-30 01:38:29 +02:00
proper server store initialization
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
module.exports = function() {
|
||||
|
||||
// initialize servers store if doesn't exist
|
||||
localStorage.servers = localStorage.servers || "[]";
|
||||
|
||||
// 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 no servers are saved, load the default ones
|
||||
if (!servers || servers.length === 0) {
|
||||
servers = defaultServers;
|
||||
save();
|
||||
|
||||
Reference in New Issue
Block a user