Skip to content

Instantly share code, notes, and snippets.

@ebith
Last active May 25, 2024 11:00
Show Gist options
  • Save ebith/fa0381b8b386c349da4dd474957791f9 to your computer and use it in GitHub Desktop.
Save ebith/fa0381b8b386c349da4dd474957791f9 to your computer and use it in GitHub Desktop.
Inject CSS into a Discord client.
/*
* Usage
*
* copy core.asar from Discord app
* Win: %APPDATA%/discord/0.0.xxx/modules/discord_desktop_core/core.asar
* Mac: ~/Library/Application\ Support/discord/0.0.xxx/modules/discord_desktop_core/core.asar
* yarn add asar
* asar e core.asar core
* CSS_PATH=C:/dropbox/discordUser.css node injectUserCss.js
* asar p core core.asar
* copy core.asar to Discord app
*
* Supported: 0.0.250(Mac), 0.0.300(Win)
*/
const fs = require('fs');
const jsPath = 'core/app/mainScreen.js';
let content = fs.readFileSync(jsPath, 'utf-8');
const cssInjection = `
require('fs').readFile('${process.env.CSS_PATH}', 'utf-8', (err, userCss) => {
const style = document.createElement('style');
style.innerHTML = userCss;
document.head.appendChild(style);
});
`;
content = content.replace('mainWindow.webContents.', `mainWindow.webContents.on('dom-ready', () => {
mainWindow.webContents.executeJavaScript(\`${cssInjection}\`);
});mainWindow.webContents.`);
fs.writeFileSync(jsPath, content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment