forked from hant0508-zz/usescripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPikabu current seconds.user.js
38 lines (33 loc) · 1.19 KB
/
Pikabu current seconds.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// ==UserScript==
// @name Pikabu current seconds
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Сколько прошло секунд?
// @author hant0508
// @match http://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 += ' ';
}
else end += ' ';
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));