From 4bceb059d996dd24f2a321394e064644ec3473fc Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 1 Mar 2013 23:16:29 +0100 Subject: [PATCH] Add AddCallback API. #932 @milkytiptoe --- 4chan_x.user.js | 8 ++++++++ src/main.coffee | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/4chan_x.user.js b/4chan_x.user.js index 6f70bf6d0..291b68ce2 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -7291,6 +7291,7 @@ initFeature('Index Navigation', Nav); initFeature('Keybinds', Keybinds); console.timeEnd('All initializations'); + $.on(d, 'AddCallback', Main.addCallback); $.on(d, '4chanMainInit', Main.initStyle); return $.ready(Main.initReady); }, @@ -7416,6 +7417,13 @@ return Main.handleErrors(errors); } }, + addCallback: function(e) { + var Klass, obj; + obj = e.detail; + Klass = obj.type === 'Post' ? Post : Thread; + obj.callback.isAddon = true; + return Klass.prototype.callbacks.push(obj.callback); + }, handleErrors: function(errors) { var div, error, logs, _i, _len; if (!('length' in errors)) { diff --git a/src/main.coffee b/src/main.coffee index a1f16fff2..c0f8ee3eb 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -357,6 +357,7 @@ Main = initFeature 'Keybinds', Keybinds console.timeEnd 'All initializations' + $.on d, 'AddCallback', Main.addCallback $.on d, '4chanMainInit', Main.initStyle $.ready Main.initReady @@ -450,6 +451,15 @@ Main = # console.profileEnd callback.name Main.handleErrors errors if errors + addCallback: (e) -> + obj = e.detail + Klass = if obj.type is 'Post' + Post + else + Thread + obj.callback.isAddon = true + Klass::callbacks.push obj.callback + handleErrors: (errors) -> unless 'length' of errors error = errors