docs: explain CatWar mod settings helpers
This commit is contained in:
1 parent
7bb4154bbe
commit
f9da8094e1
1 file changed
+11
@@ -110,6 +110,7 @@ for (var key in defaults) {
|
||||
}
|
||||
}
|
||||
|
||||
// Reads one persisted userscript preference or its default value.
|
||||
function getSettings(key) {
|
||||
let setting = 'cs_n_' + key;
|
||||
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) {
|
||||
let setting = 'cs_n_' + key;
|
||||
window.localStorage.setItem(setting, String(val));
|
||||
globals[key] = val;
|
||||
}
|
||||
|
||||
// Removes one preference so future reads use its default.
|
||||
function removeSettings(key) {
|
||||
let setting = 'cs_n_' + key;
|
||||
window.localStorage.removeItem(setting);
|
||||
}
|
||||
|
||||
// Resets selected preferences to defaults and saves the result.
|
||||
function resetSettings(settingsToReset) {
|
||||
for (var i = 0; i < settingsToReset.length; i++) {
|
||||
let key = settingsToReset[i];
|
||||
@@ -225,6 +229,7 @@ catch (err) {
|
||||
window.console.error('Варомод:', err);
|
||||
}
|
||||
|
||||
// Writes the current settings object to userscript storage.
|
||||
function updateStorage() {
|
||||
// 2.0
|
||||
Object.keys(window.localStorage).forEach(function(key) {
|
||||
@@ -243,6 +248,7 @@ function updateStorage() {
|
||||
});
|
||||
}
|
||||
|
||||
// Applies shared navigation and style enhancements across page types.
|
||||
function changeAllPages() {
|
||||
const white = $('body > span').first();
|
||||
if (white.length) {
|
||||
@@ -400,6 +406,7 @@ function changeAllPages() {
|
||||
});
|
||||
}
|
||||
|
||||
// Displays a temporary informational or error popup.
|
||||
function showCwmodPopup(type, text) {
|
||||
$('#cwmod-popup-wrap').removeClass().addClass(type);
|
||||
$('#cwmod-popup-text').html(text);
|
||||
@@ -408,6 +415,7 @@ function showCwmodPopup(type, text) {
|
||||
}
|
||||
}
|
||||
|
||||
// Initializes the moon-age calculator form and date conversions.
|
||||
function moonCalc() {
|
||||
if (!$('#info').length) return;
|
||||
addCSS(`.calc-error { color: darkred; }`);
|
||||
@@ -478,10 +486,12 @@ function moonCalc() {
|
||||
});
|
||||
}
|
||||
|
||||
// Returns the grammatically correct Russian word for a moon count.
|
||||
function updateMoonWord(moons) {
|
||||
$('#moon-word').html(declOfNum(moons, ['луна', 'луны', 'лун']));
|
||||
}
|
||||
|
||||
// Calculates elapsed moon cycles between two calendar dates.
|
||||
function getMoonsFromDate(birthDateString, dateString) {
|
||||
const birthday = Date.parse(birthDateString);
|
||||
const date = Date.parse(dateString);
|
||||
@@ -489,6 +499,7 @@ function getMoonsFromDate(birthDateString, dateString) {
|
||||
return 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));
|
||||
|
||||
Reference in new issue
Block a user