OpenAsar/src/mainWindow.js

75 lines
2.4 KiB
JavaScript
Raw Normal View History

if ('<notrack>' === 'true') { // Disable sentry
try {
window.__SENTRY__.hub.getClient().getOptions().enabled = false;
2022-06-10 10:00:01 +00:00
Object.keys(console).forEach(x => console[x] = console[x].__sentry_original__ ?? console[x]);
} catch { }
}
2021-12-26 14:06:10 +00:00
let lastBgPrimary = '';
2021-12-26 17:47:04 +00:00
const themesync = async () => {
const getVar = (name, el = document.body) => el && (getComputedStyle(el).getPropertyValue(name) || getVar(name, el.parentElement))?.trim();
const bgPrimary = getVar('--background-primary');
if (!bgPrimary || bgPrimary === '#36393f' || bgPrimary === '#fff' || bgPrimary === lastBgPrimary) return; // Default primary bg or same as last
lastBgPrimary = bgPrimary;
2021-12-16 16:52:25 +00:00
const vars = [ '--background-primary', '--background-secondary', '--brand-experiment', '--header-primary', '--text-muted' ];
let cached = await DiscordNative.userDataCache.getCached() || {};
2022-03-13 20:20:26 +00:00
const value = `body { ${vars.reduce((acc, x) => acc += `${x}: ${getVar(x)}; `, '')} }`;
const pastValue = cached['openasarSplashCSS'];
2021-12-16 16:52:25 +00:00
cached['openasarSplashCSS'] = value;
if (value !== pastValue) DiscordNative.userDataCache.cacheUserData(JSON.stringify(cached));
2021-12-16 16:52:25 +00:00
};
2021-12-26 17:47:04 +00:00
// Settings info version injection
2022-03-13 20:12:42 +00:00
setInterval(() => {
const host = [...document.querySelectorAll('[class*="info-"] [class*="line-"]')].find(x => x.textContent.startsWith('Host '));
2022-03-13 20:12:42 +00:00
if (!host || document.querySelector('#openasar-ver')) return;
2021-12-16 16:52:25 +00:00
2022-03-13 20:12:42 +00:00
const el = document.createElement('span');
el.id = 'openasar-ver';
el.textContent = 'OpenAsar <hash>';
el.onclick = () => DiscordNative.ipc.send('DISCORD_UPDATED_QUOTES', 'o');
host.append(document.createTextNode(' | '), el);
}, 2000);
2022-09-28 16:50:29 +00:00
const injCSS = x => {
const el = document.createElement('style');
el.appendChild(document.createTextNode(x));
document.body.appendChild(el);
};
2022-03-13 20:12:42 +00:00
2022-09-28 16:50:29 +00:00
injCSS(document.createTextNode(`
[class^="socialLinks-"] + [class^="info-"] {
2021-12-18 18:48:04 +00:00
padding-right: 0;
}
2021-12-26 17:47:04 +00:00
2022-03-13 20:12:42 +00:00
#openasar-ver {
text-transform: none;
cursor: pointer;
2021-12-26 17:47:04 +00:00
}
2022-03-13 20:12:42 +00:00
#openasar-ver:hover {
text-decoration: underline;
color: var(--text-normal);
}`));
2022-09-28 16:50:29 +00:00
injCSS(`<css>`);
2021-12-26 17:47:04 +00:00
openasar = {}; // Define global for any mods which want to know / etc
DiscordNative.nativeModules.ensureModule('discord_voice'); // Ensure discord_voice to generally prevent corruption message / broken VC, also for deferring for fresh start
setInterval(() => { // Try init themesync
try {
themesync();
} catch (e) { }
}, 10000);
themesync();