From 8df74317434e56f0ab51db8716dc666f0abc2e46 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Wed, 2 Nov 2016 07:38:32 +0200 Subject: [PATCH] Skeletons --- v2/dist/js/main.js | 91 +++++++++++++++++++++++------ v2/lib/core.js | 2 +- v2/src/js/core.js | 10 ++-- v2/src/js/event.js | 20 ++++--- v2/src/js/modules/modules.js | 8 ++- v2/src/js/modules/observermodule.js | 34 +++++++++++ 6 files changed, 132 insertions(+), 33 deletions(-) create mode 100644 v2/src/js/modules/observermodule.js diff --git a/v2/dist/js/main.js b/v2/dist/js/main.js index a9f5b8e8..1168491a 100644 --- a/v2/dist/js/main.js +++ b/v2/dist/js/main.js @@ -3,7 +3,7 @@ "use strict"; var electron = require("electron"); - var src_js_modules_modules, src_js_utils, src_js_api, src_js_event, src_js_core; + 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++) { @@ -28,10 +28,32 @@ throw new TypeError('Cannot call a class as a function'); } } - src_js_modules_modules = function () { - var modules = {}; - return modules; + 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); @@ -44,39 +66,72 @@ }; return new Api(); }(); - src_js_event = function () { - var eventEmitter = new require('events').EventEmitter; - var event = function () { - function event() { - _classCallCheck(this, event); + src_js_plugin = function () { + var Plugin = function () { + function Plugin(args) { + _classCallCheck(this, Plugin); + this.info = args; } - _createClass(event, [ + _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) { - eventEmitter.on(eventName, callback); + this.eventEmitter.on(eventName, callback); } }, { key: 'emit', value: function emit() { - return 'Not allowed'; + var _eventEmitter; + (_eventEmitter = this.eventEmitter).emit.apply(_eventEmitter, arguments); } } ]); - return event; + return Event; }(); - return new 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; - this.event = event; - this.eventEmitter = event.eventEmitter; } _createClass(Core, [ { @@ -103,8 +158,8 @@ window.$B = function (s) { return $('[data-bd=' + s); }; - var BD = new Core(); + window.BD = new Core(); BD.init(); - }(src_js_modules_modules, src_js_utils, src_js_api, src_js_event); + }(src_js_modules_modules, src_js_utils, src_js_api, src_js_plugin, src_js_event); }()); \ No newline at end of file diff --git a/v2/lib/core.js b/v2/lib/core.js index aa24aad3..38851dc9 100644 --- a/v2/lib/core.js +++ b/v2/lib/core.js @@ -38,7 +38,7 @@ const _resources = { "jQuery": { "path": "vendor", "filename": "jquery-2.2.4.min.js", - "var": "window.BD.$ = window.BD.jQuery" + "var": "window.$ = window.jQuery" } }; diff --git a/v2/src/js/core.js b/v2/src/js/core.js index 55ab4030..e28f6c62 100644 --- a/v2/src/js/core.js +++ b/v2/src/js/core.js @@ -13,17 +13,19 @@ 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; - this.event = event; - this.eventEmitter = event.eventEmitter; } init() { @@ -42,7 +44,7 @@ define([ window.$B = s => { return $(`[data-bd=${s}`); }; - const BD = new Core(); + window.BD = new Core(); BD.init(); - + }); \ No newline at end of file diff --git a/v2/src/js/event.js b/v2/src/js/event.js index c67a6af7..2daa5313 100644 --- a/v2/src/js/event.js +++ b/v2/src/js/event.js @@ -11,19 +11,23 @@ define(() => { - const eventEmitter = new require('events').EventEmitter; - - class event { + const EventEmitter = new require('events').EventEmitter; + + class Event { - on(eventName, callback) { - eventEmitter.on(eventName, callback); + constructor() { + this.eventEmitter = new EventEmitter; } - emit() { - return "Not allowed"; + on(eventName, callback) { + this.eventEmitter.on(eventName, callback); + } + + emit(...args) { + this.eventEmitter.emit(...args); } } - return new event(); + return new Event(); }); \ No newline at end of file diff --git a/v2/src/js/modules/modules.js b/v2/src/js/modules/modules.js index abaadad3..6fab4b23 100644 --- a/v2/src/js/modules/modules.js +++ b/v2/src/js/modules/modules.js @@ -8,9 +8,13 @@ * License: MIT */ -define([], () => { +define([ + "./observermodule" +], (observerModule) => { - var modules = {}; + const modules = { + observerModule: observerModule + }; return modules; }); \ No newline at end of file diff --git a/v2/src/js/modules/observermodule.js b/v2/src/js/modules/observermodule.js new file mode 100644 index 00000000..bec7217b --- /dev/null +++ b/v2/src/js/modules/observermodule.js @@ -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(); +}); \ No newline at end of file