docs: explain lightweight game helper functions
This commit is contained in:
1 parent
bea7c39f7b
commit
afa56b46ee
1 file changed
+16
@@ -78,6 +78,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
// Entry point: wires settings, timers, and page-specific observers together.
|
||||
function init() {
|
||||
if (isGamePage()) {
|
||||
if (settings.smellTimer) setupSmellTimer();
|
||||
@@ -88,10 +89,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true when the current URL belongs to the CatWar game view.
|
||||
function isGamePage() {
|
||||
return /^\/cw3(\/(kns|jagd))?/.test(window.location.pathname);
|
||||
}
|
||||
|
||||
// Detects direct-message pages where the DM helper should be enabled.
|
||||
function isDmPage() {
|
||||
return /^\/ls/.test(window.location.pathname);
|
||||
}
|
||||
@@ -101,6 +104,7 @@
|
||||
* Вспомогательные утилиты
|
||||
* ---------------------
|
||||
*/
|
||||
// Loads persisted user preferences, falling back to the built-in defaults.
|
||||
function loadSettings() {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(STORAGE_KEY);
|
||||
@@ -113,6 +117,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Persists the supplied preferences for the next page visit.
|
||||
function saveSettings(value) {
|
||||
try {
|
||||
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(value));
|
||||
@@ -121,6 +126,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a reusable audio element configured for an alert sound.
|
||||
function createAudio(src, volume) {
|
||||
const audio = new Audio();
|
||||
audio.preload = 'none';
|
||||
@@ -129,6 +135,7 @@
|
||||
return audio;
|
||||
}
|
||||
|
||||
// Converts a visible timer string into seconds, or null when it is invalid.
|
||||
function parseSeconds(text) {
|
||||
if (!text) return NaN;
|
||||
const clean = text.replace(/\u00A0/g, ' ');
|
||||
@@ -147,6 +154,7 @@
|
||||
* Смелл-таймер
|
||||
* ---------------------
|
||||
*/
|
||||
// Locates the smell countdown and attaches the alert timer behavior.
|
||||
function setupSmellTimer() {
|
||||
const menu = document.querySelector('#app > span.small, .small');
|
||||
if (!menu || menu.querySelector('#cwshed-lite-smell')) return;
|
||||
@@ -186,6 +194,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Starts a one-shot countdown that updates the page and plays an alert.
|
||||
function startSmellTimer(seconds) {
|
||||
const label = document.getElementById('cwshed-lite-smell');
|
||||
if (!label) return;
|
||||
@@ -215,6 +224,7 @@
|
||||
smellTimerHandle = window.setInterval(tick, 1000);
|
||||
}
|
||||
|
||||
// Cancels the active smell countdown and restores its original display.
|
||||
function clearSmellTimer() {
|
||||
if (smellTimerHandle) {
|
||||
window.clearInterval(smellTimerHandle);
|
||||
@@ -229,6 +239,7 @@
|
||||
if (label) label.textContent = 'Нюх: —';
|
||||
}
|
||||
|
||||
// Re-reads the current smell value and starts a fresh countdown if possible.
|
||||
function restartSmellTimer() {
|
||||
clearSmellTimer();
|
||||
if (settings.smellTimer && isGamePage()) {
|
||||
@@ -236,6 +247,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Formats a number of seconds as the compact MM:SS timer shown to players.
|
||||
function formatTime(totalSeconds) {
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
@@ -252,6 +264,7 @@
|
||||
* Уведомление о конце действия
|
||||
* ---------------------
|
||||
*/
|
||||
// Observes the action panel and schedules sound/title alerts for completion.
|
||||
function setupActionWatcher() {
|
||||
if (actionIntervalHandle) window.clearInterval(actionIntervalHandle);
|
||||
const audio = (settings.actionAlert && settings.actionAlertSound)
|
||||
@@ -297,12 +310,14 @@
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// Restores the document title after an action notification has been handled.
|
||||
function restoreTitle() {
|
||||
if (storedTitle) {
|
||||
document.title = storedTitle;
|
||||
}
|
||||
}
|
||||
|
||||
// Stops and reinitializes action observation after a DOM refresh.
|
||||
function restartActionWatcher() {
|
||||
if (!isGamePage()) return;
|
||||
if (actionIntervalHandle) {
|
||||
@@ -321,6 +336,7 @@
|
||||
* ID собеседника в ЛС
|
||||
* ---------------------
|
||||
*/
|
||||
// Adds the current conversation identifier to DM links when it is available.
|
||||
function injectDmId(force) {
|
||||
const container = document.getElementById('main');
|
||||
if (!container) return;
|
||||
|
||||
Reference in new issue
Block a user