kfahy / slack-disable-wysiwyg-bookmarklet

Disables the WYSIWYG editor in Slack.
MIT License
824 stars 23 forks source link

Does not work out of the box for nativifier #23

Open keymon opened 4 years ago

keymon commented 4 years ago

I am using this with nativifier: https://github.com/jiahaog/nativefier/blob/master/docs/api.md#inject but it runs "too" early and slackDebug is not yet ready. The app is created with:

nativefier "https://app.slack.com" -m --name slack --disable-context-menu --disable-dev-tools  --internal-urls '(.*\.slack\.com)|(slack\.com)|(confluent\.okta\.com)' --inject /tmp/no_wysiwyg.js  

to solve it, I added a timeout to call the function later after 10s. Not elegant but works. I don't know too much about js to make it better.

It looks like this

(() => {
    setTimeout( function(){
        const workspaceIds = slackDebug.clientStore.workspaces.getAllWorkspaces();
        for (const workspaceId of workspaceIds) {
            const { redux } = slackDebug[workspaceId];
            const {
                wysiwyg_composer,
                wysiwyg_composer_ios,
                wysiwyg_composer_webapp,
                ...payload
            } = redux.getState().experiments;
            redux.dispatch({
                type: '[19] Bulk add experiment assignments to redux',
                payload
            });
        }
    }, 10000);
})();