diff --git a/web/CatWarMod.js b/web/CatWarMod.js index a027616..a95b324 100644 --- a/web/CatWarMod.js +++ b/web/CatWarMod.js @@ -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 val = window.localStorage.getItem(setting); 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; window.localStorage.setItem(setting, String(val)); globals[key] = val; } -function removeSettings(key) { + // Removes one preference so future reads use its default. + function removeSettings(key) { let setting = 'cs_n_' + key; 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++) { let key = settingsToReset[i]; removeSettings(key); @@ -225,7 +229,8 @@ catch (err) { window.console.error('Варомод:', err); } -function updateStorage() { + // Writes the current settings object to userscript storage. + function updateStorage() { // 2.0 Object.keys(window.localStorage).forEach(function(key) { 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(); if (white.length) { 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-text').html(text); 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; addCSS(`.calc-error { color: darkred; }`); $('#info').after('
'); @@ -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, ['луна', 'луны', 'лун'])); } -function getMoonsFromDate(birthDateString, dateString) { + // Calculates elapsed moon cycles between two calendar dates. + function getMoonsFromDate(birthDateString, dateString) { const birthday = Date.parse(birthDateString); const date = Date.parse(dateString); const moons = Math.floor(convertTime('ms d', date - birthday) / 4 * 10) / 10; 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 age = Math.round(convertTime('d ms', moons * 4)); return dateToString(birthday + age);