Created
March 1, 2018 05:55
-
-
Save mohdsayed/9a968acbe677e278811021bd9428ed6d to your computer and use it in GitHub Desktop.
ac-injector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function( $ ){ | |
class ACExtenstion { | |
constructor() { | |
this.$timeGroups = $( '.tracking_objects_list_group' ); | |
this.addTotal() | |
} | |
addTotal() { | |
const _this = this; | |
this.$timeGroups.each( function() { | |
let $group = $( this ); | |
let $groupObjects = $group.find( '.tracking_objects_list_group_object' ); | |
let totalMinutes = 0; | |
$groupObjects.each( function() { | |
let $groupObject = $( this ); | |
let time = $groupObject.find( '.tracking_object_value' ).find( 'span' ).text(); | |
if ( time ) { | |
const timeInMinute = _this.convertToMinutes( time ); | |
totalMinutes += timeInMinute; | |
} | |
} ); | |
$group.append( `<p><strong>Total: ${ _this.getTotalHours( totalMinutes ) } </strong></p>` ); | |
} ); | |
} | |
getTotalHours( minutes ) { | |
let totalHours = Math.floor( minutes/60 ); | |
let totalMinutes = minutes % 60; | |
totalHours = totalHours > 9 ? totalHours : '0' + totalHours; | |
totalMinutes = totalMinutes > 9 ? totalMinutes : '0' + totalMinutes; | |
return totalHours + ':' + totalMinutes; | |
} | |
convertToMinutes( time ) { | |
const timeSplit = time.split( ':' ); | |
const hours = parseInt( timeSplit[0], 10 ); | |
const minutes = parseInt( timeSplit[1], 10 ); | |
return ( hours * 60 ) + minutes; | |
} | |
} | |
new ACExtenstion(); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment