-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
173 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"recommendations": ["Vue.volar"] | ||
"recommendations": ["Vue.volar"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
export default defineBackground(() => { | ||
console.log('Hello background!', { id: browser.runtime.id }); | ||
console.log('Hello background!', {id: browser.runtime.id}) | ||
|
||
// Allows users to open the side panel by clicking on the action toolbar icon | ||
// @ts-expect-error: sidePanel is not typed | ||
browser.sidePanel | ||
.setPanelBehavior({ openPanelOnActionClick: true }) | ||
.catch((error: unknown) => console.error(error)); | ||
}); | ||
// Allows users to open the side panel by clicking on the action toolbar icon | ||
// @ts-expect-error: sidePanel is not typed | ||
browser.sidePanel.setPanelBehavior({openPanelOnActionClick: true}).catch((error: unknown) => console.error(error)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,111 @@ | ||
import dayjs from 'dayjs'; | ||
import duration from 'dayjs/plugin/duration'; | ||
import relativeTime from 'dayjs/plugin/relativeTime'; | ||
import dayjs from 'dayjs' | ||
import duration from 'dayjs/plugin/duration' | ||
import relativeTime from 'dayjs/plugin/relativeTime' | ||
|
||
export type TimeLogType = [number, number, string, boolean]; | ||
export type TimeLogsType = TimeLogType[]; | ||
export type TimeLogType = [number, number, string, boolean] | ||
export type TimeLogsType = TimeLogType[] | ||
|
||
export function parseTimeLog(log: string) { | ||
if (log === '' || log === '[]') { | ||
return []; | ||
return [] | ||
} | ||
|
||
const defaultRow: TimeLogsType = [[0, 0, '', true]]; | ||
const parsed: TimeLogsType = JSON.parse(log); | ||
const defaultRow: TimeLogsType = [[0, 0, '', true]] | ||
const parsed: TimeLogsType = JSON.parse(log) | ||
|
||
if (!parsed.length) { | ||
return defaultRow; | ||
return defaultRow | ||
} | ||
|
||
return parsed; | ||
return parsed | ||
} | ||
|
||
export function calculateHours(log: string, includeRunning = false) { | ||
const times = parseTimeLog(log); | ||
const times = parseTimeLog(log) | ||
|
||
let seconds = 0; | ||
let seconds = 0 | ||
|
||
for (const [start, finish] of times) { | ||
if (start > finish && !includeRunning) { | ||
continue; | ||
continue | ||
} | ||
|
||
const finishTime = finish !== 0 ? finish : Math.floor(Date.now() / 1000); | ||
const durationInSeconds = finishTime - start; | ||
const finishTime = finish !== 0 ? finish : Math.floor(Date.now() / 1000) | ||
const durationInSeconds = finishTime - start | ||
|
||
seconds += Math.max(durationInSeconds, 0); | ||
seconds += Math.max(durationInSeconds, 0) | ||
} | ||
|
||
const totalHours = Math.floor(seconds / 3600); | ||
const totalMinutes = Math.floor((seconds % 3600) / 60); | ||
const totalSecondsRemaining = seconds % 60; | ||
const totalHours = Math.floor(seconds / 3600) | ||
const totalMinutes = Math.floor((seconds % 3600) / 60) | ||
const totalSecondsRemaining = seconds % 60 | ||
|
||
if (totalHours < 24) { | ||
return `${totalHours}:${totalMinutes | ||
.toString() | ||
.padStart(2, '0')}:${totalSecondsRemaining.toString().padStart(2, '0')}`; | ||
return `${totalHours}:${totalMinutes.toString().padStart(2, '0')}:${totalSecondsRemaining.toString().padStart(2, '0')}` | ||
} | ||
|
||
return `${totalHours}h`; | ||
return `${totalHours}h` | ||
} | ||
|
||
interface CalculateTimeOptions { | ||
inSeconds?: boolean; | ||
calculateLastTimeLog?: boolean; | ||
inSeconds?: boolean | ||
calculateLastTimeLog?: boolean | ||
} | ||
|
||
export function calculateTime(log: string, options?: CalculateTimeOptions) { | ||
const times = parseTimeLog(log); | ||
dayjs.extend(duration); | ||
dayjs.extend(relativeTime); | ||
const times = parseTimeLog(log) | ||
dayjs.extend(duration) | ||
dayjs.extend(relativeTime) | ||
|
||
let seconds = 0; | ||
let seconds = 0 | ||
|
||
if (options?.calculateLastTimeLog) { | ||
const lastLogIndex = times.length - 1; | ||
const lastLogIndex = times.length - 1 | ||
|
||
const start = times[lastLogIndex][0]; | ||
const startTime = start ? dayjs.unix(start) : dayjs(); | ||
const start = times[lastLogIndex][0] | ||
const startTime = start ? dayjs.unix(start) : dayjs() | ||
|
||
seconds += dayjs().diff(startTime, 'seconds'); | ||
seconds += dayjs().diff(startTime, 'seconds') | ||
} else { | ||
times.map(([start, stop]) => { | ||
const startTime = start ? dayjs.unix(start) : dayjs(); | ||
const stopTime = stop ? dayjs.unix(stop) : dayjs(); | ||
const startTime = start ? dayjs.unix(start) : dayjs() | ||
const stopTime = stop ? dayjs.unix(stop) : dayjs() | ||
|
||
seconds += stopTime.diff(startTime, 'seconds'); | ||
}); | ||
seconds += stopTime.diff(startTime, 'seconds') | ||
}) | ||
} | ||
|
||
if (options?.inSeconds) { | ||
return seconds.toString(); | ||
return seconds.toString() | ||
} | ||
|
||
return seconds > 86400 | ||
? dayjs.duration(seconds, 'seconds').humanize() | ||
: dayjs.duration(seconds, 'seconds').format('HH:mm:ss'); | ||
return seconds > 86400 ? dayjs.duration(seconds, 'seconds').humanize() : dayjs.duration(seconds, 'seconds').format('HH:mm:ss') | ||
} | ||
|
||
export function calculateDifferenceBetweenLogs(log: string, logIndex: number) { | ||
const times = parseTimeLog(log); | ||
const logTimes = times[logIndex]; | ||
const times = parseTimeLog(log) | ||
const logTimes = times[logIndex] | ||
|
||
const start = logTimes ? dayjs.unix(logTimes[0]) : dayjs(); | ||
const end = logTimes ? dayjs.unix(logTimes[1]) : dayjs(); | ||
const start = logTimes ? dayjs.unix(logTimes[0]) : dayjs() | ||
const end = logTimes ? dayjs.unix(logTimes[1]) : dayjs() | ||
|
||
const seconds = end.diff(start, 'seconds'); | ||
const seconds = end.diff(start, 'seconds') | ||
|
||
return new Date(seconds * 1000).toISOString().slice(11, 19); | ||
return new Date(seconds * 1000).toISOString().slice(11, 19) | ||
} | ||
|
||
export const isTaskRunning = (task): boolean => { | ||
let running = false; | ||
let running = false | ||
|
||
parseTimeLog(task.time_log).forEach(([, stop]) => { | ||
if (stop === 0) { | ||
running = true; | ||
running = true | ||
} | ||
}); | ||
}) | ||
|
||
return running; | ||
}; | ||
return running | ||
} | ||
|
||
export function capitalizeFirstLetter(string: string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); | ||
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": "./.wxt/tsconfig.json" | ||
"extends": "./.wxt/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.