Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isGitHubRepoUrl, getRepoPathFromUrl, isSameGitHubRepo } from './utils'
import { isGitHubRepoUrl, getRepoPathFromUrl, isSameGitHubRepo, isGitHubReservedName } from './utils'

const timer = (ms: number) => new Promise((res) => setTimeout(res, ms))

Expand All @@ -24,7 +24,7 @@ const run = async () => {
}
const filtered = Array.from(anchors).filter(
(a) =>
isGitHubRepoUrl(a.href) && !isSameGitHubRepo(a.href, window.location.href)
isGitHubRepoUrl(a.href) && !isGitHubReservedName(a.href) && !isSameGitHubRepo(a.href, location.href)
)
for (const a of filtered) {
displayStarCount(a)
Expand Down
20 changes: 20 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ const GITHUB_REPO_REGEX = new RegExp(
export const isGitHubRepoUrl = (url: string): boolean =>
GITHUB_REPO_REGEX.test(url)

const GITHUB_RESERVED_PATHS = [
'about',
'blog',
'contact',
'explore',
'features',
'marketplace',
'pricing',
'security',
'site',
'sponsors',
'topics',
'trending',
]

export const isGitHubReservedName = (href: string): boolean => {
const path = href.split('/').slice(3)
return GITHUB_RESERVED_PATHS.includes(path[0])
}

export const isSameGitHubRepo = (href: string, current: string): boolean => {
const hrefRepoPath = href.match(GITHUB_REPO_REGEX)
const currentRepoPath = current.match(GITHUB_REPO_REGEX)
Expand Down