-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMint_Date_Range.user.js
187 lines (158 loc) · 5.36 KB
/
Mint_Date_Range.user.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// ==UserScript==
// @name Mint Date Range
// @namespace http://leftbraintinkering.blogspot.com/
// @description Query by date range in Mint
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @require http://raw.github.com/skelliam/Datejs/next/build/date-en-US.js
// @include https://wwws.mint.com/transaction.event*
// @grant GM_addStyle
// @version 1
// ==/UserScript==
//Put date pickers on the screen for start date/end date
//User selects dates
//User presses "go"
//URL is altered to add start end date
//if URL already contains start end date, it should be updated
var jStartDate = null;
var jEndDate = null;
var clrMintGreen = "#DEEFE9";
var clrMintDarkGreen = "#00C44B";
var clrPink = "#F9DEDE";
var clrWhite = "#FFFFFF";
var cssText =
"input.di {\n" +
" font-family: sans-serif;\n" +
" font-size: 0.9em;\n" +
" height: 0.9em;" +
" width: 6em;" +
"}\n\n" +
"a.dibtn {\n" +
" font-weight: bold;" +
" background-color: " + clrMintDarkGreen + ";\n" +
" border: 1px;" +
" width: 0.9em;" +
" border-radius: 3px 3px 3px 3px;" +
" border-style: outset;" +
" border-width: 1px;" +
" border-color: black;" +
" color: white;" +
" cursor: pointer;" +
" text-decoration: none;" +
"}\n\n" +
"div#account-summary {\n" +
" clear: right !important;" +
" padding: 2px;" +
"}\n\n";
function updateURL(startdate, enddate) {
//finally we actually update the URL in the browser which may force a reload
var searchstring = "";
searchstring += "?startDate=" + startdate.toString('MM/dd/yyyy');
searchstring += "&endDate=" + enddate.toString('MM/dd/yyyy');
document.location.search = searchstring;
}
function validateAndUpdateURL() {
//whenever a date is changed, validate the dates and update the URL
var startdateval = jStartDate.val();
var enddateval = jEndDate.val();
var startdate = Date.parse(startdateval);
var enddate = Date.parse(enddateval);
if ( (startdateval == "")
|| (enddateval == "")
|| (startdateval == null)
|| (enddateval == null)
)
{ /* either date blank */
if ((startdateval == "") && (enddateval == "")) {
//both dates blank by intention
updateURL("", "");
}
return;
}
else if (enddate < startdate) {
alert("End date is before start date.");
jEndDate.css("background-color", clrPink);
jEndDate.prop("title", "End date is before start date.");
return;
}
else if (startdate > enddate) {
alert("Start date is after end date.");
jStartDate.css("background-color", clrPink);
jStartDate.css("title", "Start date is after end date.");
return;
}
updateURL( startdate.toString('MM/dd/yyyy'), enddate.toString('MM/dd/yyyy') );
}
function validateDate(jObj, update) {
//pass this function the object to validate,
//as well as whether or not to update the main document URL at this time
var date = Date.parse(jObj.val());
if (date != null) {
jObj.css("background-color", clrMintGreen); //this is the Mint background color :)
jObj.prop('title', "Date OK: " + date.toString('dddd, MMMM d, yyyy'));
}
else {
if (jObj.val()=="") {
jObj.css("background-color", clrWhite); //this color indicates something wrong with the date
jObj.prop('title', "Enter a date.");
}
else {
jObj.css("background-color", clrPink); //this color indicates something wrong with the date
jObj.prop('title', "Invalid date, please fix me.");
}
}
}
function startDateChanged() {
validateDate(jStartDate, true);
}
function endDateChanged() {
validateDate(jEndDate, true);
}
function updateUI() {
//create the date pickers (jQuery syntax)
jStartDate = $("<input class='di' id='startdate' title='Enter a date.'/>");
jEndDate = $("<input class='di' id='enddate' title='Enter a date.'/>");
jGoBtn = $("<a class='di dibtn'>Go</a>");
//add events with jQuery syntax
jStartDate.change(startDateChanged);
jEndDate.change(endDateChanged);
jGoBtn.click(validateAndUpdateURL);
//find class="search-container" (jQuery syntax) and insert date fields
$(".search-container").append("<b>Start Date: </b>", jStartDate, "<b>End Date: </b>", jEndDate, jGoBtn);
}
function fillDatePickers() {
//this function will populate the date pickers with dates from the URL
if (location.search.contains('&')) {
var things = location.search.split('&');
}
else {
return;
}
for (i=0; i<things.length; i++) {
var startdate = things[i].match('startDate=(.*)');
var enddate = things[i].match('endDate=(.*)');
if (startdate != null) {
jStartDate.val(startdate[1]);
}
else if (enddate != null) {
jEndDate.val(enddate[1]);
}
}
validateDate(jStartDate, false);
validateDate(jEndDate, false);
}
function main() {
//cross-browser support added from: http://userscripts.org/groups/51
if (typeof GM_addStyle == 'undefined') {
var GM_addStyle = function(css) {
var head = document.getElementsByTagName('head')[0], style = document.createElement('style');
if (!head) return;
style.type = 'text/css';
style.textContent = css;
head.appendChild(style);
}
}
GM_addStyle( cssText );
updateUI();
fillDatePickers();
}
main();