mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-11 00:46:38 +01:00
RossMods: Debounce online status display
This commit is contained in:
parent
2f43c8e227
commit
8061f45368
@ -56,22 +56,25 @@ let counterNonce = Date.now();
|
|||||||
|
|
||||||
const observerConfig = { childList: true, subtree: true };
|
const observerConfig = { childList: true, subtree: true };
|
||||||
const countTokensDebounced = debounce(RA_CountCharTokens, debounce_timeout.relaxed);
|
const countTokensDebounced = debounce(RA_CountCharTokens, debounce_timeout.relaxed);
|
||||||
|
const countTokensShortDebounced = debounce(RA_CountCharTokens, debounce_timeout.short);
|
||||||
|
const checkStatusDebounced = debounce(RA_checkOnlineStatus, debounce_timeout.short);
|
||||||
|
|
||||||
const observer = new MutationObserver(function (mutations) {
|
const observer = new MutationObserver(function (mutations) {
|
||||||
mutations.forEach(function (mutation) {
|
mutations.forEach(function (mutation) {
|
||||||
|
if (!(mutation.target instanceof HTMLElement)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (mutation.target.classList.contains('online_status_text')) {
|
if (mutation.target.classList.contains('online_status_text')) {
|
||||||
RA_checkOnlineStatus();
|
checkStatusDebounced();
|
||||||
} else if (mutation.target.parentNode === SelectedCharacterTab) {
|
} else if (mutation.target.parentNode === SelectedCharacterTab) {
|
||||||
setTimeout(RA_CountCharTokens, 200);
|
countTokensShortDebounced();
|
||||||
} else if (mutation.target.classList.contains('mes_text')) {
|
} else if (mutation.target.classList.contains('mes_text')) {
|
||||||
if (mutation.target instanceof HTMLElement) {
|
for (const element of mutation.target.getElementsByTagName('math')) {
|
||||||
for (const element of mutation.target.getElementsByTagName('math')) {
|
element.childNodes.forEach(function (child) {
|
||||||
element.childNodes.forEach(function (child) {
|
if (child.nodeType === Node.TEXT_NODE) {
|
||||||
if (child.nodeType === Node.TEXT_NODE) {
|
child.textContent = '';
|
||||||
child.textContent = '';
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -159,8 +162,8 @@ export function shouldSendOnEnter() {
|
|||||||
export function humanizedDateTime() {
|
export function humanizedDateTime() {
|
||||||
const now = new Date(Date.now());
|
const now = new Date(Date.now());
|
||||||
const dt = {
|
const dt = {
|
||||||
year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate(),
|
year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate(),
|
||||||
hour: now.getHours(), minute: now.getMinutes(), second: now.getSeconds(),
|
hour: now.getHours(), minute: now.getMinutes(), second: now.getSeconds(),
|
||||||
};
|
};
|
||||||
for (const key in dt) {
|
for (const key in dt) {
|
||||||
dt[key] = dt[key].toString().padStart(2, '0');
|
dt[key] = dt[key].toString().padStart(2, '0');
|
||||||
@ -725,9 +728,7 @@ export function addSafariPatch() {
|
|||||||
|
|
||||||
export function initRossMods() {
|
export function initRossMods() {
|
||||||
// initial status check
|
// initial status check
|
||||||
setTimeout(() => {
|
checkStatusDebounced();
|
||||||
RA_checkOnlineStatus();
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
if (power_user.auto_load_chat) {
|
if (power_user.auto_load_chat) {
|
||||||
RA_autoloadchat();
|
RA_autoloadchat();
|
||||||
@ -752,7 +753,7 @@ export function initRossMods() {
|
|||||||
setTimeout(() => RA_autoconnect(PrevAPI), 100);
|
setTimeout(() => RA_autoconnect(PrevAPI), 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#api_button').click(function () { setTimeout(RA_checkOnlineStatus, 100); });
|
$('#api_button').on('click', () => checkStatusDebounced());
|
||||||
|
|
||||||
//toggle pin class when lock toggle clicked
|
//toggle pin class when lock toggle clicked
|
||||||
$(RPanelPin).on('click', function () {
|
$(RPanelPin).on('click', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user