Skip to content

Commit

Permalink
Merge branch 'main' into mv2
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepzh committed Oct 17, 2023
2 parents 3fc1fa9 + 87739f3 commit df3ecd2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timer",
"version": "1.9.5",
"version": "1.9.6",
"description": "Web timer",
"homepage": "https://github.com/sheepzh/timer",
"scripts": {
Expand Down Expand Up @@ -68,4 +68,4 @@
"engines": {
"node": ">=16"
}
}
}
15 changes: 15 additions & 0 deletions script/zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

FOLDER=$(cd "$(dirname "$0")/.."; pwd)
TARGET_PATH="${FOLDER}/aaa"

tar -zcvf ${TARGET_PATH} \
--exclude=dist*/ \
--exclude=.git/ \
--exclude=package-lock.json \
--exclude=node_modules \
--exclude=firefox_dev*/ \
--exclude=market_packages \
--exclude=aaa \
./

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

import { fillExist } from "@service/components/import-processor"
import { AUTHOR_EMAIL } from "@src/package"
import { isBrowserUrl } from "@util/pattern"

export type OtherExtension = "webtime_tracker" | "web_activity_time_tracker"
export type OtherExtension =
| "webtime_tracker"
| "web_activity_time_tracker"
| "history_trends_unlimited"

const throwError = () => { throw new Error("Failed to parse, please check your file or contact the author via " + AUTHOR_EMAIL) }

Expand All @@ -29,6 +33,9 @@ export async function parseFile(ext: OtherExtension, file: File): Promise<timer.
} else if (ext === 'webtime_tracker') {
rows = await parseWebtimeTracker(file)
focus = true
} else if (ext === 'history_trends_unlimited') {
rows = await parseHistoryTrendsUnlimited(file)
time = true
}
await fillExist(rows)
return { rows, focus, time }
Expand Down Expand Up @@ -102,6 +109,33 @@ async function parseWebtimeTracker(file: File): Promise<timer.imported.Row[]> {
throw new Error("Invalid file format")
}

async function parseHistoryTrendsUnlimited(file: File): Promise<timer.imported.Row[]> {
const text = await file.text()
if (isTsvFile(file)) {
const lines = text.split('\n').map(line => line.trim()).filter(line => !!line)
const dailyVisits: { [dateAndHost: string]: number } = {}
lines.forEach(line => {
const cells = line.split('\t')
const url = cells[0]
if (isBrowserUrl(url)) return
const host = cells[1]
const dateStr = cells[4]
const date = cvtWebtimeTrackerDate(dateStr?.substring(0, 10))
if (!host || !date) return
const key = date + host
dailyVisits[key] = (dailyVisits[key] ?? 0) + 1
})
return Object.entries(dailyVisits).map(([dateAndHost, time]) => {
const date = dateAndHost.substring(0, 8)
const host = dateAndHost.substring(8)
return { date, host, time }
})
}
throw new Error("Invalid file format")
}

const isJsonFile = (file: File): boolean => file?.type?.startsWith('application/json')

const isCsvFile = (file: File): boolean => file?.type?.startsWith('text/csv')

const isTsvFile = (file: File): boolean => file?.type?.startsWith('text/tab-separated-values')
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import { OtherExtension, parseFile } from "./processor"

const OTHER_NAMES: { [ext in OtherExtension]: string } = {
webtime_tracker: "Webtime Tracker",
web_activity_time_tracker: "Web Activity Time Tracker"
web_activity_time_tracker: "Web Activity Time Tracker",
history_trends_unlimited: "History Trends Unlimited",
}

const OTHER_FILE_FORMAT: { [ext in OtherExtension]: string } = {
webtime_tracker: '.csv,.json',
web_activity_time_tracker: '.csv',
history_trends_unlimited: '.tsv',
}

const ALL_TYPES: OtherExtension[] = Object.keys(OTHER_NAMES) as OtherExtension[]
Expand Down

0 comments on commit df3ecd2

Please sign in to comment.