Skip to content

Instantly share code, notes, and snippets.

@shark0der
Created November 14, 2022 09:09
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shark0der/5cae3356dddd21573aaef6d4933ca43c to your computer and use it in GitHub Desktop.
Save shark0der/5cae3356dddd21573aaef6d4933ca43c to your computer and use it in GitHub Desktop.
Disable WhatsApp automatic emoji conversion

Disable WhatsApp automatic emoji conversion

The script works by patching the webpack chunks instead of manipulating the DOM.

// ==UserScript==
// @name Disable WhatsApp automatic emoji conversion
// @namespace Violentmonkey Scripts
// @match https://web.whatsapp.com/*
// @grant none
// @version 1.0
// @author shark0der
// @description 11/11/2022, 00:53:53 AM
// ==/UserScript==
self.webpackChunkwhatsapp_web_client = self.webpackChunkwhatsapp_web_client || [];
(() => {
// webpack array
const wp = self.webpackChunkwhatsapp_web_client;
// callbacks
const push = wp.push.bind(wp);
let callback = push;
// tainted symbol
const isTainted = Symbol('tainted');
const patchChunk = chunk => {
const [[chunkId], modules, ...whatev] = chunk;
const patchedModules = Object.keys(modules).reduce((acc, id) => {
const f = modules[id];
if (!f.toString().includes('TEXT_TO_EMOJI_HASH=')) {
return { ...acc, [id]: f };
}
console.log(`Patching chunkId=${chunkId} moduleId=${id}`);
const p = function(e, t, n) {
f(e, t, n);
Object.keys(t.TEXT_TO_EMOJI_HASH).forEach(k => delete t.TEXT_TO_EMOJI_HASH[k]);
};
return { ...acc, [id]: p };
}, {});
return [[chunkId], patchedModules, ...whatev];
};
const hijackedPush = (function(...items) {
const [chunk, ...rest] = items;
if (chunk[isTainted]) {
delete chunk[isTainted];
return push(chunk, ...rest);
}
const patchedChunk = patchChunk(chunk);
Object.defineProperty(
patchedChunk,
isTainted,
{ enumerable: false, value: true, configurable: true },
);
return callback(patchedChunk, ...rest);
}).bind(wp);
Object.defineProperty(wp, 'push', {
set: _callback => (callback = _callback),
get: () => hijackedPush,
});
})();
@robinhundt
Copy link

Thanks, works great for me! 👍

@clairekardas
Copy link

Great work! 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment