This commit is contained in:
Jiiks 2015-08-29 22:20:11 +03:00
parent e5dcf7b500
commit bf89eb3eb4
4 changed files with 113 additions and 27 deletions

View File

@ -2,7 +2,7 @@
* Version: 1.2
* Author: Jiiks | http://jiiks.net
* Date: 27/08/2015 - 16:36
* Last Update: 29/08/2015 - 22:00
* Last Update: 29/08/2015 - 22:19
* https://github.com/Jiiks/BetterDiscordApp
*/
@ -63,16 +63,16 @@ Core.prototype.init = function() {
this.initSettings();
this.initObserver();
//Settings button
$(".guilds li:first-child").after($("<li/>", {id:"tc-settings-li"}).append($("<div/>", { class: "guild-inner" }).append($("<a/>").append($("<div/>", { class: "avatar-small", id: "tc-settings-button", style: 'background-image:url("https://a96edc24045943bce10e086d4fdfb287582825b6.googledrive.com/host/0B4q1DpUVMKCofkgwdTRpWkxYdVhhdEdDYXdFa2V3eWJvbUJ5bHM3dHFDM21taHJJem5JaUU/settings_icon.png")' })))));
settingsPanel = new SettingsPanel();
settingsPanel.init();
quickEmoteMenu.init(false);
$("#tc-settings-button").on("click", function(e) { settingsPanel.show(); });
$(".guilds-wrapper").ready(function() {
//Settings button
$(".guilds li:first-child").after($("<li/>", {id:"tc-settings-li"}).append($("<div/>", { class: "guild-inner" }).append($("<a/>").append($("<div/>", { class: "avatar-small", id: "tc-settings-button", style: 'background-image:url("https://a96edc24045943bce10e086d4fdfb287582825b6.googledrive.com/host/0B4q1DpUVMKCofkgwdTRpWkxYdVhhdEdDYXdFa2V3eWJvbUJ5bHM3dHFDM21taHJJem5JaUU/settings_icon.png")' })))));
settingsPanel = new SettingsPanel();
settingsPanel.init();
quickEmoteMenu.init(false);
$("#tc-settings-button").on("click", function(e) { settingsPanel.show(); });
});
}
Core.prototype.initSettings = function() {

View File

@ -2,7 +2,7 @@
* Version: 1.2
* Author: Jiiks | http://jiiks.net
* Date: 27/08/2015 - 16:36
* Last Update: 29/08/2015 - 22:00
* Last Update: 29/08/2015 - 22:19
* https://github.com/Jiiks/BetterDiscordApp
*/
@ -63,16 +63,16 @@ Core.prototype.init = function() {
this.initSettings();
this.initObserver();
//Settings button
$(".guilds li:first-child").after($("<li/>", {id:"tc-settings-li"}).append($("<div/>", { class: "guild-inner" }).append($("<a/>").append($("<div/>", { class: "avatar-small", id: "tc-settings-button", style: 'background-image:url("https://a96edc24045943bce10e086d4fdfb287582825b6.googledrive.com/host/0B4q1DpUVMKCofkgwdTRpWkxYdVhhdEdDYXdFa2V3eWJvbUJ5bHM3dHFDM21taHJJem5JaUU/settings_icon.png")' })))));
settingsPanel = new SettingsPanel();
settingsPanel.init();
quickEmoteMenu.init(false);
$("#tc-settings-button").on("click", function(e) { settingsPanel.show(); });
$(".guilds-wrapper").ready(function() {
//Settings button
$(".guilds li:first-child").after($("<li/>", {id:"tc-settings-li"}).append($("<div/>", { class: "guild-inner" }).append($("<a/>").append($("<div/>", { class: "avatar-small", id: "tc-settings-button", style: 'background-image:url("https://a96edc24045943bce10e086d4fdfb287582825b6.googledrive.com/host/0B4q1DpUVMKCofkgwdTRpWkxYdVhhdEdDYXdFa2V3eWJvbUJ5bHM3dHFDM21taHJJem5JaUU/settings_icon.png")' })))));
settingsPanel = new SettingsPanel();
settingsPanel.init();
quickEmoteMenu.init(false);
$("#tc-settings-button").on("click", function(e) { settingsPanel.show(); });
});
}
Core.prototype.initSettings = function() {

View File

@ -8,13 +8,14 @@
var _config = require("./config.json");
var _utils = require("./utils");
var version;
var _version;
var _mainWindow;
var _updater;
var _hash;
function BetterDiscord(mainWindow) {
_mainWindow = mainWindow;
version = _config.Core.Version;
_version = _config.Core.Version;
_utils = new _utils.Utils(mainWindow);
}
@ -24,13 +25,33 @@ BetterDiscord.prototype.getUtils = function() {
BetterDiscord.prototype.init = function() {
var self = this;
//Get latest commit hash
this.getUtils().getHash(function(hash) {
_hash = hash;
self.getUtils().log("Latest Hash: " + _hash);
//Get updater
self.getUtils().download("raw.githubusercontent.com", "/Jiiks/BetterDiscordApp/"+hash+"/updater.json", function(updater) {
_updater = JSON.parse(updater);
self.getUtils().log("Latest Version: " + _updater.LatestVersion);
self.getUtils().log("CDN: " + _updater.CDN);
self.start();
});
});
return;
console.log("BetterDiscord v" + version + " Initialized");
self.getUtils().getWebContents().on('did-finish-load', function() {
});
self.getUtils().getWebContents().on('dom-ready', function() {
self.getUtils().execJs('var version = "0.1.2";');
self.getUtils().injectJavaScript("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"); //jquery
@ -42,10 +63,52 @@ BetterDiscord.prototype.init = function() {
setTimeout(function() {
self.getUtils().injectJavaScript("//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js");
self.getUtils().injectJavaScript("https://rawgit.com/Jiiks/BetterDiscordApp/806eeabd2473d7b65746bc67a4c1e2cf77a55bd6/js/main.min.js");
// setTimeout(funct)
// self.getUtils().execJs("var mainCore = new Core(); mainCore.init();");
}, 2000);
});
}
BetterDiscord.prototype.start = function() {
var self = this;
this.getUtils().log(" v" + _version + " Initialized");
if(_updater.LatestVersion > _version) {
this.getUtils().log("Update available!");
}
//Event handlers
self.getUtils().getWebContents().on('did-finish-load', function() {
});
self.getUtils().getWebContents().on('dom-ready', function() {
if(_updater.LatestVersion > _version) self.getUtils().execJs('alert("An update for BetterDiscord is available(v'+ _updater.LatestVersion +')! Run the installer or download the latest version from GitHub!")');
//Version var
self.getUtils().execJs('var version = "'+_version+'"');
//Load jquery
self.getUtils().injectJavaScript("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js");
//CSS
self.getUtils().execJs('function injectMainCss() { $(\'head\').append( \'<link rel=\"stylesheet\" type=\"text\/css\" href=\"\/\/'+_updater.CDN+'\/Jiiks\/BetterDiscordApp\/'+_hash+'\/css\/main.min.css\">\' ) }');
//self.getUtils().execJs('function injectCss() { $(\'head\').append(\'<link rel=\"stylesheet\" type=\"text\/css\" href=\"https:\/\/rawgit.com\/Jiiks\/BetterDiscordApp\/master\/css\/main.min.css\">\') }');
self.getUtils().execJs('var deferCount = 0; function defer() { if(window.jQuery) { injectMainCss() } else { setTimeout( function() { if(deferCount < 100) { deferCount++; defer(); } else { alert("BetterDiscord failed to load :( try restarting Discord. code:0x01"); } }, 100 ); } } deferCount = 0; defer();');
self.getUtils().injectJavaScript("//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js", true);
self.getUtils().injectJavaScript("//" + _updater.CDN + "/Jiiks/BetterDiscordApp/"+_hash+"/js/main.js", true);
//Start BDA
self.getUtils().execJs("var startBda = function() { var mainCore = new Core(); mainCore.init(); }");
self.getUtils().execJs("function startDefer() { if(window.Core && window.jQuery && $.cookie){ startBda(); } else { setTimeout(function() { startDefer(); }, 100) } } startDefer(); ")
});
}
exports.BetterDiscord = BetterDiscord;

View File

@ -6,7 +6,7 @@
* https://github.com/Jiiks/BetterDiscordApp
*/
var http = require('https');
var https = require('https');
var _mainWindow;
function Utils(mainWindow) {
@ -19,8 +19,15 @@ function getMainWindow() {
}
//Download using http
Utils.prototype.download = function(url, callback) {
https.get(url, function(res) {
Utils.prototype.download = function(host, path, callback) {
var options = {
host: host,
path: path,
headers: {'user-agent': 'Mozilla/5.0'},
}
https.get(options, function(res) {
var data = "";
res.on('data', function(chunk) {
data += chunk;
@ -33,13 +40,19 @@ Utils.prototype.download = function(url, callback) {
});
}
Utils.prototype.getHash = function(callback) {
this.download("api.github.com", "/repos/Jiiks/BetterDiscordApp/commits/master", function(data) {
callback(JSON.parse(data).sha);
});
}
//Get Webcontents
Utils.prototype.getWebContents = function() {
return getMainWindow().webContents;
}
//Js logger
Utils.prototype.log = function(message, type) {
Utils.prototype.jsLog = function(message, type) {
switch(type) {
case "log":
@ -54,6 +67,11 @@ Utils.prototype.log = function(message, type) {
}
}
//Logger
Utils.prototype.log = function(message) {
console.log("BetterDiscrod: " + message);
}
//Execute javascript
Utils.prototype.execJs = function(js) {
this.getWebContents().executeJavaScript(js);
@ -77,8 +95,13 @@ Utils.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+'" })();')
}
Utils.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+'"; })();');
Utils.prototype.injectJavaScript = function(url, jquery) {
if(!jquery) {
this.execJs('(function() { var script = document.createElement("script"); script.type = "text/javascript"; document.getElementsByTagName("body")[0].appendChild(script); script.src = "' + url + '"; })();');
}else {
this.execJs(' (function() { function injectJs() { var script = document.createElement("script"); script.type = "text/javascript"; document.getElementsByTagName("body")[0].appendChild(script); script.src = "' + url + '"; } function jqDefer() { if(window.jQuery) { injectJs(); }else{ setTimeout(function() { jqDefer(); }, 100) } } jqDefer(); })(); ');
}
}
exports.Utils = Utils;