The script works by patching the webpack chunks instead of manipulating the DOM.
Created
November 14, 2022 09:09
-
-
Save shark0der/5cae3356dddd21573aaef6d4933ca43c to your computer and use it in GitHub Desktop.
Disable WhatsApp automatic emoji conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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, | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great work! 💪