diff --git a/.gitignore b/.gitignore index 2a3c60e..8553ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,3 @@ bin/ # vweb and database *.db -*.js diff --git a/static/index.js b/static/index.js new file mode 100644 index 0000000..73c9d57 --- /dev/null +++ b/static/index.js @@ -0,0 +1,23 @@ + const startDate = new Date('2019-06-20T00:00:00Z'); /* будем считать, что именно в это время был первый релиз */ + + function updateYearsPassed() { + const now = Date.now(); + const millisecondsPerYear = 1000 * 60 * 60 * 24 * 365.2425; /* учёт високосных лет */ + const yearsPassed = (now - startDate) / millisecondsPerYear; + + document.getElementById('counter').textContent = + `${yearsPassed}`; + } + + function updateYear() { + const now = new Date().getFullYear(); + years = document.getElementsByClassName("year") + for (year in years) { + year.textContent = ` ${now} `} +} + + updateYearsPassed(); /* сразу при загрузке */ + updateYear(); + setInterval(updateYearsPassed, 10); + setInterval(updateYear, 10000); + /* код написал чат гопоты, мне осталось лишь подправить. Каюсь, гречневая */