BetterDiscordApp-v1/dev/js/12api.js

112 lines
2.5 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
2016-04-10 14:43:27 +02:00
BdApi.joinServer = function (code) {
opublicServers.joinServer(code);
2015-12-11 05:49:40 +01:00
};
//Inject CSS to document head
//id = id of element
//css = custom css
2016-04-10 14:43:27 +02:00
BdApi.injectCSS = function (id, css) {
$("head").append('<style id="' + id + '"></style>');
2015-12-16 12:21:46 +01:00
$("#" + id).html(css);
2015-12-11 05:49:40 +01:00
};
//Clear css/remove any element
//id = id of element
2016-04-10 14:43:27 +02:00
BdApi.clearCSS = function (id) {
$("#" + id).remove();
2015-12-11 05:49:40 +01:00
};
//Get another plugin
//name = name of plugin
2016-04-10 14:43:27 +02:00
BdApi.getPlugin = function (name) {
if (bdplugins.hasOwnProperty(name)) {
2015-12-16 12:21:46 +01:00
return bdplugins[name]["plugin"];
}
return null;
2015-12-11 05:49:40 +01:00
};
//Get ipc for reason
2016-04-10 14:43:27 +02:00
BdApi.getIpc = function () {
return betterDiscordIPC;
2015-12-11 05:49:40 +01:00
};
//Get BetterDiscord Core
2016-04-10 14:43:27 +02:00
BdApi.getCore = function () {
return mainCore;
2015-12-16 12:21:46 +01:00
};
//Attempts to get user id by username
//Name = username
//Since Discord hides users if there's too many, this will often fail
2016-04-10 14:43:27 +02:00
BdApi.getUserIdByName = function (name) {
2015-12-16 12:21:46 +01:00
var users = $(".member-username");
2016-04-10 14:43:27 +02:00
for (var i = 0; i < users.length; i++) {
2015-12-16 12:21:46 +01:00
var user = $(users[i]);
2016-04-10 14:43:27 +02:00
if (user.text() == name) {
2015-12-16 12:21:46 +01:00
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;
2016-04-10 14:43:27 +02:00
BdApi.getUserNameById = function (id) {
2015-12-16 12:21:46 +01:00
var users = $(".avatar-small");
2016-04-10 14:43:27 +02:00
for (var i = 0; i < users.length; i++) {
2015-12-16 12:21:46 +01:00
var user = $(users[i]);
var url = user.css("background-image");
2016-04-10 14:43:27 +02:00
if (id == url.match(/\d+/)) {
2015-12-16 12:21:46 +01:00
return user.parent().find(".member-username").text();
}
}
return null;
2016-04-10 14:43:27 +02:00
};
//Set current game
//game = game
BdApi.setPlaying = function (game) {
bdws.send({
"op": 3,
"d": {
"idle_since": null,
"game": {
"name": game
}
}
});
};
//Set current status
//idle_since = date
//status = status
BdApi.setStatus = function (idle_since, status) {
bdws.send({
"op": 3,
"d": {
"idle_since": idle_since,
"game": {
"name": status
}
}
});
2015-12-11 05:49:40 +01:00
};