1
+ /* global $,Materialize*/
1
2
var enableToggleElement = document . getElementById ( "enable" ) ;
2
3
var githubUsernameElement = document . getElementById ( "githubUsername" ) ;
4
+ var lastWeekContributionElement = document . getElementById ( "lastWeekContribution" ) ;
3
5
var startingDateElement = document . getElementById ( "startingDate" ) ;
4
6
var endingDateElement = document . getElementById ( "endingDate" ) ;
5
7
var showOpenLabelElement = document . getElementById ( "showOpenLabel" ) ;
@@ -8,7 +10,7 @@ var userReasonElement = document.getElementById("userReason");
8
10
9
11
function handleBodyOnLoad ( ) {
10
12
// prefill name
11
- chrome . storage . local . get ( [ "githubUsername" , "enableToggle" , "startingDate" , "endingDate" , "showOpenLabel" , "showClosedLabel" , "userReason" ] , function ( items ) {
13
+ chrome . storage . local . get ( [ "githubUsername" , "enableToggle" , "startingDate" , "endingDate" , "showOpenLabel" , "showClosedLabel" , "userReason" , "lastWeekContribution" ] , function ( items ) {
12
14
if ( items . githubUsername ) {
13
15
githubUsernameElement . value = items . githubUsername ;
14
16
}
@@ -42,6 +44,14 @@ function handleBodyOnLoad(){
42
44
if ( items . userReason ) {
43
45
userReasonElement . value = items . userReason ;
44
46
}
47
+ if ( items . lastWeekContribution ) {
48
+ lastWeekContributionElement . checked = items . lastWeekContribution ;
49
+ handleLastWeekContributionChange ( ) ;
50
+ }
51
+ else if ( items . lastWeekContribution !== false ) {
52
+ lastWeekContributionElement . checked = true ;
53
+ handleLastWeekContributionChange ( ) ;
54
+ }
45
55
} ) ;
46
56
}
47
57
function handleEnableChange ( ) {
@@ -56,6 +66,42 @@ function handleEndingDateChange(){
56
66
var value = endingDateElement . value ;
57
67
chrome . storage . local . set ( { "endingDate" : value } ) ;
58
68
}
69
+ function handleLastWeekContributionChange ( ) {
70
+ var value = lastWeekContributionElement . checked ;
71
+ if ( value ) {
72
+ startingDateElement . disabled = true ;
73
+ endingDateElement . disabled = true ;
74
+ endingDateElement . value = getToday ( ) ;
75
+ startingDateElement . value = getLastWeek ( ) ;
76
+ handleEndingDateChange ( ) ;
77
+ handleStartingDateChange ( ) ;
78
+ }
79
+ else {
80
+ startingDateElement . disabled = false ;
81
+ endingDateElement . disabled = false ;
82
+ }
83
+ chrome . storage . local . set ( { "lastWeekContribution" : value } ) ;
84
+ }
85
+ function getLastWeek ( ) {
86
+ var today = new Date ( ) ;
87
+ var lastWeek = new Date ( today . getFullYear ( ) , today . getMonth ( ) , today . getDate ( ) - 7 ) ;
88
+ var lastWeekMonth = lastWeek . getMonth ( ) + 1 ;
89
+ var lastWeekDay = lastWeek . getDate ( ) ;
90
+ var lastWeekYear = lastWeek . getFullYear ( ) ;
91
+ var lastWeekDisplayPadded = ( "0000" + lastWeekYear . toString ( ) ) . slice ( - 4 ) + "-" + ( "00" + lastWeekMonth . toString ( ) ) . slice ( - 2 ) + "-" + ( "00" + lastWeekDay . toString ( ) ) . slice ( - 2 ) ;
92
+ return lastWeekDisplayPadded ;
93
+ }
94
+ function getToday ( ) {
95
+ var today = new Date ( ) ;
96
+ var Week = new Date ( today . getFullYear ( ) , today . getMonth ( ) , today . getDate ( ) ) ;
97
+ var WeekMonth = Week . getMonth ( ) + 1 ;
98
+ var WeekDay = Week . getDate ( ) ;
99
+ var WeekYear = Week . getFullYear ( ) ;
100
+ var WeekDisplayPadded = ( "0000" + WeekYear . toString ( ) ) . slice ( - 4 ) + "-" + ( "00" + WeekMonth . toString ( ) ) . slice ( - 2 ) + "-" + ( "00" + WeekDay . toString ( ) ) . slice ( - 2 ) ;
101
+ return WeekDisplayPadded ;
102
+ }
103
+
104
+
59
105
function handleGithubUsernameChange ( ) {
60
106
var value = githubUsernameElement . value ;
61
107
chrome . storage . local . set ( { "githubUsername" : value } ) ;
@@ -82,6 +128,7 @@ enableToggleElement.addEventListener("change", handleEnableChange);
82
128
githubUsernameElement . addEventListener ( "keyup" , handleGithubUsernameChange ) ;
83
129
startingDateElement . addEventListener ( "keyup" , handleStartingDateChange ) ;
84
130
endingDateElement . addEventListener ( "keyup" , handleEndingDateChange ) ;
131
+ lastWeekContributionElement . addEventListener ( "change" , handleLastWeekContributionChange ) ;
85
132
showOpenLabelElement . addEventListener ( "change" , handleOpenLabelChange ) ;
86
133
showClosedLabelElement . addEventListener ( "change" , handleClosedLabelChange ) ;
87
134
userReasonElement . addEventListener ( "keyup" , handleUserReasonChange ) ;
0 commit comments