-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.js
52 lines (38 loc) · 1.03 KB
/
button.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict"
function createButtons() {
$("span.actionButtonLabel").each(function(i, span) {
if (span.innerText === "Submit") {
var $button = $("<button type='button'>FreeAgent Invoice</button>")
.click(onClick)
$(span).parent().parent()
.prepend($button)
}
})
}
function onClick() {
var timesheet = retrieveTimesheet()
console.log(timesheet)
}
function retrieveTimesheet() {
var $table = $("table.dayAsColumnEntryTable").eq(1)
, totalDaysWorked = parseInt($table.find("td:last").text())
, friday = $table.find("th").eq(6).text()
, fridayDate = retrieveDate(friday)
return {
days: totalDaysWorked,
weekEndDate: fridayDate
}
}
/**
* Retrieves a date object from a string such as "Fri 01/06/15"
*/
function retrieveDate(str) {
str = str.substr(4)
var dateParts = str.split("/")
, day = parseInt(dateParts[0])
, month = parseInt(dateParts[1]) - 1
, year = parseInt("20" + dateParts[2])
, date = new Date(year, month, day)
return date
}
createButtons()