docs: explain CatWar mod settings helpers

This commit is contained in:
nyan404 committed 2026-08-25 04:30:46 +03:00
1 parent 7bb4154bbe
commit f9da8094e1
1 file changed
+11
+11
View File
@@ -110,6 +110,7 @@ for (var key in defaults) {
} }
} }
// Reads one persisted userscript preference or its default value.
function getSettings(key) { function getSettings(key) {
let setting = 'cs_n_' + key; let setting = 'cs_n_' + key;
let val = window.localStorage.getItem(setting); let val = window.localStorage.getItem(setting);
@@ -125,17 +126,20 @@ function getSettings(key) {
} }
} }
// Persists one preference and updates the in-memory settings state.
function setSettings(key, val) { function setSettings(key, val) {
let setting = 'cs_n_' + key; let setting = 'cs_n_' + key;
window.localStorage.setItem(setting, String(val)); window.localStorage.setItem(setting, String(val));
globals[key] = val; globals[key] = val;
} }
// Removes one preference so future reads use its default.
function removeSettings(key) { function removeSettings(key) {
let setting = 'cs_n_' + key; let setting = 'cs_n_' + key;
window.localStorage.removeItem(setting); window.localStorage.removeItem(setting);
} }
// Resets selected preferences to defaults and saves the result.
function resetSettings(settingsToReset) { function resetSettings(settingsToReset) {
for (var i = 0; i < settingsToReset.length; i++) { for (var i = 0; i < settingsToReset.length; i++) {
let key = settingsToReset[i]; let key = settingsToReset[i];
@@ -225,6 +229,7 @@ catch (err) {
window.console.error('Варомод:', err); window.console.error('Варомод:', err);
} }
// Writes the current settings object to userscript storage.
function updateStorage() { function updateStorage() {
// 2.0 // 2.0
Object.keys(window.localStorage).forEach(function(key) { Object.keys(window.localStorage).forEach(function(key) {
@@ -243,6 +248,7 @@ function updateStorage() {
}); });
} }
// Applies shared navigation and style enhancements across page types.
function changeAllPages() { function changeAllPages() {
const white = $('body > span').first(); const white = $('body > span').first();
if (white.length) { if (white.length) {
@@ -400,6 +406,7 @@ function changeAllPages() {
}); });
} }
// Displays a temporary informational or error popup.
function showCwmodPopup(type, text) { function showCwmodPopup(type, text) {
$('#cwmod-popup-wrap').removeClass().addClass(type); $('#cwmod-popup-wrap').removeClass().addClass(type);
$('#cwmod-popup-text').html(text); $('#cwmod-popup-text').html(text);
@@ -408,6 +415,7 @@ function showCwmodPopup(type, text) {
} }
} }
// Initializes the moon-age calculator form and date conversions.
function moonCalc() { function moonCalc() {
if (!$('#info').length) return; if (!$('#info').length) return;
addCSS(`.calc-error { color: darkred; }`); addCSS(`.calc-error { color: darkred; }`);
@@ -478,10 +486,12 @@ function moonCalc() {
}); });
} }
// Returns the grammatically correct Russian word for a moon count.
function updateMoonWord(moons) { function updateMoonWord(moons) {
$('#moon-word').html(declOfNum(moons, ['луна', 'луны', 'лун'])); $('#moon-word').html(declOfNum(moons, ['луна', 'луны', 'лун']));
} }
// Calculates elapsed moon cycles between two calendar dates.
function getMoonsFromDate(birthDateString, dateString) { function getMoonsFromDate(birthDateString, dateString) {
const birthday = Date.parse(birthDateString); const birthday = Date.parse(birthDateString);
const date = Date.parse(dateString); const date = Date.parse(dateString);
@@ -489,6 +499,7 @@ function getMoonsFromDate(birthDateString, dateString) {
return moons; return moons;
} }
// Calculates the calendar date reached after a number of moon cycles.
function getDateStringFromMoons(birthDateString, moons) { function getDateStringFromMoons(birthDateString, moons) {
const birthday = Date.parse(birthDateString); const birthday = Date.parse(birthDateString);
const age = Math.round(convertTime('d ms', moons * 4)); const age = Math.round(convertTime('d ms', moons * 4));