2020-07-04 05:05:53 +00:00
|
|
|
let blockedLibrary = {}
|
2020-07-06 01:00:06 +00:00
|
|
|
let isConnectedToVoiceServer = false
|
|
|
|
|
|
|
|
let keepAliveClientOP = null
|
|
|
|
let keepAliveRemoteOP = null
|
|
|
|
|
|
|
|
let windowName = 0
|
2020-07-04 05:05:53 +00:00
|
|
|
|
|
|
|
function convertObjToString(arr) {
|
|
|
|
let arrStr = `[`
|
|
|
|
arr.forEach(function(i, idx, array){
|
|
|
|
let _subStr = i.toString()
|
|
|
|
arrStr = arrStr.concat("'").concat(_subStr).concat("'")
|
|
|
|
if (idx !== array.length - 1){
|
|
|
|
arrStr = arrStr.concat(`,`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
arrStr = arrStr.concat(`]`).toString()
|
|
|
|
return arrStr
|
|
|
|
}
|
|
|
|
|
2019-12-21 01:04:26 +00:00
|
|
|
function openMic(webview){
|
2019-12-21 22:11:50 +00:00
|
|
|
console.log("talking")
|
2019-12-22 01:43:29 +00:00
|
|
|
document.getElementById("overlay").style.display = "block";
|
2019-12-21 22:11:50 +00:00
|
|
|
webview.sendInputEvent({keyCode: 'Backspace', type: 'keyDown'});
|
2020-06-20 19:00:15 +00:00
|
|
|
//webview.sendInputEvent({keyCode: 'Backspace', type: 'char'});
|
2019-12-21 01:04:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 18:51:08 +00:00
|
|
|
function muteMic(webview){
|
|
|
|
console.log("not talking")
|
2019-12-22 01:43:29 +00:00
|
|
|
document.getElementById("overlay").style.display = "none";
|
2019-10-19 18:51:08 +00:00
|
|
|
webview.sendInputEvent({keyCode: 'Backspace', type: 'keyUp'});
|
2020-06-20 19:00:15 +00:00
|
|
|
//webview.sendInputEvent({keyCode: 'Backspace', type: 'char'});
|
2019-10-19 18:51:08 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 19:33:08 +00:00
|
|
|
function removeBloat(webview) {
|
|
|
|
console.log("--Removing bloat")
|
|
|
|
bloatList = [
|
|
|
|
'noticeDefault',
|
|
|
|
'noticeBrand',
|
|
|
|
'actionButtons-14eAc_',
|
|
|
|
]
|
|
|
|
bloatList.forEach(function(tag){
|
|
|
|
webview.executeJavaScript(`
|
|
|
|
document.querySelectorAll("div[class^=${tag}]").forEach(e => {
|
2020-07-04 05:05:53 +00:00
|
|
|
console.log("Removing ", e)
|
2020-07-06 01:00:06 +00:00
|
|
|
e.style.display = 'none'
|
2020-06-19 19:33:08 +00:00
|
|
|
})
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
|
2020-05-11 00:30:59 +00:00
|
|
|
if (document.querySelectorAll('[aria-label="Disconnect"]').length === 1){
|
|
|
|
console.log('--user is connected to voice server')
|
2019-10-24 01:27:57 +00:00
|
|
|
}else {
|
2020-05-11 00:30:59 +00:00
|
|
|
console.log('--user is not connected to voice server')
|
2019-10-24 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
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 = () => {
|
2019-12-22 01:43:29 +00:00
|
|
|
document.getElementById("overlay").style.display = "none";
|
2019-10-14 19:23:56 +00:00
|
|
|
const webview = document.querySelector('webview')
|
2019-10-15 00:35:25 +00:00
|
|
|
|
2020-07-06 01:00:06 +00:00
|
|
|
const whiteList = [
|
2020-07-04 05:05:53 +00:00
|
|
|
'PATCH', // Mute/Unmute/notification/cosmetic guild changes
|
|
|
|
'DELETE', // Leaving a guild / Deleting messages
|
2020-08-13 01:28:00 +00:00
|
|
|
'https://discord.com/api/v8/channels/', // Text channel address
|
|
|
|
'https://discord.com/api/v8/auth/login', // Login address
|
|
|
|
'https://discord.com/api/v8/invites/', // Accepting guild invite
|
|
|
|
'https://discord.com/api/v8/voice/regions', // Required when creating new guild
|
|
|
|
'https://discord.com/api/v8/guilds', // Creating a guild
|
|
|
|
'https://discord.com/api/v8/gateway' // This may be required to get past login screen if not cached locally
|
2020-07-04 05:05:53 +00:00
|
|
|
]
|
|
|
|
|
2020-07-06 01:00:06 +00:00
|
|
|
const _whiteList = convertObjToString(whiteList)
|
|
|
|
|
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() {
|
2020-07-06 01:00:06 +00:00
|
|
|
|
2020-07-04 05:05:53 +00:00
|
|
|
// Discord does not do client-side hashing
|
|
|
|
webview.executeJavaScript(`
|
|
|
|
(function(open, send) {
|
2020-07-06 01:00:06 +00:00
|
|
|
let whiteList = ${_whiteList}
|
2020-07-04 05:05:53 +00:00
|
|
|
|
|
|
|
let xhrOpenRequestUrl
|
|
|
|
let xhrSendResponseUrl
|
|
|
|
let xhrMethod
|
|
|
|
let responseData
|
|
|
|
|
|
|
|
let _done = false
|
|
|
|
let _block = true
|
|
|
|
let _isWhitelisted = false
|
|
|
|
|
2020-07-06 01:00:06 +00:00
|
|
|
XMLHttpRequest.prototype.open = function(method, url, async, x, y) {
|
2020-07-04 05:05:53 +00:00
|
|
|
xhrMethod = method.toString()
|
|
|
|
xhrOpenRequestUrl = url.toString()
|
|
|
|
if (xhrOpenRequestUrl.includes("science")) {
|
|
|
|
console.log("--BLOCKED.OPEN|" + xhrOpenRequestUrl)
|
2020-07-06 01:00:06 +00:00
|
|
|
return open.apply(this, false)
|
2020-07-04 05:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log("EVALUATING:", xhrOpenRequestUrl)
|
|
|
|
|
|
|
|
whiteList.forEach( wl => {
|
|
|
|
if (xhrOpenRequestUrl.includes(wl) || xhrMethod.includes(wl)) {
|
|
|
|
_done = true
|
|
|
|
_block = false
|
|
|
|
_isWhitelisted = true
|
|
|
|
console.log("--ALLOWED.OPEN", xhrOpenRequestUrl + "")
|
2020-07-06 01:00:06 +00:00
|
|
|
return open.apply(this, arguments)
|
2020-07-04 05:05:53 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (_done === false) {
|
|
|
|
console.log("--BLOCKED.OPEN|" + xhrOpenRequestUrl)
|
2020-07-06 01:00:06 +00:00
|
|
|
return open.apply(this, false)
|
2020-07-04 05:05:53 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-06 01:00:06 +00:00
|
|
|
|
2020-07-04 05:05:53 +00:00
|
|
|
XMLHttpRequest.prototype.send = function(data) {
|
|
|
|
if (_block === true || _isWhitelisted === false) {
|
|
|
|
console.log("--BLOCKED.SEND", data, xhrOpenRequestUrl, _isWhitelisted)
|
2020-07-06 01:00:06 +00:00
|
|
|
return send.apply(this, false)
|
2020-07-04 05:05:53 +00:00
|
|
|
}
|
|
|
|
if (_block === false && _isWhitelisted === true) {
|
|
|
|
if (data && !data.toString().includes("password")) {
|
|
|
|
console.log("--ALLOWED.SEND", data, xhrOpenRequestUrl, _isWhitelisted)
|
|
|
|
}else {
|
|
|
|
console.log("--ALLOWED.SEND")
|
|
|
|
}
|
2020-07-06 01:00:06 +00:00
|
|
|
return send.apply(this, arguments)
|
2020-07-04 05:05:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})(XMLHttpRequest.prototype.open, XMLHttpRequest.prototype.send)
|
|
|
|
`)
|
|
|
|
|
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
|
|
|
|
2020-07-04 05:05:53 +00:00
|
|
|
// Insert a function that will be called later
|
|
|
|
webview.executeJavaScript(`
|
|
|
|
function isMicMuted() {
|
|
|
|
if (document.querySelectorAll('[aria-label="Mute"]')[0].getAttribute("aria-checked") === "false"){
|
|
|
|
console.log("unmuted")
|
|
|
|
}else {
|
|
|
|
console.log("muted")
|
|
|
|
}
|
2019-10-25 03:18:02 +00:00
|
|
|
}
|
2020-07-06 01:00:06 +00:00
|
|
|
`)
|
2020-07-04 05:05:53 +00:00
|
|
|
})
|
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) => {
|
2020-07-06 01:00:06 +00:00
|
|
|
|
2020-05-11 00:30:59 +00:00
|
|
|
if (e.message === "--user is connected to voice server") {
|
2019-10-14 19:59:30 +00:00
|
|
|
console.log("Connected to server")
|
2019-10-20 03:38:47 +00:00
|
|
|
window.postMessage({ type: "connected"}, "*")
|
2020-06-20 19:00:15 +00:00
|
|
|
removeBloat(webview)
|
2020-07-06 01:00:06 +00:00
|
|
|
isConnectedToVoiceServer = true
|
2019-10-14 19:59:30 +00:00
|
|
|
}
|
2019-10-14 19:23:56 +00:00
|
|
|
|
2020-05-11 00:30:59 +00:00
|
|
|
if (e.message === "--user is not connected to 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"}, "*")
|
2020-07-06 01:00:06 +00:00
|
|
|
isConnectedToVoiceServer = false
|
2019-10-14 19:23:56 +00:00
|
|
|
}
|
2019-10-16 20:52:33 +00:00
|
|
|
|
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") {
|
2020-07-06 01:00:06 +00:00
|
|
|
webview.executeJavaScript(`document.getElementsByClassName("listItem-2P_4kh")[document.getElementsByClassName("listItem-2P_4kh").length - 1].style.display = 'none';`) // Remove download button
|
2019-10-24 01:27:57 +00:00
|
|
|
userListChangeListener(webview)
|
|
|
|
userMuteDeafenListener(webview)
|
2020-06-19 19:33:08 +00:00
|
|
|
removeBloat(webview)
|
2019-10-16 20:52:33 +00:00
|
|
|
}
|
2020-07-06 01:00:06 +00:00
|
|
|
|
2020-07-04 05:05:53 +00:00
|
|
|
if (e.message.toString().includes("--BLOCKED.OPEN")) {
|
2020-07-06 01:00:06 +00:00
|
|
|
let _url = e.message.toString().split(",").find(a =>a.includes("http")).split("https://")[1]
|
|
|
|
if (!(_url in blockedLibrary)) {
|
|
|
|
blockedLibrary[_url] = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
blockedLibrary[_url] += 1
|
|
|
|
|
|
|
|
window.postMessage({ type: "blockUpdate", payload: {url: _url, count: blockedLibrary[_url]}}, "*")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keepAliveClientOP === null) {
|
|
|
|
if (e.message.toString().includes("S->>|")) {
|
|
|
|
let _data = e.message.split("|")[1]
|
|
|
|
_data = JSON.parse(_data)
|
|
|
|
console.log(_data)
|
|
|
|
if (Number.isInteger(_data.d)){
|
|
|
|
keepAliveClientOP = _data.op
|
|
|
|
console.log("Client OP", keepAliveClientOP)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keepAliveRemoteOP === null) {
|
|
|
|
if (e.message.toString().includes("R-<<|")) {
|
|
|
|
let _data = e.message.split("|")[1]
|
|
|
|
_data = JSON.parse(_data)
|
|
|
|
if (Number.isInteger(_data.d)){
|
|
|
|
keepAliveRemoteOP = _data.op
|
|
|
|
console.log("Client OP", keepAliveRemoteOP)
|
|
|
|
}
|
2020-07-04 05:05:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-14 19:23:56 +00:00
|
|
|
})
|
|
|
|
|
2020-07-09 03:23:17 +00:00
|
|
|
// Accept commands from mainLoad.js
|
2019-10-20 03:38:47 +00:00
|
|
|
window.addEventListener(
|
|
|
|
"message",
|
|
|
|
event => {
|
2020-07-09 03:23:17 +00:00
|
|
|
if (event.origin === "file://" && event.source === window) {
|
|
|
|
if (event.data.type === "devMode" && event.data.text === "true") {
|
|
|
|
console.log("Dev Mode On")
|
|
|
|
webview.openDevTools()
|
|
|
|
}
|
2019-10-15 00:35:25 +00:00
|
|
|
|
2020-08-13 01:28:00 +00:00
|
|
|
if (event.data.type === 'unfocused'){
|
|
|
|
console.log("window unfocused")
|
|
|
|
document.getElementById('titleBar').style.color = "#7f7f7f"
|
|
|
|
}
|
|
|
|
if (event.data.type === 'focused'){
|
|
|
|
console.log("window focused")
|
|
|
|
document.getElementById('titleBar').style.color = "#ffffff"
|
|
|
|
}
|
|
|
|
|
2020-07-09 03:23:17 +00:00
|
|
|
if (event.data.type === 'micOpen'){
|
|
|
|
openMic(webview)
|
|
|
|
window.postMessage({ type: "confirmMicOpen"}, "*")
|
|
|
|
}
|
2019-10-20 03:38:47 +00:00
|
|
|
|
2020-07-09 03:23:17 +00:00
|
|
|
if (event.data.type === 'micClose'){
|
|
|
|
muteMic(webview)
|
|
|
|
window.postMessage({ type: "confirmMicClose"}, "*")
|
|
|
|
}
|
2019-10-15 06:21:54 +00:00
|
|
|
|
2020-07-09 03:23:17 +00:00
|
|
|
if (event.data.type === 'URLCopied') {
|
|
|
|
fadeBanner("copyConfirmBanner")
|
|
|
|
}
|
2020-07-04 05:05:53 +00:00
|
|
|
}
|
2019-10-20 03:38:47 +00:00
|
|
|
},
|
|
|
|
false
|
|
|
|
)
|
|
|
|
}
|