Skip to content

Commit 07adba6

Browse files
committed
Leading zeros added to inline date/time stamps if values are below 10
1 parent 9be9c01 commit 07adba6

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Save Text to File
22

33
## Usage
4-
Firefox addon which saves highlighted text to a file in a directory (defaulting to the user's home directory)<br/>
4+
Firefox addon which saves selected text to a file in a directory (defaulting to the user's home directory).<br/>
55
Goal is to simplify note taking on web pages so users can refer to data at a later stage offline, without the need to remember URL's etc.<br/>
66
After highlighting some text, right-click and select `Save Text to File`<br/>
77
File names can have the following pre-defined formats:
@@ -23,6 +23,8 @@ File names can have the following pre-defined formats:
2323
- Set filename same as pagename
2424
- Show/hide widget icon
2525
- Optional preference confirmation panel triggered when `Save Text to File` is clicked
26+
- Option to save selected html text
27+
- Can edit text before saving
2628

2729
## Localization
2830
- Czech (cs-CZ)

lib/Chrome.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,41 @@ exports.saveTo = function(selectedText){
118118
string = '\n\n',
119119
currentTime = new Date(),
120120
date = '',
121-
time = currentTime.getHours() + "-" + currentTime.getMinutes() + "-" + currentTime.getSeconds(),
121+
time =
122+
((currentTime.getHours() < 10 ? "0" : "") + currentTime.getHours()) + "-" +
123+
((currentTime.getMinutes() < 10 ? "0" : "") + currentTime.getMinutes()) + "-" +
124+
((currentTime.getSeconds() < 10 ? "0" : "") + currentTime.getSeconds()),
122125
file = createFileObject(Preference.get('pathToFile'), filename);
123126

124127

125128
//create date format based on user's preference
126129
if (Preference.get('dateFormat') == 0){
127130

128-
date = currentTime.getDate() + "-" + (currentTime.getMonth() + 1) + "-" + currentTime.getFullYear();
131+
date =
132+
(currentTime.getDate() < 10 ? "0" : "") + currentTime.getDate() + "-" +
133+
((currentTime.getMonth() + 1) < 10 ? "0" : "") + (currentTime.getMonth() + 1) + "-" +
134+
currentTime.getFullYear();
129135

130136
}else if (Preference.get('dateFormat') == 1){
131137

132-
date = (currentTime.getMonth() + 1) + "-" + currentTime.getDate() + "-" + currentTime.getFullYear();
138+
date =
139+
((currentTime.getMonth() + 1) < 10 ? "0" : "") + (currentTime.getMonth() + 1) + "-" +
140+
(currentTime.getDate() < 10 ? "0" : "") + currentTime.getDate() + "-" +
141+
currentTime.getFullYear();
133142

134143
}else if (Preference.get('dateFormat') == 2){
135144

136-
date = currentTime.getFullYear() + "-" + (currentTime.getMonth() + 1) + "-" + currentTime.getDate();
145+
date =
146+
currentTime.getFullYear() + "-" +
147+
((currentTime.getMonth() + 1) < 10 ? "0" : "") + (currentTime.getMonth() + 1) + "-" +
148+
(currentTime.getDate() < 10 ? "0" : "") + currentTime.getDate();
137149

138150
}else if (Preference.get('dateFormat') == 3){
139151

140-
date = currentTime.getFullYear() + "-" + currentTime.getDate() + "-" + (currentTime.getMonth() + 1);
152+
date =
153+
currentTime.getFullYear() + "-" +
154+
(currentTime.getDate() < 10 ? "0" : "") + currentTime.getDate() + "-" +
155+
((currentTime.getMonth() + 1) < 10 ? "0" : "") + (currentTime.getMonth() + 1);
141156
}
142157

143158
try{

0 commit comments

Comments
 (0)