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
+22 -11
+22 -11
View File
@@ -110,7 +110,8 @@ for (var key in defaults) {
} }
} }
function getSettings(key) { // Reads one persisted userscript preference or its default value.
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);
switch (val) { switch (val) {
@@ -125,18 +126,21 @@ function getSettings(key) {
} }
} }
function setSettings(key, val) { // Persists one preference and updates the in-memory settings state.
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;
} }
function removeSettings(key) { // Removes one preference so future reads use its default.
function removeSettings(key) {
let setting = 'cs_n_' + key; let setting = 'cs_n_' + key;
window.localStorage.removeItem(setting); window.localStorage.removeItem(setting);
} }
function resetSettings(settingsToReset) { // Resets selected preferences to defaults and saves the result.
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];
removeSettings(key); removeSettings(key);
@@ -225,7 +229,8 @@ catch (err) {
window.console.error('Варомод:', err); window.console.error('Варомод:', err);
} }
function updateStorage() { // Writes the current settings object to userscript storage.
function updateStorage() {
// 2.0 // 2.0
Object.keys(window.localStorage).forEach(function(key) { Object.keys(window.localStorage).forEach(function(key) {
const savedNotes = JSON.parse(window.localStorage.getItem('cwmod_notes') || '{}'); const savedNotes = JSON.parse(window.localStorage.getItem('cwmod_notes') || '{}');
@@ -243,7 +248,8 @@ function updateStorage() {
}); });
} }
function changeAllPages() { // Applies shared navigation and style enhancements across page types.
function changeAllPages() {
const white = $('body > span').first(); const white = $('body > span').first();
if (white.length) { if (white.length) {
white.children('a').css('color', ''); white.children('a').css('color', '');
@@ -400,7 +406,8 @@ function changeAllPages() {
}); });
} }
function showCwmodPopup(type, text) { // Displays a temporary informational or error popup.
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);
if ($('#cwmod-popup-wrap').css('display') === 'none') { if ($('#cwmod-popup-wrap').css('display') === 'none') {
@@ -408,7 +415,8 @@ function showCwmodPopup(type, text) {
} }
} }
function moonCalc() { // Initializes the moon-age calculator form and date conversions.
function moonCalc() {
if (!$('#info').length) return; if (!$('#info').length) return;
addCSS(`.calc-error { color: darkred; }`); addCSS(`.calc-error { color: darkred; }`);
$('#info').after('<div id="calc-age"></div>'); $('#info').after('<div id="calc-age"></div>');
@@ -478,18 +486,21 @@ function moonCalc() {
}); });
} }
function updateMoonWord(moons) { // Returns the grammatically correct Russian word for a moon count.
function updateMoonWord(moons) {
$('#moon-word').html(declOfNum(moons, ['луна', 'луны', 'лун'])); $('#moon-word').html(declOfNum(moons, ['луна', 'луны', 'лун']));
} }
function getMoonsFromDate(birthDateString, dateString) { // Calculates elapsed moon cycles between two calendar dates.
function getMoonsFromDate(birthDateString, dateString) {
const birthday = Date.parse(birthDateString); const birthday = Date.parse(birthDateString);
const date = Date.parse(dateString); const date = Date.parse(dateString);
const moons = Math.floor(convertTime('ms d', date - birthday) / 4 * 10) / 10; const moons = Math.floor(convertTime('ms d', date - birthday) / 4 * 10) / 10;
return moons; return moons;
} }
function getDateStringFromMoons(birthDateString, moons) { // Calculates the calendar date reached after a number of moon cycles.
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));
return dateToString(birthday + age); return dateToString(birthday + age);