Skip to content

Instantly share code, notes, and snippets.

@RayTwitty
Created August 12, 2018 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RayTwitty/d7226a39decf03823cb154103aad5a91 to your computer and use it in GitHub Desktop.
Save RayTwitty/d7226a39decf03823cb154103aad5a91 to your computer and use it in GitHub Desktop.
Подсчитывает время всех задач на странице.
console.log('Скрипт запущен. Результат будет через 5 секунд.');
setTimeout(function() {
var list = $('.timespent');
var total_time = 0; // minutes
var hour = 60;
var day = 8 * hour;
var week = 5 * day;
list.each(function() {
var text = $(this).html();
if (text.length) {
var arr = text.split(',');
arr.forEach(function(value) {
value = value.trim().split(' ');
var time = parseInt(value[0]);
var type = value[1].charAt(0);
switch (type) {
case 'm':
total_time += time;
break;
case 'h':
total_time += time * hour;
break;
case 'd':
total_time += time * day;
break;
case 'w':
total_time += time * week;
break;
}
});
}
});
function getDecimal(num) {
return num - Math.floor(num);
}
total_time /= hour;
var hours = parseInt(total_time);
var minutes = parseInt(hour * getDecimal(total_time));
console.log(
`Всего на текущей странице: ${hours} ч. ${minutes} м. (${total_time.toFixed(2)} ч.)`
);
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment