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
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) {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 }
75 }78 }
76 }79 }
77 });80 });
@@ -159,8 +162,8 @@ export function shouldSendOnEnter() {
159export function humanizedDateTime() {162export function humanizedDateTime() {
160 const now = new Date(Date.now());163 const now = new Date(Date.now());
161 const dt = {164 const dt = {
162 year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate(),165 year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate(),
163 hour: now.getHours(), minute: now.getMinutes(), second: now.getSeconds(),166 hour: now.getHours(), minute: now.getMinutes(), second: now.getSeconds(),
164 };167 };
165 for (const key in dt) {168 for (const key in dt) {
166 dt[key] = dt[key].toString().padStart(2, '0');169 dt[key] = dt[key].toString().padStart(2, '0');
@@ -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 () {