# Hack: Calculate total amount of online time on dashboard

Signup for a free 18-days trial today

### Hack: Calculate total amount of online time on dashboard

If you would like to do some specific calculations from the timetable on the dashboard, we have an easy to use script! You can run this directly from your browser, when visiting our dashboard view.

The Javascript will display average online time per day, per week, and the total online time.

The instructions, to run the javascript, are for Google Chrome, but the steps are similar, or identical, in other browsers.

Google Chrome

1. Through the URL bar
1. Login to your cSupport account and go the the Dashboard
2. Write javascript: in the URL bar
3. Copy-paste the Javascript from the bottom of this page into the URL bar after the javascript:, and click enter!
2. Through the Javascript console
1. Login to your cSupport account and go the the Dashboard
2. Go to View menu, click Developer > Javascript Console
3. Copy-paste the Javascript from the bottom of this page, into the console’s commando line, and click enter!

Javascript

```function calculate(timetable_data)
{
var days = new Array();
for(k in timetable_data) { /* For each day */
var day_durtion_minutes = 0;
for(l in timetable_data[k]['data']){
day_durtion_minutes += calcTimeToMinutes(timetable_data[k]['data'][l]['e']) - calcTimeToMinutes(timetable_data[k]['data'][l]['s']);
}
days.push(day_durtion_minutes);
}
return days;
};
function calcTimeToMinutes(time){
var hours = time.substring(0,2);
var minutes = time.substring(3,5);
return parseInt(hours)*60 + parseInt(minutes);
};
function calcMinutesToTime(minutes){
var days = Math.floor(minutes / (60 * 24));
var hours = Math.floor(minutes % (60 * 24) / 60);
var minutes = minutes % 60;
return (days > 0 ? days + " days " : "") +  (hours > 0 ? hours + " hours " : "") + (minutes > 0 ? minutes + " minutes " : "") + (days < 1 && hours < 1 && minutes < 1 ? "N/A" : "");
};
function showTotalTime(){
var days = calculate(timetable_data), total_time = 0;
for(i in days){
total_time += days[i];
}

var text = "Total time spent: " + calcMinutesToTime(total_time) +
"\nPer week spent: " + calcMinutesToTime(Math.floor(total_time / (timetable_data.length / 7))) +
"\nPer day spent: " + calcMinutesToTime(Math.floor(total_time / timetable_data.length));
alert(text);
};
showTotalTime();```

Modifications
You should modify showTotalTime(), or create a new Javascript method, to display other data. Here is an example how to display per day online in the Javascript console:

```function showPerDayOnline(){
var days = calculate(timetable_data);
for(i in days){
var day = timetable_data[i].name;
console.log("Day "  + day + " was " + calcMinutesToTime(days[i]));
}
};
showPerDayOnline();```

View all