Merge pull request #3 from Jiiks/master

Updating to latest
This commit is contained in:
Alex 2016-11-02 21:28:33 +00:00 committed by GitHub
commit 66c24f246a
21 changed files with 740 additions and 4 deletions

4
.gitignore vendored
View File

@ -12,4 +12,6 @@ node_modules
/*.jiiks
Installers/dotNet/bin/
Installers/dotNet/packages/
Installers/dotNet/dlls/
Installers/dotNet/dlls/
v2/dist/vendor/
v2/lib/static.js

File diff suppressed because one or more lines are too long

View File

@ -172,6 +172,7 @@
"Dedede",
"Ohok",
"SRS!",
"Isis"
"Isis",
"Okie"
]
}

View File

@ -159,7 +159,7 @@ EmoteModule.prototype.injectEmote = function(node) {
}
if (typeof emotesBTTV !== 'undefined' && settingsCookie["bda-es-2"]) {
if(emotesBTTV.hasOwnProperty(sw) && sw.length >= 4) {
if(emotesBTTV.hasOwnProperty(sw) && sw.length >= 3) {
if(text != null) { contents.splice(i + splice++, 0, document.createTextNode(text)); text = null;}
var url = emotesBTTV[sw];
contents.splice(i + splice++, 0, self.createEmoteElement(sw, url, emoteClass));

5
v2/.babelrc Normal file
View File

@ -0,0 +1,5 @@
{
plugins: ["transform-remove-strict-mode"],
presets: ["es2015"],
sourceMap: false
}

99
v2/Gruntfile.js Normal file
View File

@ -0,0 +1,99 @@
module.exports = grunt => {
'use strict';
require('load-grunt-tasks')(grunt);
grunt.initConfig({
requirejs: {
compileProject: {
options: {
include: ['src/js/core'],
out: 'intermediate/requirejs.js',
optimize: 'none',
paths: {
'events': 'empty:',
'electron': 'empty:'
}
}
}
},
babel: {
dist: {
files: [{
src: ['intermediate/requirejs.js'],
dest: 'intermediate/babel.js'
}]
}
},
replace: {
dist: {
options: {
patterns: [{
match: /\\n +/g,
replacement: ''
},{
match: / +/g,
replacement: ' '
},{
match: /\/*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g,
replacement: ''
}]
},
files: [{
expand: true, src: ['intermediate/babel.js'], dest: ''
}]
},
nongreedy: {
options: {
patterns: [{
match: /\\n +/g,
replacement: ''
},{
match: / +/g,
replacement: ' '
},{
match: /\/\*(.|[\r\n])*?\*\//g,
replacement: ''
}]
},
files: [{
expand: true, src: ['intermediate/babel.js'], dest: ''
}]
}
},
amdclean: {
options: {
wrap: {
start: '(function() {\n\n "use strict";\n\n var electron = require("electron");\n',
end: '\n\n}());'
},
escodegen: {
format: {
indent: {
style: ' ',
base: 1
}
}
},
aggressiveOptimizations: true,
transformAMDChecks: false
},
dist: {
src: 'intermediate/babel.js',
dest: 'dist/js/main.js'
}
},
clean: [
'intermediate'
]
});
grunt.registerTask("js", [ "requirejs", "babel", "replace", "amdclean", "clean" ]);
grunt.registerTask("js-noclean", [ "requirejs", "babel", "replace", "amdclean" ]);
grunt.registerTask("fastjs", ["requirejs", "babel", "replace:nongreedy", "amdclean", "clean" ]);
grunt.registerTask("fastjs-noclean", ["requirejs", "babel", "replace:nongreedy", "amdclean" ]);
};

1
v2/README.MD Normal file
View File

@ -0,0 +1 @@
v2 preview for external testers

165
v2/dist/js/main.js vendored Normal file
View File

@ -0,0 +1,165 @@
(function() {
"use strict";
var electron = require("electron");
var src_js_modules_observermodule, src_js_modules_modules, src_js_utils, src_js_api, src_js_plugin, src_js_event, src_js_core;
var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ('value' in descriptor)
descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps)
defineProperties(Constructor.prototype, protoProps);
if (staticProps)
defineProperties(Constructor, staticProps);
return Constructor;
};
}();
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError('Cannot call a class as a function');
}
}
src_js_modules_observermodule = function () {
var Observer = function () {
function Observer() {
_classCallCheck(this, Observer);
this.mutationObserver = new MutationObserver(this.observe);
this.mutationObserver.observe(document, {
childList: true,
subtree: true
});
}
_createClass(Observer, [{
key: 'observe',
value: function observe(mutations) {
mutations.forEach(function (mutation) {
BD.event.emit('raw-mutation', mutation);
});
}
}]);
return Observer;
}();
return new Observer();
}();
src_js_modules_modules = function (observerModule) {
var modules = { observerModule: observerModule };
return modules;
}(src_js_modules_observermodule);
src_js_utils = function () {
var Utils = function Utils() {
_classCallCheck(this, Utils);
};
return new Utils();
}();
src_js_api = function () {
var Api = function Api() {
_classCallCheck(this, Api);
};
return new Api();
}();
src_js_plugin = function () {
var Plugin = function () {
function Plugin(args) {
_classCallCheck(this, Plugin);
this.info = args;
}
_createClass(Plugin, [
{
key: 'author',
get: function get() {
return this.info.author;
}
},
{
key: 'name',
get: function get() {
return this.info.name;
}
},
{
key: 'version',
get: function get() {
return this.info.version;
}
}
]);
return Plugin;
}();
return Plugin;
}();
src_js_event = function () {
var EventEmitter = events.EventEmitter;
var Event = function () {
function Event() {
_classCallCheck(this, Event);
this.eventEmitter = new EventEmitter();
}
_createClass(Event, [
{
key: 'on',
value: function on(eventName, callback) {
this.eventEmitter.on(eventName, callback);
}
},
{
key: 'emit',
value: function emit() {
var _eventEmitter;
(_eventEmitter = this.eventEmitter).emit.apply(_eventEmitter, arguments);
}
}
]);
return Event;
}();
return new Event();
}();
src_js_core = function (modules, utils, api, plugin, event) {
var Core = function () {
function Core(args) {
_classCallCheck(this, Core);
console.log(event);
this.event = event;
this.modules = modules;
this.beta = true;
this.alpha = true;
this.plugin = plugin;
}
_createClass(Core, [
{
key: 'init',
value: function init() {
console.log('Initialized');
}
},
{
key: '__version',
get: function get() {
return '2.0.0';
}
},
{
key: '__versionString',
get: function get() {
return '' + this.__version + (this.alpha ? 'A' : this.beta ? 'B' : '');
}
}
]);
return Core;
}();
window.$B = function (s) {
return $('[data-bd=' + s);
};
window.BD = new Core();
BD.init();
}(src_js_modules_modules, src_js_utils, src_js_api, src_js_plugin, src_js_event);
}());

11
v2/lib/config.json Normal file
View File

@ -0,0 +1,11 @@
{
"core": {
"version": "0.3.0"
},
"Core": {
"Version": "0.3.0"
},
"cfg": {
}
}

108
v2/lib/core.js Normal file
View File

@ -0,0 +1,108 @@
/* BetterDiscordApp Core
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
'use strict';
const
_fs = require('fs'),
_config = require('./config.json'),
{ _utils } = require('./utils'),
{ _logger } = require('./utils'),
{ EOL } = require('os'),
_os = require('os');
const _startDate = new Date();
var _cfg;
// Default configs if for some reason we don't receive config params
const _defaults = {
installPath: (_os.platform() === 'win32' ? process.env.APPDATA : _os.platform() === 'darwin' ? `${process.env.HOME}/Library/Preferences`: `/var/local`) + '/BetterDiscord/lib/',
dataPath: (_os.platform() === 'win32' ? process.env.APPDATA : _os.platform() === 'darwin' ? `${process.env.HOME}/Library/Preferences`: `/var/local`) + '/BetterDiscord/data/',
emotesEnabled: true
};
const _resources = {
"mainjs": {
"path": "js",
"filename": "main.js",
"var": "window.BetterDiscord"
},
"jQuery": {
"path": "vendor",
"filename": "jquery-2.2.4.min.js",
"var": "window.$ = window.jQuery"
}
};
var _self;
class Core {
constructor(args) {
_self = this;
this.continue = true;
_logger.log(`v${this.__version} Loading - OS: ${_os.platform()}`);
this.initConfig(args.cfg);
}
initConfig(args) {
_cfg = _config.cfg;
_cfg.installPath = args.installPath || _defaults.installPath;
_cfg.dataPath = args.dataPath || _defaults.dataPath;
_cfg.emotesEnabled = args.emotesEnabled || _defaults.emotesEnabled;
}
hook(mainWindow) {
if(mainWindow === undefined) {
this.exit("mainWindow is undefined!");
return;
}
this.mainWindow = mainWindow;
this.hookEvent('dom-ready', this.domReady);
}
hookEvent(event, callback) {
if(!this.continue) return;
try {
_logger.log(`Hooking ${event}`);
this.mainWindow.webContents.on(event, callback);
}catch(err) {
this.exit(`Failed to hook event ${event}. Reason: ${err}`);
}
}
domReady() {
for(var key in _resources) {
var resource = _resources[key];
_utils.requireJs(`${_cfg.installPath}/${resource.path}/${resource.filename}`, resource.var, _self.mainWindow);
}
_self.pluginLoader();
}
pluginLoader() {
}
exit(reason, severity) {
this.continue = false;
// TODO show an actual error dialog for user
_logger.log(`Quitting. Reason: ${reason}`, severity || 2);
_logger.save();
}
get __version() {
return _config.core.version;
}
}
exports.BetterDiscord = Core;

1
v2/lib/main.js Normal file
View File

@ -0,0 +1 @@
module.exports = require('./core');

2
v2/lib/test.js Normal file
View File

@ -0,0 +1,2 @@
var BD = require('./main');
var _bd = new BD.BetterDiscord({ cfg: { } });

105
v2/lib/utils.js Normal file
View File

@ -0,0 +1,105 @@
/* BetterDiscordApp Utilities
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
'use strict';
class Utils {
//Get the latest commit hash from github
getHash(callback) {
this.download("api.github.com", "/repos/Jiiks/BetterDiscordApp/commits/master", data => {
//TODO use the new soon to be implemented tryparse
callback(JSON.parse(data).sha);
});
}
download(host, path, callback) {
_logger.log(`Downloading Resource: ${host}${path}`);
var options = {
host: host,
path: path,
headers: this.headers
};
_https.get(options, res => {
var data = "";
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
callback(data);
});
}).on('error', () => {
//TODO error logging
callback(null);
});
}
requireJs(file, varstring, _window) {
_logger.log(`Injecting file: ${file}`);
_window.webContents.executeJavaScript(`${varstring} = require("${file}");`);
}
//Returns a datestring: [DD/MM/YYYY - HH:MM:SS]
get dateString() {
var d = new Date();
return `${("00" + (d.getDate())).slice(-2)}/` +
`${("00" + d.getMonth()).slice(-2)}/` +
`${d.getFullYear()} - ` +
`${("00" + d.getHours()).slice(-2)}:` +
`${("00" + d.getMinutes()).slice(-2)}:` +
`${("00" + d.getSeconds()).slice(-2)}`;
}
get headers() {
return { 'user-agent': 'Mozilla/5.0' };
}
}
class Logger {
constructor() {
this.logs = "";
}
log(msg, severity) {
var l = `[BD|${this.severity(severity)}][${_utils.dateString}] >>> ${msg}`;
console.log(l);
this.logs += `${l}${EOL}`;
}
save() {
try {
_fs.writeFileSync('logs.log', this.logs);
}catch(err) {
this.log("Failed to save logs! " + err, 2);
}
}
severity(severity) {
return {
0: "INF",
1: "WRN",
2: "ERR"
}[severity||0];
}
}
const _utils = new Utils(),
_logger = new Logger(),
_fs = require('fs'),
{EOL} = require('os'),
_https = require('https');
exports._utils = _utils;
exports._logger = _logger;

23
v2/package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "betterdiscord",
"description": "Discord enhancement project. v2 preview",
"version": "0.3.0",
"homepage": "https://github.com/Jiiks/BetterDiscordApp",
"license": "MIT",
"main": "lib/main.js",
"devDependencies": {
"grunt": "^0.4.5",
"load-grunt-tasks": "^3.5.0",
"grunt-requirejs": "^0.4.2",
"grunt-amdclean": "^0.1.2",
"grunt-babel": "^6.0.0",
"babel-preset-es2015": "^6.9.0",
"babel-plugin-transform-remove-strict-mode": "^0.0.2",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-uglify": "^1.0.1",
"grunt-contrib-cssmin": "^1.0.1",
"grunt-contrib-clean": "^1.0.0",
"grunt-replace": "^1.0.1"
}
}

20
v2/src/js/api.js Normal file
View File

@ -0,0 +1,20 @@
/* BetterDiscordApp Client Api
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
define(() => {
class Api {
}
return new Api();
});

50
v2/src/js/core.js Normal file
View File

@ -0,0 +1,50 @@
/* BetterDiscordApp Client Core
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
define([
"./modules/modules",
"./utils",
"./api",
"./plugin",
"./event"
], (modules, utils, api, plugin, event) => {
class Core {
constructor(args) {
console.log(event);
this.event = event;
this.modules = modules;
this.beta = true;
this.alpha = true;
this.plugin = plugin;
}
init() {
console.log("Initialized");
}
get __version() {
return "2.0.0";
}
get __versionString() {
return `${this.__version}${this.alpha ? "A" : this.beta ? "B" : ""}`;
}
}
window.$B = s => { return $(`[data-bd=${s}`); };
window.BD = new Core();
BD.init();
});

33
v2/src/js/event.js Normal file
View File

@ -0,0 +1,33 @@
/* BetterDiscordApp Event emitter
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
define(() => {
const EventEmitter = new require('events').EventEmitter;
class Event {
constructor() {
this.eventEmitter = new EventEmitter;
}
on(eventName, callback) {
this.eventEmitter.on(eventName, callback);
}
emit(...args) {
this.eventEmitter.emit(...args);
}
}
return new Event();
});

View File

@ -0,0 +1,20 @@
/* BetterDiscordApp Client Module Defines
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
define([
"./observermodule"
], (observerModule) => {
const modules = {
observerModule: observerModule
};
return modules;
});

View File

@ -0,0 +1,34 @@
/* BetterDiscordApp Client Observer
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
define([], () => {
class Observer {
constructor() {
this.mutationObserver = new MutationObserver(this.observe);
this.mutationObserver.observe(document, {
childList: true,
subtree: true
});
}
observe(mutations) {
mutations.forEach(mutation => {
BD.event.emit("raw-mutation", mutation);
});
}
}
return new Observer();
});

36
v2/src/js/plugin.js Normal file
View File

@ -0,0 +1,36 @@
/* BetterDiscordApp Plugin base class
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
define(() => {
class Plugin {
constructor(args) {
this.info = args;
}
get author() {
return this.info.author;
}
get name() {
return this.info.name;
}
get version() {
return this.info.version;
}
}
return Plugin;
});

20
v2/src/js/utils.js Normal file
View File

@ -0,0 +1,20 @@
/* BetterDiscordApp Client Utilities
* Version: 2:1.0
* Author: Jiiks | https://jiiks.net
* Date: 31/10/2016
* Last Update: 31/10/2016
* Github: https://github.com/Jiiks/BetterDiscordApp
* Git: https://github.com/Jiiks/BetterDiscordApp.git
* License: MIT
*/
define(() => {
class Utils {
}
return new Utils();
});