Skip to content

Commit

Permalink
fix: fork and star charts won't show when users are not logged in (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyn1998 authored Mar 6, 2024
1 parent 197a594 commit 65438d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/helpers/get-developer-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ export async function isDeveloperWithMeta() {
pageDetect.isUserProfile() && (await metaStore.has(getDeveloperName()))
);
}

export function checkLogined() {
return !!$('meta[name="user-login"]').attr('content');
}
5 changes: 3 additions & 2 deletions src/pages/ContentScripts/features/repo-fork-tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ const init = async (): Promise<void> => {
repoName = getRepoName();
await getData();

await elementReady('a[data-ga-click*="show fork modal"]');
$('a[data-ga-click*="show fork modal"]').attr({
const selector = '#fork-button';
await elementReady(selector);
$(selector).attr({
'data-tip': '',
'data-for': 'fork-tooltip',
'data-class': `floating-window ${githubTheme}`,
Expand Down
9 changes: 7 additions & 2 deletions src/pages/ContentScripts/features/repo-star-tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { getStars } from '../../../../api/repo';
import View from './view';
import { RepoMeta, metaStore } from '../../../../api/common';
import { checkLogined } from '../../../../helpers/get-developer-info';

const githubTheme = getGithubTheme();
const featureId = features.getFeatureID(import.meta.url);
Expand All @@ -33,7 +34,11 @@ const init = async (): Promise<void> => {
repoName = getRepoName();
await getData();

await elementReady('a[data-ga-click*="star button"]');
const isLogined = checkLogined();
const selector = isLogined
? 'button[data-ga-click*="star button"]'
: 'a[data-hydro-click*="star button"]';
await elementReady(selector);
const attributes = {
'data-tip': '',
'data-for': 'star-tooltip',
Expand All @@ -46,7 +51,7 @@ const init = async (): Promise<void> => {
'data-text-color': githubTheme === 'light' ? '#24292F' : '#C9D1D9',
'data-background-color': githubTheme === 'light' ? 'white' : '#161B22',
};
$('button[data-ga-click*="star button"]').attr(attributes);
$(selector).attr(attributes);

const container = document.createElement('div');
container.id = featureId;
Expand Down

0 comments on commit 65438d5

Please sign in to comment.