Skip to content

Commit 23f991e

Browse files
committed
feat: Added config.js script for easier secret handling
1 parent b257b26 commit 23f991e

File tree

6 files changed

+67
-51
lines changed

6 files changed

+67
-51
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore ./js/config.js file
2+
js/config.js

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@ Automatically logs:
5757
To set up the project, follow these steps:
5858

5959
1. Clone the repository.
60-
2. Create a new Google Sheet.
61-
3. Insert the following headers in the first row: `Date`, `Start time`, `End time`, `Gross working time`, `Break time`, `Net working time`, `Difference target / actual`.
62-
4. In cell `H:1`, insert the calculation of your time credit: `=SUM(G:G;G1)`.
63-
5. Delete all empty rows.
64-
6. In Google Sheet, go to `Extensions` -> `Apps Script`.
65-
7. Paste the contents of `./js/apps_script.js` into the editor.
66-
8. In the Apps Script Editor, update the `SPREADSHEET_ID` variable with the ID of your Google Sheet (part of the URL).
67-
9. Deploy the script as a web app by clicking the `Deploy` button and selecting `New deployment`.
68-
10. Copy the URL of the web application and update the `APPS_SCRIPT_URL` variable in `./js/script.js` with this URL.
69-
11. (Optional) Customize the `PLANNED_WORK_DAY_HOURS`, `FIRST_BREAK_THRESHOLD_HOURS`, `FIRST_BREAK_MINUTES`, `SECOND_BREAK_THRESHOLD_HOURS` and `SECOND_BREAK_MINUTES` variables in `./js/script.js` to fit your needs.
70-
12. (Optional) Copy the files (except `./screenshots/` and `README.md`) to a web server of your choice.
71-
13. Visit the web server's URL in your browser OR open the `index.html` file in your browser.
72-
14. Start tracking your working hours by clicking the `Start` button. A new row will be added to your Google Sheet with the current date and time.
73-
15. Click the `Stop` button to stop tracking your working hours. The end time will be added to the row in your Google Sheet.
60+
2. Copy `./js/config.template.js` to `./js/config.js`
61+
3. Create a new Google Sheet.
62+
4. Insert the following headers in the first row: `Date`, `Start time`, `End time`, `Gross working time`, `Break time`, `Net working time`, `Difference target / actual`.
63+
5. In cell `H:1`, insert the calculation of your time credit: `=SUM(G:G;G1)`.
64+
6. Delete all empty rows.
65+
7. In Google Sheet, go to `Extensions` -> `Apps Script`.
66+
8. Paste the contents of `./js/apps_script.js` into the editor.
67+
9. In the Apps Script Editor, update the `SPREADSHEET_ID` variable with the ID of your Google Sheet (part of the URL).
68+
10. Deploy the script as a web app by clicking the `Deploy` button and selecting `New deployment`.
69+
11. Copy the URL of the web application and update the `APPS_SCRIPT_URL` in `./js/config.js` with your URL.
70+
12. (Optional) Customize the `PLANNED_WORK_DAY_HOURS`, `FIRST_BREAK_THRESHOLD_HOURS`, `FIRST_BREAK_MINUTES`, `SECOND_BREAK_THRESHOLD_HOURS` and `SECOND_BREAK_MINUTES` variables in `./js/config.js` to fit your needs.
71+
13. (Optional) Copy the files (except `./screenshots/` and `README.md`) to a (static) web server of your choice.
72+
14. Visit the web server's URL in your browser OR open the `index.html` file directly in your browser.
73+
15. Start tracking your working hours by clicking the `Start` button. A new row will be added to your Google Sheet with the current date and time.
74+
16. Click the `Stop` button to stop tracking your working hours. The end time will be added to the row in your Google Sheet.

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ <h1>Time Tracker</h1>
2222
<p id="overtimeLabel">Overtime: <span id="overtime">00:00:00</span></p>
2323
</div>
2424
</div>
25+
26+
<script src="./js/config.js"></script>
2527
<script src="./js/script.js"></script>
2628
</body>
2729

js/apps_script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function doPost(e) {
2-
const SPREADSHEET_ID = 'GOOGLE_SPREADSHEET_ID';
2+
const SPREADSHEET_ID = 'YOUR_GOOGLE_SPREADSHEET_ID';
33
const spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
44
const currentYear = new Date().getFullYear();
55
const sheetName = currentYear.toString();

js/config.template.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* URL for the Google Apps Script endpoint
3+
* @constant {string}
4+
*/
5+
export const APPS_SCRIPT_URL = 'YOUR_APPS_SCRIPT_URL';
6+
7+
/**
8+
* Number of hours in a planned work day
9+
* @constant {number}
10+
*/
11+
export const PLANNED_WORK_DAY_HOURS = 8;
12+
13+
/**
14+
* Hour threshold when first break becomes mandatory
15+
* @constant {number}
16+
*/
17+
export const FIRST_BREAK_THRESHOLD_HOURS = 6;
18+
19+
/**
20+
* Duration of first mandatory break in minutes
21+
* @constant {number}
22+
*/
23+
export const FIRST_BREAK_MINUTES = 30;
24+
25+
/**
26+
* Hour threshold when second break becomes mandatory
27+
* @constant {number}
28+
*/
29+
export const SECOND_BREAK_THRESHOLD_HOURS = 9;
30+
31+
/**
32+
* Duration of second mandatory break in minutes
33+
* @constant {number}
34+
*/
35+
export const SECOND_BREAK_MINUTES = 15;

js/script.js

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
/**
2-
* URL for the Google Apps Script endpoint
3-
* @constant {string}
4-
*/
5-
const APPS_SCRIPT_URL = 'APPS_SCRIPT_URL';
6-
7-
/**
8-
* Number of hours in a planned work day
9-
* @constant {number}
10-
*/
11-
const PLANNED_WORK_DAY_HOURS = 8;
12-
13-
/**
14-
* Hour threshold when first break becomes mandatory
15-
* @constant {number}
16-
*/
17-
const FIRST_BREAK_THRESHOLD_HOURS = 6;
18-
19-
/**
20-
* Duration of first mandatory break in minutes
21-
* @constant {number}
22-
*/
23-
const FIRST_BREAK_MINUTES = 30;
24-
25-
/**
26-
* Hour threshold when second break becomes mandatory
27-
* @constant {number}
28-
*/
29-
const SECOND_BREAK_THRESHOLD_HOURS = 9;
30-
31-
/**
32-
* Duration of second mandatory break in minutes
33-
* @constant {number}
34-
*/
35-
const SECOND_BREAK_MINUTES = 15;
36-
371
/**
382
* State variables for tracking time and intervals
393
* @type {Date} startTime - Work start timestamp
@@ -47,10 +11,22 @@ let startTime, stopTime, countdownInterval, overtimeInterval;
4711
* Initialize app when DOM content is loaded
4812
*/
4913
document.addEventListener('DOMContentLoaded', () => {
14+
checkAppsScriptUrl();
5015
loadStoredTimes();
5116
addEventListeners();
5217
});
5318

19+
/**
20+
* Check if APPS_SCRIPT_URL has been changed from default value
21+
* @throws {Error} If URL has not been changed from default
22+
*/
23+
function checkAppsScriptUrl() {
24+
if (APPS_SCRIPT_URL === 'YOUR_APPS_SCRIPT_URL') {
25+
alert('Please update the APPS_SCRIPT_URL constant with your Google Apps Script deployment URL');
26+
console.error('APPS_SCRIPT_URL not configured');
27+
}
28+
}
29+
5430
/**
5531
* Load and process stored start/stop times from localStorage
5632
*/

0 commit comments

Comments
 (0)