kolobdur74 написал(а):
Ну, вот скриптом:
Код:<script> $(function(){ /* ===== НАСТРОЙКИ ===== */ const usersBirthdays = { 1648: '1929-07-19' }; /* ===================== */ /* расчет возраста */ function getAge(dateStr){ const birth = new Date(dateStr); const today = new Date(); let age = today.getFullYear() - birth.getFullYear(); const m = today.getMonth() - birth.getMonth(); if (m < 0 || (m === 0 && today.getDate() < birth.getDate())) { age--; } return age; } /* обработка постов */ $('[data-user-id]').each(function(){ const userId = $(this).data('user-id'); if(!usersBirthdays[userId]) return; const birth = usersBirthdays[userId]; const age = getAge(birth); /* поле в посте */ $(this).find('.pa-age').html( '<span class="fld-name">Возраст:</span> ' + age + ' <span style="font-size:0.9em; vertical-align:top">[' + birth + ']</span>' ); }); /* обработка профиля */ $('#viewprofile-next').each(function(){ const cls = this.className; const match = cls.match(/id-(\d+)/); if(!match) return; const userId = match[1]; if(!usersBirthdays[userId]) return; const birth = usersBirthdays[userId]; const age = getAge(birth); $('#pa-birthdate').html( '<span>Возраст:</span> <strong>' + age + ' (' + birth + ')' + '</strong>' ); }); }); </script>Можно и нескольких пользователей менять, таким образом:
const usersBirthdays = {
1648: '1929-07-19',
25: '1990-12-14',
48: '2001-03-05'
};
- Подпись автора
Счастье каждый день!