parent
69d37bcb0a
commit
94b757e464
|
@ -19,7 +19,7 @@ function getMainWindow() {
|
|||
}
|
||||
|
||||
//Download using https
|
||||
function download(url, callback) {
|
||||
Helper.prototype.download = function(url, callback) {
|
||||
https.get(url, function(res) {
|
||||
var data = "";
|
||||
res.on('data', function (chunk) {
|
||||
|
@ -42,6 +42,14 @@ Helper.prototype.getWeb = function() {
|
|||
Helper.prototype.log = function(message) {
|
||||
this.execJs('console.log("BetterDiscord: ' + message + '");');
|
||||
}
|
||||
//Warn
|
||||
Helper.prototype.warn = function(message) {
|
||||
this.execJs('console.warn("BetterDiscord: ' + message + '");');
|
||||
}
|
||||
//Error
|
||||
Helper.prototype.error = function(message) {
|
||||
this.execJs('console.error("BetterDiscord: ' + message + '");');
|
||||
}
|
||||
|
||||
//Execute javascript
|
||||
Helper.prototype.execJs = function(js) {
|
||||
|
@ -56,10 +64,18 @@ Helper.prototype.injectToElementByTag = function(element, js, varname) {
|
|||
//Injects a stylesheet from url to head as internal style
|
||||
Helper.prototype.injectStylesheet = function(url) {
|
||||
var self = this;
|
||||
download(url, function(data) {
|
||||
this.download(url, function(data) {
|
||||
var js = 'var style = document.createElement("style"); style.type = "text/css"; style.innerHTML = "'+data+'";';
|
||||
self.injectToElementByTag("head", js, "style");
|
||||
});
|
||||
}
|
||||
|
||||
Helper.prototype.headStyleSheet = function(url) {
|
||||
this.execJs('(function() { var stylesheet = document.createElement("link"); stylesheet.type = "text/css"; document.getElementsByTagName("head")[0].appendChild(stylesheet); stylesheet.href = "'+url+'" })();')
|
||||
}
|
||||
|
||||
Helper.prototype.injectJavaScript = function(url) {
|
||||
this.execJs('(function() { var script = document.createElement("script"); script.type = "text/javascript"; document.getElementsByTagName("body")[0].appendChild(script); script.src = "'+url+'"; })();');
|
||||
}
|
||||
|
||||
exports.Helper = Helper;
|
|
@ -7,20 +7,35 @@
|
|||
|
||||
var _helpers = require('./helper.js');
|
||||
var _emoteModule = require('./modules/EmoteModule.js');
|
||||
var _config = require('./config.json');
|
||||
var _helper;
|
||||
var _mainWindow;
|
||||
var _version = "1.0.0";
|
||||
var _version = "1.0.0";//https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js
|
||||
|
||||
function BetterDiscordApp(mainWindow) {
|
||||
_mainWindow = mainWindow;
|
||||
_helper = new _helpers.Helper(mainWindow);
|
||||
_helper.getWeb().on('did-finish-load', function() { init(); });
|
||||
_helper.getWeb().on('dom-ready', function() {
|
||||
_helper.log("dom-ready");
|
||||
_helper.injectJavaScript("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"); //jquery
|
||||
//TODO make this proper
|
||||
setTimeout(function() { //Temporary timer for letting jquery fully load
|
||||
_emoteModule = new _emoteModule.EmoteModule(_helper);
|
||||
// _helper.injectJavaScript("https://rawgit.com/Jiiks/BetterDiscordApp/master/js/dev3.js"); //dev test script
|
||||
//_helper.injectJavaScript("https://cdn.rawgit.com/Jiiks/BetterDiscordApp/master/js/autocomplete.js"); //Autocomplete
|
||||
}, 5000);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
_helper.log("Finish loading");
|
||||
_helper.log("v" + _version + " initialized.");
|
||||
|
||||
_helper.injectStylesheet("https://raw.githubusercontent.com/Jiiks/BetterDiscordApp/master/css/main.css");
|
||||
_emoteModule = new _emoteModule.EmoteModule(_helper);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,27 @@
|
|||
* https://github.com/Jiiks/BetterDiscordApp
|
||||
*/
|
||||
|
||||
var config = require("../config.json");
|
||||
|
||||
var _helper;
|
||||
|
||||
function EmoteModule(helper) {
|
||||
_helper = helper;
|
||||
_helper.log("Emotes Initialized");
|
||||
|
||||
_helper.execJs('var twitchEmoteUrlStart = "' + config.EmoteModule.Twitch.EmoteUrlStart + '", twitchEmoteUrlEnd = "' + config.EmoteModule.Twitch.EmoteUrlEnd + '";');
|
||||
_helper.execJs('var ffzEmoteUrlStart = "' + config.EmoteModule.FrankerFaceZ.EmoteUrlStart + '", ffzEmoteUrlEnd = "' + config.EmoteModule.FrankerFaceZ.EmoteUrlEnd + '";');
|
||||
_helper.execJs('var bttvEmoteUrlStart = "' + config.EmoteModule.BetterTTV.EmoteUrlStart + '", bttvEmoteUrlEnd = "' + config.EmoteModule.BetterTTV.EmoteUrlEnd + '";');
|
||||
|
||||
_helper.download(config.Urls.Cdn + "master/" + config.EmoteModule.Twitch.EmoteData, function(twitchEmoteData) {
|
||||
_helper.execJs("var emotesTwitch = " + twitchEmoteData + ";");
|
||||
|
||||
_helper.download(config.Urls.Cdn + "master/" + config.EmoteModule.FrankerFaceZ.EmoteData, function(ffzEmoteData) {
|
||||
_helper.execJs("var emotesFfz = " + ffzEmoteData + ";");
|
||||
_helper.injectJavaScript(config.Cdn + config.js.EmoteModule);
|
||||
_helper.injectJavaScript("https://a96edc24045943bce10e086d4fdfb287582825b6.googledrive.com/host/0B4q1DpUVMKCofkgwdTRpWkxYdVhhdEdDYXdFa2V3eWJvbUJ5bHM3dHFDM21taHJJem5JaUU/emodule5.js");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.EmoteModule = EmoteModule;
|
Loading…
Reference in New Issue