| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Time Tracker | leemorgan.io</title>
- <style>
- *{margin:0;padding:0;}
- body{
- display: flex;
- flex-direction: column;
- max-width: 500px;
- }
- body > *{margin: 15px;}
- </style>
- </head>
- <body>
- <input id="name" type="text" placeholder="NAME">
- <input id="project" type="text" placeholder="PROJECT">
- <textarea id="description" placeholder="DESCRIPTION"></textarea>
- <button id="startStop" onclick="startStop()">Start</button>
- <button id="pause" style="display:none">Pause</button>
- <script>
- let tracker = null
- let startStop = ()=>{
- if(!tracker){
- let time = new Date();
- fetch("/tracker", {
- method: "post",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- name: document.getElementById("name").value,
- project: document.getElementById("project").value,
- description: document.getElementById("description").value,
- start: time
- })
- })
- .then(r=>r.json())
- .then((response)=>{
- if(typeof(response) === "string"){
- }else{
- document.getElementById("startStop").innerText = "Stop";
- document.getElementById("pause").style.display = "block";
- tracker = response;
- }
- }).catch((err)=>{
- console.error(err);
- });
- }else{
- let time = new Date();
- fetch("/tracker", {
- method: "put",
- headers: {
- "Content-Type": "application/json"
- },
- body: JSON.stringify({
- id: tracker._id,
- end: time
- })
- })
- .then(r=>r.json())
- .then((response)=>{
- document.getElementById("startStop").innerText = "Start";
- document.getElementById("pause").style.display = "none";
- tracker = null;
- })
- .catch((err)=>{
- console.error(err);
- });
- }
- }
- </script>
- </body>
- </html>
|