Pikabu current seconds

Сколько прошло секунд?

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Pikabu current seconds
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Сколько прошло секунд?
// @author       hant0508
// @match        http://pikabu.ru/story/*
// @match        https://pikabu.ru/story/*
// @grant        none
// ==/UserScript==

function setTime(now) {
    for (var i = 0; i < comments.length; ++i)
    {
        var time = now - seconds[i];
        var sec = ' секунд';
        var end = ' назад';

        if (time % 100 < 10 || time % 100 > 20) {
            if (time % 10 == 1) sec += "a";
            else if (time % 10 < 5 && time % 10) sec += "ы";
            else end += '&ensp;';
        }
        else end += '&ensp;';

        comments[i].getElementsByClassName('current_seconds')[0].innerHTML = ' (' + time + sec + end + ')';
    }
    window.setTimeout (function(){setTime(Math.floor(Date.now()/1000));}, 5000);
}

var seconds = [];
var comments = document.getElementsByClassName('b-comment__time');
for (var i = 0; i < comments.length; ++i)
{
    seconds[i] = comments[i].getAttribute('datetime');
    comments[i].appendChild(document.createElement('span')).className='current_seconds';
}

setTime(Math.floor(Date.now()/1000));