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

80 lines
2.0 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;", "");
2016-04-11 09:41:17 +02:00
};
//Html generation utils
Utils.prototype.getDiscordCheckbox = function(data) {
return '\
<div class="checkbox" onclick="'+data.onClick+'">\
<div class="checkbox-inner">\
<input type="checkbox" id="'+data.id+'" '+(data.checked ? "checked" : "")+'>\
<span></span>\
</div>\
<span>'+data.text+'</span>\
</div>\
';
};