WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 5b259e4

Browse files
authored
mainWindow: rewrite settings injection
1 parent bf8a71e commit 5b259e4

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

src/mainWindow.js

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,54 +27,31 @@ const themesync = async () => {
2727

2828
// Settings injection
2929
setInterval(() => {
30-
const host = [...document.querySelectorAll('[class*="sidebar"] [class*="info"] [class*="line"]')].find(x => x.textContent.startsWith('Host '));
31-
if (!host || document.getElementById('openasar-ver')) return;
30+
const versionInfo = document.querySelector('[class*="sidebar"] [class*="compactInfo"]');
31+
if (!versionInfo || document.getElementById('openasar-ver')) return;
3232

33-
const oaVersion = host.cloneNode(true);
33+
const oaVersionInfo = versionInfo.cloneNode(true);
34+
const oaVersion = oaVersionInfo.children[0];
3435
oaVersion.id = 'openasar-ver';
35-
oaVersion.textContent = 'OpenAsar <channel> ';
36+
oaVersion.textContent = 'OpenAsar (<hash>)';
3637
oaVersion.onclick = () => DiscordNative.ipc.send('DISCORD_UPDATED_QUOTES', 'o');
3738

38-
const oaHash = document.querySelector('[class*="versionHash"]').cloneNode(true);
39-
oaHash.textContent = '(<hash>)';
40-
oaVersion.appendChild(oaHash);
39+
oaVersionInfo.textContent = '';
40+
oaVersionInfo.appendChild(oaVersion);
41+
versionInfo.parentElement.parentElement.lastElementChild.insertAdjacentElement('beforebegin', oaVersionInfo);
4142

42-
host.insertAdjacentElement('afterend', oaVersion);
43-
44-
if (document.getElementById('openasar-item'))
45-
return;
46-
47-
// 1st method to get the advanced node
48-
// it's the simplest way, but if discord decide to change that custom value, it's F
49-
let advanced = document.querySelector('[data-tab-id=Advanced]');
50-
51-
// 2nd method to get the advanced node
52-
// this one has the risk of not matching if discord add or remove any setting in the category
53-
if (!advanced) {
54-
advanced = document.querySelector(':has([class^=socialLinks]) > [class^="header"] + [class^="item"] + [class^="item"] + [class^="item"] + [class^="item"] + [class^="item"] + [class^="item"] + [class^="item"] + [class^="item"] + [class^="item"] + [class^="item"]:has(+ [class^="separator"])');
55-
}
56-
57-
// 3rd method to get the advanced node
58-
// this one has the risk of misplacing or not creating the settings if a client-mod is used and the place where it decide to put is settings is anywhere under the App Settings part
59-
if (!advanced) {
60-
advanced = document.querySelector(':has([class^=socialLinks]) > [class^="item"]:has(+ [class^="separator"] + :nth-last-child(1 of [class^=header]))');
61-
}
62-
63-
// 4th method to get the advanced node
64-
// this one will only work if the user's language is english
65-
if (!advanced) {
66-
advanced = [...document.querySelectorAll('[class^="item"]')].find(x => x.textContent === 'Advanced');
67-
}
43+
if (document.getElementById('openasar-item')) return;
44+
let advanced = document.querySelector('[data-list-item-id="settings-sidebar___advanced_sidebar_item"]');
45+
if (!advanced) advanced = document.querySelector('[class*="sidebar"] [class*="nav"] > [class*="section"]:nth-child(3) > :last-child');
46+
if (!advanced) advanced = [...document.querySelectorAll('[class*="item"]')].find(x => x.textContent === 'Advanced');
6847

6948
const oaSetting = advanced.cloneNode(true);
70-
oaSetting.setAttribute('data-tab-id', 'OpenAsar'); // we need to change what we clone so the data is not misleading
71-
oaSetting.setAttribute('aria-label', 'OpenAsar'); // we need to change what we clone so the data is not misleading
72-
oaSetting.textContent = 'OpenAsar';
49+
oaSetting.querySelector('[class*="text"]').textContent = 'OpenAsar';
7350
oaSetting.id = 'openasar-item';
7451
oaSetting.onclick = oaVersion.onclick;
7552

7653
advanced.insertAdjacentElement('afterend', oaSetting);
77-
}, 1000);
54+
}, 800);
7855

7956
const injCSS = x => {
8057
const el = document.createElement('style');

0 commit comments

Comments
 (0)