-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjectcss.js
More file actions
70 lines (58 loc) · 2.2 KB
/
Copy pathinjectcss.js
File metadata and controls
70 lines (58 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const fs = require('fs');
const path = require('path');
// Path to Discord's main module
const discordPath = path.join(process.env.LOCALAPPDATA, 'Discord');
const cssPath = path.join(__dirname, 'custom.css');
// Function to find Discord's module
function findDiscordModule() {
const appDirs = fs.readdirSync(discordPath).filter(dir => dir.startsWith('app-'));
if (!appDirs.length) return null;
// Get the latest version
return path.join(discordPath, appDirs[appDirs.length - 1], 'modules', 'discord_desktop_core-1', 'discord_desktop_core');
}
// Function to inject our CSS
function injectCSS() {
const modulePath = findDiscordModule();
if (!modulePath) {
console.error('Discord installation not found!');
return;
}
const indexPath = path.join(modulePath, 'index.js');
// Create custom CSS file if it doesn't exist
if (!fs.existsSync(cssPath)) {
fs.writeFileSync(cssPath, '/* Add your custom CSS here */');
}
// Read the custom CSS
const customCSS = fs.readFileSync(cssPath, 'utf-8');
// Injection code
const injection = `
module.exports = require('./core.asar');
const electron = require('electron');
const fs = require('fs');
electron.app.on('browser-window-created', (event, window) => {
window.webContents.on('dom-ready', () => {
window.webContents.executeJavaScript(\`
(() => {
const style = document.createElement('style');
style.textContent = \\\`${customCSS}\\\`;
document.head.appendChild(style);
})();
\`);
});
});
`;
// Backup original file
if (!fs.existsSync(`${indexPath}.backup`)) {
fs.copyFileSync(indexPath, `${indexPath}.backup`);
}
// Write the modified index.js
fs.writeFileSync(indexPath, injection);
console.log('CSS injection successful! Restart Discord to see changes.');
}
// Run the injector
try {
injectCSS();
} catch (error) {
console.error('Error:', error.message);
console.error('Make sure Discord is installed and you have administrator privileges.');
}