settings: add openasar setting item (rewrite)

This commit is contained in:
Ducko 2023-04-01 20:51:02 +01:00
parent 3a52bd2ac7
commit cc0cae97f9
2 changed files with 17 additions and 25 deletions

4
src/bootstrap.js vendored
View file

@ -37,10 +37,10 @@ const startCore = () => {
if (!bw.resizable) return; // Main window only
splash.pageReady(); // Override Core's pageReady with our own on dom-ready to show main window earlier
const [ channel, hash ] = oaVersion.split('-'); // Split via -
const [ channel = '', hash = '' ] = oaVersion.split('-'); // Split via -
bw.webContents.executeJavaScript(readFileSync(join(__dirname, 'mainWindow.js'), 'utf8')
.replaceAll('<hash>', hash)
.replaceAll('<hash>', hash).replaceAll('<channel>', channel)
.replaceAll('<notrack>', oaConfig.noTrack)
.replace('<css>', (oaConfig.css ?? '').replaceAll('\\', '\\\\').replaceAll('`', '\\`')));

View file

@ -25,20 +25,27 @@ const themesync = async () => {
if (value !== pastValue) DiscordNative.userDataCache.cacheUserData(JSON.stringify(cached));
};
// Settings info version injection
// Settings injection
setInterval(() => {
const host = [...document.querySelectorAll('[class*="info-"] [class*="line-"]')].find(x => x.textContent.startsWith('Host '));
if (!host || document.querySelector('#openasar-ver')) return;
const el = document.createElement('span');
el.id = 'openasar-ver';
const oaVersion = host.cloneNode(true);
oaVersion.id = 'openasar-ver';
oaVersion.textContent = 'OpenAsar <channel> <hash>';
oaVersion.onclick = () => DiscordNative.ipc.send('DISCORD_UPDATED_QUOTES', 'o');
el.textContent = 'OpenAsar <hash>';
el.onclick = () => DiscordNative.ipc.send('DISCORD_UPDATED_QUOTES', 'o');
host.insertAdjacentElement('afterend', oaVersion);
host.append(document.createTextNode(' | '), el);
}, 2000);
const advanced = document.querySelector('[class*="socialLinks-"]').parentElement.querySelectorAll('[class*="separator-')[2].previousElementSibling;
if (!advanced) return;
const oaSetting = advanced.cloneNode(true);
oaSetting.textContent = 'OpenAsar';
oaSetting.onclick = oaVersion.onclick;
advanced.insertAdjacentElement('afterend', oaSetting);
}, 1000);
const injCSS = x => {
const el = document.createElement('style');
@ -46,21 +53,6 @@ const injCSS = x => {
document.body.appendChild(el);
};
injCSS(`
[class^="socialLinks-"] + [class^="info-"] {
padding-right: 0;
}
#openasar-ver {
text-transform: none;
cursor: pointer;
}
#openasar-ver:hover {
text-decoration: underline;
color: var(--text-normal);
}`);
injCSS(`<css>`);
openasar = {}; // Define global for any mods which want to know / etc