diff --git a/extension/data/modules/modbar.js b/extension/data/modules/modbar.js index 7517e1d84..065559e52 100644 --- a/extension/data/modules/modbar.js +++ b/extension/data/modules/modbar.js @@ -5,6 +5,17 @@ import * as TBHelpers from '../tbhelpers.js'; import * as TBCore from '../tbcore.js'; import * as TBApi from '../tbapi.js'; +// Hold onto the modbarExists resolver so we can call it when the time is right +let resolveModbarExists = null; + +/** + * A promise which resolves when the modbar is added to the page. + * @constant {Promise} + */ +export const modbarExists = new Promise(resolve => { + resolveModbarExists = resolve; +}); + export default new Module({ name: 'Modbar', id: 'Modbar', @@ -306,6 +317,9 @@ export default new Module({ toggleMenuBar(modbarHidden); + // modbar was added to the DOM, let everyone know so they can add buttons and stuff + resolveModbarExists(); + // moderated subreddits button. if (enableModSubs) { TBCore.getModSubs().then(async () => { diff --git a/extension/data/modules/personalnotes.js b/extension/data/modules/personalnotes.js index c61da3381..29457d577 100644 --- a/extension/data/modules/personalnotes.js +++ b/extension/data/modules/personalnotes.js @@ -4,6 +4,8 @@ import * as TBui from '../tbui.js'; import * as TBHelpers from '../tbhelpers.js'; import * as TBCore from '../tbcore.js'; +import {modbarExists} from './modbar.js'; + export default new Module({ name: 'Personal Notes', id: 'PNotes', @@ -124,8 +126,10 @@ export default new Module({ }); }; - // add the button to the modbar - $body.find('#tb-toolbarshortcuts').before(' Personal Notes'); + // add the button to the modbar once the modbar is available + modbarExists.then(() => { + $body.find('#tb-toolbarshortcuts').before(' Personal Notes'); + }); // Since we have a button we can click on it! $body.on('click', '#tb-personal-notes-button', async () => {