/* BetterDiscordApp PublicSevers JavaScripts
* Version: 1.0
* Author: Jiiks | http://jiiks.net
* Date: 27/08/2015 - 14:16
* https://github.com/Jiiks/BetterDiscordApp
*/
var publicServers = { "servers": { "server": { "code": 0, "icon": null, "title": "title", "language": "EN", "description": "description" } } }; //for ide
function PublicServers() {
}
PublicServers.prototype.getPanel = function() {
return this.container;
};
PublicServers.prototype.init = function() {
var self = this;
this.container = $("
", {
id: "bd-ps-container",
style: "display:none"
});
var header = $("", {
id: "bd-ps-header"
});
$("", {
text: "Public Servers"
}).appendTo(header);
$("", {
id: "bd-ps-close",
style:"cursor:pointer;",
text: "X"
}).appendTo(header);
header.appendTo(this.getPanel());
var psbody = $("", {
id: "bd-ps-body"
});
psbody.appendTo(this.getPanel());
var table = $("", {
border:"0"
});
var thead = $("");
thead.appendTo(table);
var headers = $("
", {
}).append($(" | ", {
text: "Name"
})).append($(" | ", {
text: "Code"
})).append($(" | ", {
text: "Language"
})).append($(" | ", {
text: "Description"
})).append($(" | ", {
text: "Join"
}));
headers.appendTo(thead);
var tbody = $("", {
id: "bd-ps-tbody"
});
tbody.appendTo(table);
table.appendTo(psbody);
$("body").append(this.getPanel());
$("#bd-ps-close").on("click", function() { self.show(); });
var servers = publicServers.servers;
for(var server in servers) {
if(servers.hasOwnProperty(server)) {
var s = servers[server];
var code = s.code;
var title = s.title;
var language = s.language;
var description = s.description;
this.addServer(server, code, title, language, description);
}
}
};
PublicServers.prototype.addServer = function(name, code, title, language, description) {
var self = this;
var tableBody = $("#bd-ps-tbody");
var desc = $(" | ").append($("", {
class: "bd-ps-description",
text: description
}));
var tr = $("
");
tr.append($(" | ", {
text: title
}));
tr.append($(" | ", {
css: {
"-webkit-user-select":"initial",
"user-select":"initial"
},
text: code
}));
tr.append($(" | ", {
text: language
}));
tr.append(desc);
tr.append($(" | ").append($("", {
text: "Join",
css: {
"height": "30px",
"display": "block",
"margin-top": "10px",
"background-color": "#36393E",
"border": "1px solid #404040",
"outline": "1px solid #000",
"color": "#EDEDED"
},
click: function() { self.joinServer(code); }
})));
tableBody.append(tr);
};
PublicServers.prototype.show = function() {
this.getPanel().toggle();
var li = $("#bd-pub-li");
li.removeClass();
if(this.getPanel().is(":visible")) {
li.addClass("active");
}
};
//Workaround for joining a server
PublicServers.prototype.joinServer = function(code) {
console.log("Code: " + code);
$(".guilds-add").click();
$(".action.join .btn").click();
$(".create-guild-container input").val(code);
$(".form.join-server .btn-primary").click();
};