feat: extract work hours

This commit is contained in:
Pihkaal
2025-11-05 14:37:29 +01:00
parent 25c5a1b4bf
commit 273c420b4e

View File

@@ -4,7 +4,8 @@ import { ref } from "vue";
type WorkEvent = { type WorkEvent = {
day: number; day: number;
work: boolean; start: { hours: number; minutes: number };
end: { hours: number; minutes: number };
}; };
const data = ref<{ const data = ref<{
@@ -25,7 +26,7 @@ async function extractData() {
} }
const urlMatch = tab.url?.match(/\/(\d{2})-(\d{4})$/); const urlMatch = tab.url?.match(/\/(\d{2})-(\d{4})$/);
if (!urlMatch?.[1] || !urlMatch[2]) { if (!urlMatch) {
console.error("Could not extract month and year from URL"); console.error("Could not extract month and year from URL");
return null; return null;
} }
@@ -39,16 +40,25 @@ async function extractData() {
for (const tr of trs) { for (const tr of trs) {
const tds = tr.querySelectorAll("td"); const tds = tr.querySelectorAll("td");
const dateText = tds[0]?.textContent?.trim() ?? "";
const dateText = tds[0]?.textContent?.trim() ?? "";
const dateMatch = dateText.match(/^[A-Z][a-z]{2}\s+(\d{2})$/); const dateMatch = dateText.match(/^[A-Z][a-z]{2}\s+(\d{2})$/);
if (!dateMatch) continue; if (!dateMatch) continue;
const workText = tds[1]?.textContent?.trim() ?? ""; const workText = tds[1]?.textContent?.trim() ?? "";
const hoursMatch = workText.match(/^(\d+):(\d+) - (\d+):(\d+)$/);
if (!hoursMatch) continue;
events.push({ events.push({
day: parseInt(dateMatch[1]!), day: parseInt(dateMatch[1]!),
work: /^\d+:\d+ - \d+:\d+$/.test(workText), start: {
hours: parseInt(hoursMatch[1]!),
minutes: parseInt(hoursMatch[2]!),
},
end: {
hours: parseInt(hoursMatch[3]!),
minutes: parseInt(hoursMatch[4]!),
},
}); });
} }
@@ -58,15 +68,15 @@ async function extractData() {
if (!eventsQuery?.result) return null; if (!eventsQuery?.result) return null;
data.value = { data.value = {
year: parseInt(urlMatch[2]!),
month: parseInt(urlMatch[1]!),
events: eventsQuery.result, events: eventsQuery.result,
month: parseInt(urlMatch[1]),
year: parseInt(urlMatch[2]),
}; };
return { return {
year: parseInt(urlMatch[2]!),
month: parseInt(urlMatch[1]!),
events: eventsQuery.result, events: eventsQuery.result,
month: parseInt(urlMatch[1]),
year: parseInt(urlMatch[2]),
}; };
} catch (error) { } catch (error) {
console.error("Error getting elements data:", error); console.error("Error getting elements data:", error);