Skip to content

Commit d300515

Browse files
ritik48rickstaaqwerty541
authored andcommitted
feat: show wakatime stats in percentage (resolves anuraghazra#3016) (anuraghazra#3326)
* added option to display wakatime in percentage * updated exclusive options in wakatime * added percent sign * Update readme.md Co-authored-by: Rick Staa <rick.staa@outlook.com> * made the required changes * Update wakatime-card.js * Update wakatime-card.js --------- Co-authored-by: Rick Staa <rick.staa@outlook.com> Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
1 parent 2a84a12 commit d300515

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

api/wakatime.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const handler = async (req, res, env) => {
3131
api_domain,
3232
border_radius,
3333
border_color,
34+
display_format,
3435
disable_animations,
3536
} = req.query;
3637

@@ -89,6 +90,7 @@ export const handler = async (req, res, env) => {
8990
locale: locale ? locale.toLowerCase() : null,
9091
layout,
9192
langs_count,
93+
display_format,
9294
disable_animations: parseBoolean(disable_animations),
9395
}),
9496
);

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ If we don't support your language, please consider contributing! You can find mo
423423
- `layout` - Switches between two available layouts `default` & `compact`. Default `default`.
424424
- `langs_count` - Limits the number of languages on the card, defaults to all reported languages *(number)*.
425425
- `api_domain` - Sets a custom API domain for the card, e.g. to use services like [Hakatime](https://github.com/mujx/hakatime) or [Wakapi](https://github.com/muety/wakapi) *(string)*. Default `Waka API`.
426+
- `display_format` - Sets the WakaTime stats display format. Choose `time` to display time-based stats or `percent` to show percentages. Default: `time`.
426427
- `disable_animations` - Disables all animations in the card *(boolean)*. Default: `false`.
427428

428429
***

src/cards/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type WakaTimeOptions = CommonOptions & {
5454
custom_title: string;
5555
layout: "compact" | "normal";
5656
langs_count: number;
57+
display_format: "time" | "percent";
5758
disable_animations: boolean;
5859
};
5960

src/cards/wakatime-card.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
225225
langs_count = languages.length,
226226
border_radius,
227227
border_color,
228+
display_format = "time",
228229
disable_animations,
229230
} = options;
230231

@@ -338,7 +339,10 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
338339
return createTextNode({
339340
id: language.name,
340341
label: language.name,
341-
value: language.text,
342+
value:
343+
display_format === "percent"
344+
? `${language.percent.toFixed(2).toString()} %`
345+
: language.text,
342346
index,
343347
percent: language.percent,
344348
// @ts-ignore

0 commit comments

Comments
 (0)