Created
March 26, 2018 15:57
-
-
Save peruihkxt/aefe83db2b62f822770ad772bbd02f76 to your computer and use it in GitHub Desktop.
TSheets - Round Payroll Report
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
// ==UserScript== | |
// @name Round Payroll Report | |
// @namespace http://jlee.in | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://jdlee.tsheets.com/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
window.first_observer = new MutationObserver(function (mutations) { | |
jQuery.each(mutations, function(i, m) { | |
jQuery.each(m.addedNodes,function(i, addedNode) { | |
if(addedNode.id == 'reporting_payroll') { | |
if($('#reporting_payroll_round_time_button').length != 0) { | |
return; | |
} | |
var round_button_texts = ['Round to 0.25', 'Show Actual']; | |
var round_button_html = '<button class="flat primary ts-small-tooltip-bottom action-button expand" id="reporting_payroll_round_time_button" title="Round all timesheets">Round to 0.25</button>'; | |
$('#reporting_payroll_action_buttons').append(round_button_html); | |
var round_button = $('#reporting_payroll_round_time_button'); | |
round_button.click(function() { | |
var hour_holders = $('.day_hours'); | |
if(round_button.text() == round_button_texts[0]) { | |
hour_holders.each(function(index) { | |
if(this.parentElement.id == 'reporting_payroll_day_holder') { | |
return true; | |
} | |
var t = $(this); | |
t.data('original_value', t.text()); | |
t.text(Math.round(parseFloat(t.text()) * 4) / 4); | |
}); | |
round_button.text(round_button_texts[1]); | |
} else { | |
hour_holders.each(function(index) { | |
if(this.parentElement.id == 'reporting_payroll_day_holder'){ | |
return; | |
} | |
var t = $(this); | |
t.text(t.data('original_value')); | |
}); | |
round_button.text(round_button_texts[0]); | |
} | |
}); | |
} | |
}); | |
}); | |
}); | |
window.first_observer.observe(document.getElementById('window_container'), {childList: true}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment