BetterDiscordApp-v2/dev/js/07utils.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-08-26 18:41:18 +02:00
/* BetterDiscordApp Utilities JavaScript
* Version: 1.0
* Author: Jiiks | http://jiiks.net
* Date: 26/08/2015 - 15:54
* https://github.com/Jiiks/BetterDiscordApp
*/
2015-11-01 12:37:04 +01:00
var _hash;
2016-04-10 14:43:27 +02:00
2015-08-26 18:41:18 +02:00
function Utils() {
}
2016-04-10 14:43:27 +02:00
Utils.prototype.getTextArea = function () {
2015-08-26 18:41:18 +02:00
return $(".channel-textarea-inner textarea");
};
2015-08-26 18:41:18 +02:00
2016-04-10 14:43:27 +02:00
Utils.prototype.jqDefer = function (fnc) {
if (window.jQuery) {
fnc();
} else {
setTimeout(function () {
this.jqDefer(fnc);
}, 100);
}
2015-11-01 12:37:04 +01:00
};
2016-04-10 14:43:27 +02:00
Utils.prototype.getHash = function () {
$.getJSON("https://api.github.com/repos/Jiiks/BetterDiscordApp/commits/master", function (data) {
2015-11-01 12:37:04 +01:00
_hash = data.sha;
2015-12-16 12:21:46 +01:00
emoteModule.getBlacklist();
2015-11-01 12:37:04 +01:00
});
2015-12-16 12:21:46 +01:00
};
2016-04-10 14:43:27 +02:00
Utils.prototype.loadHtml = function (html, callback) {
var container = $("<div/>", {
class: "bd-container"
}).appendTo("body");
//TODO Inject these in next core update
html = '//cdn.rawgit.com/Jiiks/BetterDiscordApp/' + _hash + '/html/' + html + '.html';
2015-12-16 12:21:46 +01:00
2016-04-10 14:43:27 +02:00
container.load(html, callback());
2015-12-16 12:21:46 +01:00
};
2016-04-10 14:43:27 +02:00
Utils.prototype.injectJs = function (uri) {
2015-12-16 12:21:46 +01:00
$("<script/>", {
type: "text/javascript",
src: uri
}).appendTo($("body"));
};
2015-11-01 12:37:04 +01:00
2016-04-10 14:43:27 +02:00
Utils.prototype.injectCss = function (uri) {
2015-12-16 12:21:46 +01:00
$("<link/>", {
type: "text/css",
rel: "stylesheet",
href: uri
}).appendTo($("head"));
2016-04-10 14:43:27 +02:00
};
Utils.prototype.log = function (message) {
console.info("%c[BetterDiscord]%c " + message, "color:teal; font-weight:bold;", "");
};
Utils.prototype.err = function (message) {
console.info("%c[BetterDiscord]%c " + message, "color:red; font-weight:bold;", "");
};