2019-10-19 04:30:26 +00:00
|
|
|
function removeBloat(webview) {
|
2019-10-24 01:35:36 +00:00
|
|
|
console.log("Removing bloat")
|
2019-10-24 01:27:57 +00:00
|
|
|
bloatList = [
|
2019-10-25 03:18:02 +00:00
|
|
|
'buttons-205you', // remove buttons from chat box (Gift, GIF, and Emojis)
|
2019-10-24 01:27:57 +00:00
|
|
|
'noticeDefault-362Ko2',
|
|
|
|
'channelNotice-1-XFjC',
|
|
|
|
]
|
|
|
|
bloatList.forEach(function(tag){
|
|
|
|
webview.executeJavaScript(`
|
|
|
|
if (document.getElementsByClassName("${tag}").length !== 0){
|
|
|
|
document.getElementsByClassName("${tag}")[document.getElementsByClassName("${tag}").length - 1].remove();
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
})
|
2019-10-19 04:30:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 18:51:08 +00:00
|
|
|
function muteMic(webview){
|
|
|
|
console.log("not talking")
|
|
|
|
webview.sendInputEvent({keyCode: 'Backspace', type: 'keyUp'});
|
|
|
|
webview.sendInputEvent({keyCode: 'Backspace', type: 'char'});
|
|
|
|
}
|
|
|
|
|
2019-10-24 01:27:57 +00:00
|
|
|
// Creates an observer for user list to detect if server is switched
|
|
|
|
function userListChangeListener(webview) {
|
|
|
|
webview.executeJavaScript(`
|
|
|
|
const userList = document.getElementsByClassName("sidebar-2K8pFh")[0]
|
|
|
|
const userListconfig = { attributes: false, childList: true, subtree: true, characterData: false };
|
|
|
|
|
|
|
|
const userListChangeCallback = function(mutationsList, observer) {
|
|
|
|
console.log('--user list changed');
|
|
|
|
|
|
|
|
if (document.getElementsByClassName("container-1giJp5").length !== 0){
|
|
|
|
console.log('--user has connected to discord voice server')
|
|
|
|
}else {
|
|
|
|
console.log('--user has disconnected to discord voice server')
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
const userListObserver = new MutationObserver(userListChangeCallback);
|
|
|
|
userListObserver.observe(userList, userListconfig);
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
function userMuteDeafenListener(webview) {
|
|
|
|
webview.executeJavaScript(`
|
|
|
|
const userMuteDeafen = document.getElementsByClassName("container-3baos1")[0]
|
|
|
|
const userMuteDeafenconfig = { attributes: false, childList: true, subtree: true, characterData: false };
|
|
|
|
|
|
|
|
const userMuteDeafencallback = function(mutationsList, observer) {
|
2019-10-25 03:18:02 +00:00
|
|
|
isMicMuted()
|
2019-10-24 01:27:57 +00:00
|
|
|
};
|
|
|
|
const userMuteDeafenObserver = new MutationObserver(userMuteDeafencallback);
|
|
|
|
userMuteDeafenObserver.observe(userMuteDeafen, userMuteDeafenconfig);
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2019-10-14 19:23:56 +00:00
|
|
|
onload = () => {
|
|
|
|
const webview = document.querySelector('webview')
|
2019-10-19 18:51:08 +00:00
|
|
|
let muteTimeout = null
|
2019-10-15 00:35:25 +00:00
|
|
|
|
2019-10-20 03:38:47 +00:00
|
|
|
// Insert JS to detect when discord finishes loading
|
2019-10-16 20:52:33 +00:00
|
|
|
webview.addEventListener('did-finish-load', function() {
|
2019-10-20 03:38:47 +00:00
|
|
|
webview.executeJavaScript(`
|
|
|
|
let dlButton = document.getElementsByClassName("listItem-2P_4kh");
|
|
|
|
t = setInterval(function(){
|
|
|
|
if(dlButton.length != 0) {
|
2019-10-24 01:27:57 +00:00
|
|
|
console.log("--discord-load-complete")
|
2019-10-20 03:38:47 +00:00
|
|
|
clearInterval(t)
|
2019-10-25 03:18:02 +00:00
|
|
|
isMicMuted()
|
2019-10-20 03:38:47 +00:00
|
|
|
}else {
|
|
|
|
console.log("waiting for load")
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
`)
|
2019-10-25 03:18:02 +00:00
|
|
|
|
|
|
|
// Insert a function that will be called later
|
|
|
|
webview.executeJavaScript(`
|
|
|
|
function isMicMuted() {
|
|
|
|
if (document.querySelectorAll('[aria-label="Mute"]').length === 0){
|
|
|
|
console.log("muted")
|
|
|
|
}else {
|
|
|
|
console.log("unmuted")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
});
|
2019-10-15 00:35:25 +00:00
|
|
|
|
2019-10-20 03:38:47 +00:00
|
|
|
// Send commands to preload.js
|
|
|
|
webview.addEventListener('console-message', (e) => {
|
2019-10-24 01:27:57 +00:00
|
|
|
if (e.message === "--user has connected to discord voice server") {
|
2019-10-14 19:59:30 +00:00
|
|
|
console.log("Connected to server")
|
2019-10-21 00:24:24 +00:00
|
|
|
removeBloat(webview)
|
2019-10-20 03:38:47 +00:00
|
|
|
window.postMessage({ type: "connected"}, "*")
|
2019-10-14 19:59:30 +00:00
|
|
|
}
|
2019-10-14 19:23:56 +00:00
|
|
|
|
2019-10-24 01:27:57 +00:00
|
|
|
if (e.message === "--user has disconnected to discord voice server") {
|
2019-10-14 19:23:56 +00:00
|
|
|
console.log("Disconnected from server")
|
2019-10-20 03:38:47 +00:00
|
|
|
window.postMessage({ type: "disconnected"}, "*")
|
2019-10-14 19:23:56 +00:00
|
|
|
}
|
2019-10-16 20:52:33 +00:00
|
|
|
|
2019-10-24 01:27:57 +00:00
|
|
|
if (e.message === '--user list changed') {
|
|
|
|
removeBloat(webview)
|
|
|
|
}
|
|
|
|
|
2019-10-19 04:30:26 +00:00
|
|
|
if (e.message === "muted") {
|
|
|
|
console.log("Self Muted in Discord")
|
2019-10-20 03:38:47 +00:00
|
|
|
window.postMessage({ type: "self-muted"}, "*")
|
2019-10-19 04:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (e.message === "unmuted") {
|
2019-10-20 03:38:47 +00:00
|
|
|
console.log("Self Un-Muted in Discord")
|
|
|
|
window.postMessage({ type: "self-unmuted"}, "*")
|
2019-10-19 04:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Execute JS into the webview after login
|
2019-10-24 01:27:57 +00:00
|
|
|
if (e.message === "--discord-load-complete") {
|
2019-10-25 03:18:02 +00:00
|
|
|
webview.executeJavaScript(`document.getElementsByClassName("listItem-2P_4kh")[document.getElementsByClassName("listItem-2P_4kh").length - 1].remove();`) // Remove download button
|
|
|
|
//removeBloat(webview)
|
2019-10-24 01:27:57 +00:00
|
|
|
userListChangeListener(webview)
|
|
|
|
userMuteDeafenListener(webview)
|
2019-10-16 20:52:33 +00:00
|
|
|
}
|
2019-10-14 19:23:56 +00:00
|
|
|
})
|
|
|
|
|
2019-10-20 03:38:47 +00:00
|
|
|
// Accept commands from preload.js
|
|
|
|
window.addEventListener(
|
|
|
|
"message",
|
|
|
|
event => {
|
|
|
|
if (event.origin === "file://" && event.source === window) {
|
2019-10-15 06:21:54 +00:00
|
|
|
|
2019-10-20 03:38:47 +00:00
|
|
|
if (event.data.type === "devMode" && event.data.text === "true") {
|
|
|
|
webview.openDevTools()
|
|
|
|
}
|
2019-10-15 00:35:25 +00:00
|
|
|
|
2019-10-20 03:38:47 +00:00
|
|
|
if (event.data.type === 'micOpen'){
|
|
|
|
clearTimeout(muteTimeout) // Cancel mic-off incase of accidental double-tap
|
|
|
|
console.log("talking")
|
|
|
|
webview.sendInputEvent({keyCode: 'Backspace', type: 'keyDown'});
|
|
|
|
webview.sendInputEvent({keyCode: 'Backspace', type: 'char'});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.data.type === 'micClose'){
|
2019-10-25 03:18:02 +00:00
|
|
|
muteTimeout = setTimeout(() => muteMic(webview), 1200); // incase accidental double-click or release so the user doesn't cut-out
|
2019-10-20 03:38:47 +00:00
|
|
|
}
|
2019-10-15 06:21:54 +00:00
|
|
|
|
2019-10-20 03:38:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
false
|
|
|
|
)
|
|
|
|
}
|