Skip to content

Instantly share code, notes, and snippets.

@Randomblock1
Last active November 11, 2021 13:08
Show Gist options
  • Save Randomblock1/b8cd3948ce0b4688b874f2643a2a6941 to your computer and use it in GitHub Desktop.
Save Randomblock1/b8cd3948ce0b4688b874f2643a2a6941 to your computer and use it in GitHub Desktop.
JavaScript code for Nativefier Discord to add a counter and native style

You need Nativefier and this icon. Then, save discord.js, the icon, and build.sh in the same folder. Finally, just execute build.sh! ./build.sh (remember to chmod 755 build.sh first)!

nativefier \
--background-color '#23272A' \
--browserwindow-options '{ "fullscreenable": "true", "simpleFullscreen": "false" }' \
--counter \
--darwin-dark-mode-support \
--enable-es3-apis \
--icon discord.icns \
--inject discord.js \
--title-bar-style hiddenInset \
https://discord.com/app
new MutationObserver(function (mutationList, observer) {
mutationList.forEach((mutation) => {
if (mutation.attributeName == 'class' &&
mutation.target.classList.contains('platform-web')) {
mutation.target.classList.remove('platform-web');
mutation.target.classList.add('platform-osx');
}
});
}).observe(document.documentElement, {attributes: true,
characterData: false,
childList: false});
function updateTitle() {
var x = document.querySelector('.scroller-1Bvpku').getElementsByClassName("numberBadge-2s8kKX");
var i;
var total = 0;
for (i = 0; i < x.length; i++) {
total = total + parseInt(x[i].innerHTML, 10);
}
if (total){
document.title = '(' + total + ')';
} else {
document.title = ''
}
}
function periodicalCheck() {
updateTitle();
setTimeout(function(){
periodicalCheck();
}, 5000);
}
var mutationObserver = new MutationObserver(function(mutations) {
updateTitle();
});
const regex = new RegExp('\([0-9]+\)');
var mutationObserver = new MutationObserver(function(mutations) {
if (!regex.test(document.title)) {
updateTitle();
}
});
function onload() {
x = document.querySelector(".scroller-1Bvpku")
mutationObserver.observe(x, {
attributes: true,
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
});
mutationObserver.observe(x, {
childList: true,
subtree: true,
characterData: false,
attributes: false
});
var title = document.querySelector('title');
mutationObserver.observe(title, {
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
});
periodicalCheck();
}
function maybeLoad() {
try {
onload();
} catch (error) {
console.error('failed, trying again in 5')
setTimeout(function(){
maybeLoad();
}, 1000);
}
}
maybeLoad();
@chriskalos
Copy link

Is there any way to get screen sharing working? It's the only thing missing, really.

@Randomblock1
Copy link
Author

Is there any way to get screen sharing working? It's the only thing missing, really.

No, that's a desktop only feature. It's the only reason I haven't completely uninstalled the normal Discord app.

@dmilith
Copy link

dmilith commented Oct 18, 2021

I wonder how to get one missing functionality from the native app: cmd-1, cmd-2, … shortcuts for multiple servers.

@yannhodiesne
Copy link

Forgot to put this here, but thanks @Randomblock1 for this snippet!
I integrated it into my custom client, along with working screen sharing: https://github.com/yannhodiesne/Discord-M1
The last missing features are keyboard shortcuts and push-to-talk, on which several people are trying to make it work

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