Pikabu current seconds

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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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));