RossMods: Debounce online status display

8061f453687bfc95edb3de7a3d6702dd48c42bd8

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +9 -8Showing whitespace changes
public/scripts/RossAscends-mods.js+9 -8
@@ -56,15 +56,19 @@ let counterNonce = Date.now();
5656
57const observerConfig = { childList: true, subtree: true };57const observerConfig = { childList: true, subtree: true };
58const countTokensDebounced = debounce(RA_CountCharTokens, debounce_timeout.relaxed);58const countTokensDebounced = debounce(RA_CountCharTokens, debounce_timeout.relaxed);
59const countTokensShortDebounced = debounce(RA_CountCharTokens, debounce_timeout.short);
60const checkStatusDebounced = debounce(RA_checkOnlineStatus, debounce_timeout.short);
5961
60const observer = new MutationObserver(function (mutations) {62const observer = new MutationObserver(function (mutations) {
61 mutations.forEach(function (mutation) {63 mutations.forEach(function (mutation) {
64 if (!(mutation.target instanceof HTMLElement)) {
65 return;
66 }
62 if (mutation.target.classList.contains('online_status_text')) {67 if (mutation.target.classList.contains('online_status_text')) {
63 RA_checkOnlineStatus();68 checkStatusDebounced();
64 } else if (mutation.target.parentNode === SelectedCharacterTab) {69 } else if (mutation.target.parentNode === SelectedCharacterTab) {
65 setTimeout(RA_CountCharTokens, 200);70 countTokensShortDebounced();
66 } else if (mutation.target.classList.contains('mes_text')) {71 } else if (mutation.target.classList.contains('mes_text')) {
67 if (mutation.target instanceof HTMLElement) {
68 for (const element of mutation.target.getElementsByTagName('math')) {72 for (const element of mutation.target.getElementsByTagName('math')) {
69 element.childNodes.forEach(function (child) {73 element.childNodes.forEach(function (child) {
70 if (child.nodeType === Node.TEXT_NODE) {74 if (child.nodeType === Node.TEXT_NODE) {
@@ -73,7 +77,6 @@ const observer = new MutationObserver(function (mutations) {
73 });77 });
74 }78 }
75 }79 }
76 }
77 });80 });
78});81});
7982
@@ -725,9 +728,7 @@ export function addSafariPatch() {
725728
726export function initRossMods() {729export function initRossMods() {
727 // initial status check730 // initial status check
728 setTimeout(() => {731 checkStatusDebounced();
729 RA_checkOnlineStatus();
730 }, 100);
731732
732 if (power_user.auto_load_chat) {733 if (power_user.auto_load_chat) {
733 RA_autoloadchat();734 RA_autoloadchat();
@@ -752,7 +753,7 @@ export function initRossMods() {
752 setTimeout(() => RA_autoconnect(PrevAPI), 100);753 setTimeout(() => RA_autoconnect(PrevAPI), 100);
753 });754 });
754755
755 $('#api_button').click(function () { setTimeout(RA_checkOnlineStatus, 100); });756 $('#api_button').on('click', () => checkStatusDebounced());
756757
757 //toggle pin class when lock toggle clicked758 //toggle pin class when lock toggle clicked
758 $(RPanelPin).on('click', function () {759 $(RPanelPin).on('click', function () {