mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Add long time account and acient account Trophy
This commit is contained in:
parent
636e4437bd
commit
16c87caa4f
5 changed files with 94 additions and 46 deletions
|
|
@ -6,7 +6,10 @@ import {
|
||||||
TotalIssueTrophy,
|
TotalIssueTrophy,
|
||||||
TotalPullRequestTrophy,
|
TotalPullRequestTrophy,
|
||||||
TotalRepositoryTrophy,
|
TotalRepositoryTrophy,
|
||||||
MultipleLangTrophy
|
MultipleLangTrophy,
|
||||||
|
LongTimeAccountTrophy,
|
||||||
|
AncientAccountTrophy
|
||||||
|
|
||||||
} from "./trophies.ts";
|
} from "./trophies.ts";
|
||||||
import { UserInfo } from "./github_api_client.ts";
|
import { UserInfo } from "./github_api_client.ts";
|
||||||
import { CONSTANTS, RANK_ORDER, RANK } from "./utils.ts";
|
import { CONSTANTS, RANK_ORDER, RANK } from "./utils.ts";
|
||||||
|
|
@ -32,6 +35,8 @@ export class Card {
|
||||||
new TotalPullRequestTrophy(userInfo.totalPullRequests),
|
new TotalPullRequestTrophy(userInfo.totalPullRequests),
|
||||||
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
||||||
new MultipleLangTrophy(userInfo.languageCount),
|
new MultipleLangTrophy(userInfo.languageCount),
|
||||||
|
new LongTimeAccountTrophy(userInfo.durationYear),
|
||||||
|
new AncientAccountTrophy(userInfo.acientAccount),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Filter by hidden
|
// Filter by hidden
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ export class UserInfo {
|
||||||
public totalStargazers: number,
|
public totalStargazers: number,
|
||||||
public totalRepositories: number,
|
public totalRepositories: number,
|
||||||
public totalContributed: number,
|
public totalContributed: number,
|
||||||
public languageCount: number
|
public languageCount: number,
|
||||||
|
public durationYear: number,
|
||||||
|
public acientAccount:number
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,6 +26,7 @@ export class GithubAPIClient {
|
||||||
user(login: $username) {
|
user(login: $username) {
|
||||||
name
|
name
|
||||||
login
|
login
|
||||||
|
createdAt
|
||||||
contributionsCollection {
|
contributionsCollection {
|
||||||
totalCommitContributions
|
totalCommitContributions
|
||||||
restrictedContributionsCount
|
restrictedContributionsCount
|
||||||
|
|
@ -76,6 +79,9 @@ export class GithubAPIClient {
|
||||||
languages.add(node.languages.nodes[0].name)
|
languages.add(node.languages.nodes[0].name)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const durationTime = new Date().getTime() - new Date(userData.createdAt).getTime();
|
||||||
|
const durationYear = new Date(durationTime).getUTCFullYear() - 1970;
|
||||||
|
const acientAccount = new Date(userData.createdAt).getFullYear() <= 2010 ? 1:0;
|
||||||
const userInfo = new UserInfo(
|
const userInfo = new UserInfo(
|
||||||
totalCommits,
|
totalCommits,
|
||||||
userData.followers.totalCount,
|
userData.followers.totalCount,
|
||||||
|
|
@ -84,7 +90,9 @@ export class GithubAPIClient {
|
||||||
totalStargazers,
|
totalStargazers,
|
||||||
userData.repositories.totalCount,
|
userData.repositories.totalCount,
|
||||||
userData.repositoriesContributedTo.totalCount,
|
userData.repositoriesContributedTo.totalCount,
|
||||||
languages.size
|
languages.size,
|
||||||
|
durationYear,
|
||||||
|
acientAccount
|
||||||
)
|
)
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
54
src/icons.ts
54
src/icons.ts
|
|
@ -1,14 +1,5 @@
|
||||||
import { RANK } from "./utils.ts";
|
import { RANK, COLORS } from "./utils.ts";
|
||||||
|
|
||||||
const goldColor = "#FAD200";
|
|
||||||
const goldShadowColor = "#C8A090";
|
|
||||||
const goldTextColor = "#886000";
|
|
||||||
const silverColor = "#B0B0B0";
|
|
||||||
const sliverShadowColor = "#9090C0";
|
|
||||||
const silverTextColor = "#505050";
|
|
||||||
const bronzeColor = "#A18D66";
|
|
||||||
const bronzeShadowColor = "#816D96";
|
|
||||||
const bronzeTextColor = "#412D06";
|
|
||||||
const leafIcon =
|
const leafIcon =
|
||||||
`<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="90pt" height="90pt" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
|
`<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="90pt" height="90pt" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
|
||||||
<metadata>
|
<metadata>
|
||||||
|
|
@ -35,7 +26,6 @@ Created by potrace 1.15, written by Peter Selinger 2001-2017
|
||||||
|
|
||||||
export const getNextRankBar = (
|
export const getNextRankBar = (
|
||||||
title: string,
|
title: string,
|
||||||
color: string,
|
|
||||||
percentage: number,
|
percentage: number,
|
||||||
): string => {
|
): string => {
|
||||||
const maxWidht = 80;
|
const maxWidht = 80;
|
||||||
|
|
@ -60,7 +50,7 @@ export const getNextRankBar = (
|
||||||
width="${maxWidht}"
|
width="${maxWidht}"
|
||||||
height="3.2"
|
height="3.2"
|
||||||
opacity="0.3"
|
opacity="0.3"
|
||||||
fill="${color}"
|
fill="${COLORS.NEXT_RANK_BAR}"
|
||||||
/>
|
/>
|
||||||
<rect
|
<rect
|
||||||
id="${title}-rank-progress"
|
id="${title}-rank-progress"
|
||||||
|
|
@ -69,7 +59,7 @@ export const getNextRankBar = (
|
||||||
rx="1"
|
rx="1"
|
||||||
opacity="0.7"
|
opacity="0.7"
|
||||||
height="3.2"
|
height="3.2"
|
||||||
fill="${color}"
|
fill="${COLORS.NEXT_RANK_BAR}"
|
||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
@ -82,7 +72,7 @@ const getSmallTrophyIcon = (
|
||||||
const leftXPosition = 7;
|
const leftXPosition = 7;
|
||||||
const rightXPosition = 68;
|
const rightXPosition = 68;
|
||||||
const getIcon = (x: number) => {
|
const getIcon = (x: number) => {
|
||||||
return `<svg x="${x}" y="35" width="65" height="65" viewBox="0 0 30 30" class="bi bi-trophy" fill="${color}" xmlns="http://www.w3.org/2000/svg">
|
return `<svg x="${x}" y="35" width="65" height="65" viewBox="0 0 30 30" fill="${color}" xmlns="http://www.w3.org/2000/svg">
|
||||||
${icon}
|
${icon}
|
||||||
</svg>`;
|
</svg>`;
|
||||||
};
|
};
|
||||||
|
|
@ -97,46 +87,46 @@ const getSmallTrophyIcon = (
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
export const getTrophyIcon = (rank = RANK.UNKNOWN) => {
|
export const getTrophyIcon = (rank = RANK.UNKNOWN) => {
|
||||||
let color = "currentColor";
|
let color = COLORS.DEFAULT_RANK_BASE;
|
||||||
let rankColor = "#333";
|
let rankColor = COLORS.DEFAULT_RANK_TEXT;
|
||||||
let backgroundIcon = "";
|
let backgroundIcon = "";
|
||||||
let gradationColor = `
|
let gradationColor = `
|
||||||
<stop offset="0%" stop-color="#777"/>
|
<stop offset="0%" stop-color="${COLORS.DEFAULT_RANK_BASE}"/>
|
||||||
<stop offset="50%" stop-color="#777"/>
|
<stop offset="50%" stop-color="${COLORS.DEFAULT_RANK_BASE}"/>
|
||||||
<stop offset="100%" stop-color="#333"/>
|
<stop offset="100%" stop-color="${COLORS.DEFAULT_RANK_SHADOW}"/>
|
||||||
`;
|
`;
|
||||||
if (rank === RANK.SECRET) {
|
if (rank === RANK.SECRET) {
|
||||||
rankColor = "fuchsia";
|
rankColor = COLORS.SECRET_RANK_TEXT;
|
||||||
gradationColor = `
|
gradationColor = `
|
||||||
<stop offset="0%" stop-color="red"/>
|
<stop offset="0%" stop-color="${COLORS.SECRET_RANK_1}"/>
|
||||||
<stop offset="50%" stop-color="fuchsia"/>
|
<stop offset="50%" stop-color="${COLORS.SECRET_RANK_2}"/>
|
||||||
<stop offset="100%" stop-color="blue"/>
|
<stop offset="100%" stop-color="${COLORS.SECRET_RANK_3}"/>
|
||||||
`;
|
`;
|
||||||
} else if (rank.slice(0, 1) === RANK.S) {
|
} else if (rank.slice(0, 1) === RANK.S) {
|
||||||
color = goldColor;
|
color = COLORS.S_RANK_BASE;
|
||||||
rankColor = goldTextColor;
|
rankColor = COLORS.S_RANK_TEXT;
|
||||||
backgroundIcon = leafIcon;
|
backgroundIcon = leafIcon;
|
||||||
gradationColor = `
|
gradationColor = `
|
||||||
<stop offset="0%" stop-color="${color}"/>
|
<stop offset="0%" stop-color="${color}"/>
|
||||||
<stop offset="70%" stop-color="${color}"/>
|
<stop offset="70%" stop-color="${color}"/>
|
||||||
<stop offset="100%" stop-color="${goldShadowColor}"/>
|
<stop offset="100%" stop-color="${COLORS.S_RANK_SHADOW}"/>
|
||||||
`;
|
`;
|
||||||
} else if (rank.slice(0, 1) === RANK.A) {
|
} else if (rank.slice(0, 1) === RANK.A) {
|
||||||
color = silverColor;
|
color = COLORS.A_RANK_BASE;
|
||||||
rankColor = silverTextColor;
|
rankColor = COLORS.A_RAKN_TEXT;
|
||||||
backgroundIcon = leafIcon;
|
backgroundIcon = leafIcon;
|
||||||
gradationColor = `
|
gradationColor = `
|
||||||
<stop offset="0%" stop-color="${color}"/>
|
<stop offset="0%" stop-color="${color}"/>
|
||||||
<stop offset="70%" stop-color="${color}"/>
|
<stop offset="70%" stop-color="${color}"/>
|
||||||
<stop offset="100%" stop-color="${sliverShadowColor}"/>
|
<stop offset="100%" stop-color="${COLORS.A_RANK_SHADOW}"/>
|
||||||
`;
|
`;
|
||||||
} else if (rank === RANK.B) {
|
} else if (rank === RANK.B) {
|
||||||
color = bronzeColor;
|
color = COLORS.B_RANK_BASE;
|
||||||
rankColor = bronzeTextColor;
|
rankColor = COLORS.B_RANK_TEXT;
|
||||||
gradationColor = `
|
gradationColor = `
|
||||||
<stop offset="0%" stop-color="${color}"/>
|
<stop offset="0%" stop-color="${color}"/>
|
||||||
<stop offset="70%" stop-color="${color}"/>
|
<stop offset="70%" stop-color="${color}"/>
|
||||||
<stop offset="100%" stop-color="${bronzeShadowColor}"/>
|
<stop offset="100%" stop-color="${COLORS.B_RANK_SHADOW}"/>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
const icon = `
|
const icon = `
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { getTrophyIcon, getNextRankBar } from "./icons.ts";
|
import { getTrophyIcon, getNextRankBar } from "./icons.ts";
|
||||||
import { CONSTANTS, RANK, abridgeScore, RANK_ORDER } from "./utils.ts";
|
import { CONSTANTS, RANK, abridgeScore, RANK_ORDER, COLORS } from "./utils.ts";
|
||||||
|
|
||||||
class RankCondition {
|
class RankCondition {
|
||||||
constructor(
|
constructor(
|
||||||
|
|
@ -57,7 +57,6 @@ export class Trophy {
|
||||||
render(x = 0, y = 0, panelSize = CONSTANTS.DEFAULT_PANEL_SIZE): string {
|
render(x = 0, y = 0, panelSize = CONSTANTS.DEFAULT_PANEL_SIZE): string {
|
||||||
const nextRankBar = getNextRankBar(
|
const nextRankBar = getNextRankBar(
|
||||||
this.title,
|
this.title,
|
||||||
"#0366d6",
|
|
||||||
this.calculateNextRankPercentage(),
|
this.calculateNextRankPercentage(),
|
||||||
);
|
);
|
||||||
return `
|
return `
|
||||||
|
|
@ -103,7 +102,36 @@ export class MultipleLangTrophy extends Trophy{
|
||||||
this.title = "MultipleLang";
|
this.title = "MultipleLang";
|
||||||
this.hidden = true;
|
this.hidden = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AncientAccountTrophy extends Trophy{
|
||||||
|
constructor(score: number){
|
||||||
|
const rankConditions = [
|
||||||
|
new RankCondition(
|
||||||
|
RANK.SECRET,
|
||||||
|
"Ancient User",
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
super(score, rankConditions);
|
||||||
|
this.title = "AncientUser";
|
||||||
|
this.bottomMessage = "Before 2010"
|
||||||
|
this.hidden = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export class LongTimeAccountTrophy extends Trophy{
|
||||||
|
constructor(score: number){
|
||||||
|
const rankConditions = [
|
||||||
|
new RankCondition(
|
||||||
|
RANK.SECRET,
|
||||||
|
"Village Elder",
|
||||||
|
10,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
super(score, rankConditions);
|
||||||
|
this.title = "LongTimeUser";
|
||||||
|
this.hidden = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TotalStarTrophy extends Trophy {
|
export class TotalStarTrophy extends Trophy {
|
||||||
|
|
|
||||||
33
src/utils.ts
33
src/utils.ts
|
|
@ -1,8 +1,8 @@
|
||||||
import { ServerRequest } from ".././deps.ts";
|
import { ServerRequest } from ".././deps.ts";
|
||||||
|
|
||||||
export function parseParams(req: ServerRequest): URLSearchParams {
|
export function parseParams(req: ServerRequest): URLSearchParams {
|
||||||
const splitedURL = req.url.split("?")
|
const splitedURL = req.url.split("?");
|
||||||
if (splitedURL.length < 2){
|
if (splitedURL.length < 2) {
|
||||||
return new URLSearchParams();
|
return new URLSearchParams();
|
||||||
}
|
}
|
||||||
return new URLSearchParams(splitedURL[1]);
|
return new URLSearchParams(splitedURL[1]);
|
||||||
|
|
@ -12,12 +12,10 @@ export function abridgeScore(score: number): string {
|
||||||
if (Math.abs(score) < 1) {
|
if (Math.abs(score) < 1) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
if (Math.abs(score) > 999){
|
if (Math.abs(score) > 999) {
|
||||||
return (Math.sign(score) * (Math.abs(score) / 1000)).toFixed(1) + "pt"
|
return (Math.sign(score) * (Math.abs(score) / 1000)).toFixed(1) + "pt";
|
||||||
|
|
||||||
}
|
}
|
||||||
return (Math.sign(score) * Math.abs(score)).toString() + "pt";
|
return (Math.sign(score) * Math.abs(score)).toString() + "pt";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CONSTANTS = {
|
export const CONSTANTS = {
|
||||||
|
|
@ -38,7 +36,26 @@ export enum RANK {
|
||||||
B = "B",
|
B = "B",
|
||||||
C = "C",
|
C = "C",
|
||||||
UNKNOWN = "?",
|
UNKNOWN = "?",
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RANK_ORDER= Object.values(RANK);
|
export const COLORS = {
|
||||||
|
SECRET_RANK_1: "red",
|
||||||
|
SECRET_RANK_2: "fuchsia",
|
||||||
|
SECRET_RANK_3: "blue",
|
||||||
|
SECRET_RANK_TEXT: "fuchsia",
|
||||||
|
S_RANK_BASE: "#FAD200",
|
||||||
|
S_RANK_SHADOW: "#C8A090",
|
||||||
|
S_RANK_TEXT: "#886000",
|
||||||
|
A_RANK_BASE: "#B0B0B0",
|
||||||
|
A_RANK_SHADOW: "#9090C0",
|
||||||
|
A_RAKN_TEXT: "#505050",
|
||||||
|
B_RANK_BASE: "#A18D66",
|
||||||
|
B_RANK_SHADOW: "#816D96",
|
||||||
|
B_RANK_TEXT: "#412D06",
|
||||||
|
DEFAULT_RANK_BASE: "#777",
|
||||||
|
DEFAULT_RANK_SHADOW: "#333",
|
||||||
|
DEFAULT_RANK_TEXT: "#333",
|
||||||
|
NEXT_RANK_BAR: "#0366d6",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RANK_ORDER = Object.values(RANK);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue