-
Notifications
You must be signed in to change notification settings - Fork 16
/
discocss
executable file
·87 lines (70 loc) · 2.54 KB
/
discocss
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
confdir="${XDG_CONFIG_HOME:=$HOME/.config}/discocss"
preloadFile="$confdir/preload.js"
cssFile="$confdir/custom.css"
mkdir -p "$confdir"
touch "$cssFile"
cat <<EOF > "$preloadFile"
module.exports = () => {
const fs = require("fs");
const electron = require("electron");
const confDir = "$confdir";
const cssFile = "$cssFile";
function reload() {
const css = fs.readFileSync(cssFile, { encoding: "utf-8" });
electron.webFrame.executeJavaScript(\`
(() => {
let loaded = false;
function load() {
if (loaded) return;
const disco = document.createElement("style");
disco.id = "disco";
disco.innerHTML = \${JSON.stringify(css)};
document.getElementById('disco')?.remove();
document.head.appendChild(disco);
loaded = true;
}
window.addEventListener("load", () => {
load();
});
try {
load();
} catch (e) {}
})();
\`);
}
reload();
fs.watch(confDir, {}, () => reload());
};
module.exports.mw = (mainWindow) => {
mainWindow.setBackgroundColor("#00000000");
};
module.exports.mo = (options) => {
options.transparent = true;
if (process.platform === "linux") {
options.frame = true;
}
};
EOF
ln -f -s "$preloadFile" /tmp/discocss-preload.js
if [ "$(uname)" = "Darwin" ]; then
sed_options='-i ""'
core_asar="$(echo "$HOME/Library/Application Support/discord/"*"/modules/discord_desktop_core/core.asar")"
else
sed_options='-i'
core_asar="$(echo "$XDG_CONFIG_HOME/discord/"*"/modules/discord_desktop_core/core.asar")"
fi
app_preload_replace='s| // App preload script, used to provide a replacement native API now that|try {require\(`/tmp/discocss-preload.js`)()} catch \(e\) {console.error\(e\);} |'
launch_main_app_replace='s|// launch main app window; could be called multiple times for various reasons| const dp = require(`/tmp/discocss-preload.js`); |'
frame_true_replace='s| mainWindowOptions.frame = true;|}dp.mo(mainWindowOptions);{ |'
causing_the_window_replace='s|// causing the window to be too small on a larger secondary display| dp.mw(mainWindow); |'
LC_ALL=C sed $sed_options "$app_preload_replace; $launch_main_app_replace; $frame_true_replace; $causing_the_window_replace" \
"$core_asar"
discordBin="$DISCOCSS_DISCORD_BIN"
if [ "$discordBin" ]; then
unset DISCOCSS_DISCORD_BIN
exec "$discordBin"
else
command -v discord && exec discord
command -v Discord && exec Discord
fi