kfahy / slack-disable-wysiwyg-bookmarklet

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

Add a script to patch Mac desktop Slack.app #19

Closed dbalatero closed 4 years ago

dbalatero commented 4 years ago

Closes #15

kfahy commented 4 years ago

Woohoo 🎉 🎉 I'll go ahead and add a link to your script in the README. Thanks again!

nathairtras commented 4 years ago

Running the patch didn't seem to fix it on its own.

Still converting markdown and showing the wysiwyg button.

However if I then open with the developer menu, paste the code in the console, it does work. If I quit and re-open Slack, still patched.

Is this the expected behavior? Or something weird wrt my system?

macOS 10.14.6 Slack 4.1.2

dbalatero commented 4 years ago

@nathairtras

What does the patch output?

If you do:

sudo npx asar extract \
  /Applications/Slack.app/Contents/Resources/app.asar \
  /tmp/app.asar.unpacked

sudo vim /tmp/app.asar.unpacked/dist/ssb-interop.bundle.js

What injection code is in the bottom?

nathairtras commented 4 years ago

Here's what's in the file.

// WYSIWYG patch
(() => {
  const disableWysiwygEditor = redux => {
    const {
      wysiwyg_composer,
      wysiwyg_composer_ios,
      wysiwyg_composer_webapp,
      ...payload
    } = redux.getState().experiments;

    redux.dispatch(
      {
        type: '[19] Bulk add experiment assignments to redux',
        payload
      }
    );
  };

  let currentTeamId = null;
  const seenTeams = {};

  setInterval(() => {
    if (!window.slackDebug) return;

    const { activeTeamId } = window.slackDebug;
    const newId = activeTeamId && activeTeamId !== currentTeamId

    if (newId && slackDebug[activeTeamId] && slackDebug[activeTeamId].redux) {
      currentTeamId = activeTeamId;
      const needsPatching = !seenTeams[activeTeamId];

      if (needsPatching) {
        seenTeams[activeTeamId] = true;

        const checkInterval = setInterval(() => {
          const team = slackDebug[activeTeamId];
          const wysiwygLoaded = Boolean(
            document.querySelector('[data-qa="texty_composer_button"]')
          );

          if (team.redux && wysiwygLoaded) {
            disableWysiwygEditor(team.redux);
            clearInterval(checkInterval);
          }
        });
      }
    }
  }, 50);
})();
// END patch

I haven't tested thoroughly, assuming that running the patch manually in-app wouldn't have touched this, but I'll need to uninstall / reinstall Slack to start over with the wysiwyg. Will try to do that over the weekend and pull the .js file out during each step to see what changes. Assuming I can reproduce the issue in the first place.