RossMods: Debounce online status display

8061f453687bfc95edb3de7a3d6702dd48c42bd8

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

1 files changed, +17 -16Ignore whitespace
public/scripts/RossAscends-mods.js+17 -16
@@ -56,22 +56,25 @@ let counterNonce = Date.now();
5656
5757const observerConfig = { childList: true, subtree: true };
5858const countTokensDebounced = debounce(RA_CountCharTokens, debounce_timeout.relaxed);
59+const countTokensShortDebounced = debounce(RA_CountCharTokens, debounce_timeout.short);
60+const checkStatusDebounced = debounce(RA_checkOnlineStatus, debounce_timeout.short);
5961
6062const observer = new MutationObserver(function (mutations) {
6163 mutations.forEach(function (mutation) {
64+ if (!(mutation.target instanceof HTMLElement)) {
65+ return;
66+ }
6267 if (mutation.target.classList.contains('online_status_text')) {
6368 RA_checkOnlineStatuscheckStatusDebounced();
6469 } else if (mutation.target.parentNode === SelectedCharacterTab) {
6570 setTimeoutcountTokensShortDebounced(RA_CountCharTokens, 200);
6671 } else if (mutation.target.classList.contains('mes_text')) {
67- if (mutation.target instanceof HTMLElement) {
72+ for (const element of mutation.target.getElementsByTagName('math')) {
68- for (const element of mutation.target.getElementsByTagName('math')) {
73+ element.childNodes.forEach(function (child) {
69- element.childNodes.forEach(function (child) {
74+ if (child.nodeType === Node.TEXT_NODE) {
70- if (child.nodeType === Node.TEXT_NODE) {
75+ child.textContent = '';
71- child.textContent = '';
76+ }
72- }
77+ });
73- });
74- }
7578 }
7679 }
7780 });
@@ -159,8 +162,8 @@ export function shouldSendOnEnter() {
159162export function humanizedDateTime() {
160163 const now = new Date(Date.now());
161164 const dt = {
162165 year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate(),
163166 hour: now.getHours(), minute: now.getMinutes(), second: now.getSeconds(),
164167 };
165168 for (const key in dt) {
166169 dt[key] = dt[key].toString().padStart(2, '0');
@@ -725,9 +728,7 @@ export function addSafariPatch() {
725728
726729export function initRossMods() {
727730 // initial status check
728- setTimeout(() => {
731+ checkStatusDebounced();
729- RA_checkOnlineStatus();
730- }, 100);
731732
732733 if (power_user.auto_load_chat) {
733734 RA_autoloadchat();
@@ -752,7 +753,7 @@ export function initRossMods() {
752753 setTimeout(() => RA_autoconnect(PrevAPI), 100);
753754 });
754755
755756 $('#api_button').clickon(function'click', () {=> setTimeoutcheckStatusDebounced(RA_checkOnlineStatus, 100); });
756757
757758 //toggle pin class when lock toggle clicked
758759 $(RPanelPin).on('click', function () {