From 94b757e4646970ad5e6da0370431257c8dd1b4d8 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Tue, 25 Aug 2015 15:43:04 +0300 Subject: [PATCH] Many things too many things to rember --- betterdiscordapp/helper.js | 20 ++++++++++++++++++-- betterdiscordapp/index.js | 19 +++++++++++++++++-- betterdiscordapp/modules/EmoteModule.js | 16 ++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/betterdiscordapp/helper.js b/betterdiscordapp/helper.js index 12f90aa9..1ded11fb 100644 --- a/betterdiscordapp/helper.js +++ b/betterdiscordapp/helper.js @@ -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; \ No newline at end of file diff --git a/betterdiscordapp/index.js b/betterdiscordapp/index.js index 5d32c32d..553faf50 100644 --- a/betterdiscordapp/index.js +++ b/betterdiscordapp/index.js @@ -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); + } diff --git a/betterdiscordapp/modules/EmoteModule.js b/betterdiscordapp/modules/EmoteModule.js index 925567f3..1511a754 100644 --- a/betterdiscordapp/modules/EmoteModule.js +++ b/betterdiscordapp/modules/EmoteModule.js @@ -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; \ No newline at end of file