BetterDiscordApp-v2/js/bdapi.js

83 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-12-11 05:49:40 +01:00
/* BetterDiscordApp API for Plugins
* Version: 1.0
* Author: Jiiks | http://jiiks.net
* Date: 11/12/2015
* Last Update: 11/12/2015
* https://github.com/Jiiks/BetterDiscordApp
*
* Plugin Template: https://gist.github.com/Jiiks/71edd5af0beafcd08956
*/
2015-12-16 12:21:46 +01:00
function BdApi() {}
2015-12-11 05:49:40 +01:00
//Joins a server
//code = server invite code
2015-12-11 05:53:23 +01:00
BdApi.joinServer = function(code) {
2015-12-16 12:21:46 +01:00
opublicServers.joinServer(code);
2015-12-11 05:49:40 +01:00
};
//Inject CSS to document head
//id = id of element
//css = custom css
2015-12-11 05:53:23 +01:00
BdApi.injectCSS = function(id, css) {
2015-12-16 12:21:46 +01:00
$("head").append('<style id="'+id+'"></style>')
$("#" + id).html(css);
2015-12-11 05:49:40 +01:00
};
//Clear css/remove any element
//id = id of element
2015-12-11 05:53:23 +01:00
BdApi.clearCSS = function(id) {
2015-12-16 12:21:46 +01:00
$("#"+id).remove();
2015-12-11 05:49:40 +01:00
};
//Get another plugin
//name = name of plugin
2015-12-11 05:53:23 +01:00
BdApi.getPlugin = function(name) {
2015-12-16 12:21:46 +01:00
if(bdplugins.hasOwnProperty(name)) {
return bdplugins[name]["plugin"];
}
return null;
2015-12-11 05:49:40 +01:00
};
//Get ipc for reason
2015-12-11 05:53:23 +01:00
BdApi.getIpc = function() {
2015-12-16 12:21:46 +01:00
return betterDiscordIPC;
2015-12-11 05:49:40 +01:00
};
//Get BetterDiscord Core
2015-12-11 05:53:23 +01:00
BdApi.getCore = function() {
2015-12-16 12:21:46 +01:00
return mainCore;
};
//Attempts to get user id by username
//Name = username
//Since Discord hides users if there's too many, this will often fail
BdApi.getUserIdByName = function(name) {
var users = $(".member-username");
for(var i = 0 ; i < users.length ; i++) {
var user = $(users[i]);
if(user.text() == name) {
var avatarUrl = user.closest(".member").find(".avatar-small").css("background-image");
return avatarUrl.match(/\d+/);
}
}
return null;
};
//Attempts to get username by id
//ID = user id
//Since Discord hides users if there's too many, this will often fail
var gg;
BdApi.getUserNameById = function(id) {
var users = $(".avatar-small");
for(var i = 0 ; i < users.length ; i++) {
var user = $(users[i]);
var url = user.css("background-image");
if(id == url.match(/\d+/)) {
return user.parent().find(".member-username").text();
}
}
return null;
2015-12-11 05:49:40 +01:00
};