From 1ffe41dc986993ec4f6e5612e0ef5767e3dc6f4c Mon Sep 17 00:00:00 2001 From: Lam Tang Date: Thu, 17 Aug 2023 13:39:58 +0800 Subject: [PATCH] fix: the old isPublicRepo() fails in the new UI --- src/helpers/get-repo-info.ts | 15 +++++---------- src/helpers/is-perceptor.ts | 5 +++-- .../features/repo-activity-racing-bar/index.tsx | 7 +++++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/helpers/get-repo-info.ts b/src/helpers/get-repo-info.ts index 8ade6850..5daa602c 100644 --- a/src/helpers/get-repo-info.ts +++ b/src/helpers/get-repo-info.ts @@ -10,16 +10,11 @@ export function getRepoName() { // check if the repository is public export async function isPublicRepo() { - // another selector that also works - // const repoLabel = $('strong[itemprop="name"]').siblings('span.Label.Label--secondary').text(); - await elementReady('#repository-container-header'); - const repoLabel = $('#repository-container-header') - .find('span.Label.Label--secondary:first') - .text(); - return ( - pageDetect.isRepo() && - (repoLabel === 'Public' || repoLabel === 'Public template') - ); + const selector = 'meta[name="octolytics-dimension-repository_public"]'; + await elementReady(selector); + // + const isPublic = $(selector).attr('content') === 'true'; + return pageDetect.isRepo() && isPublic; } export async function isPublicRepoWithMeta() { diff --git a/src/helpers/is-perceptor.ts b/src/helpers/is-perceptor.ts index c9b6e4bd..3cad003f 100644 --- a/src/helpers/is-perceptor.ts +++ b/src/helpers/is-perceptor.ts @@ -1,4 +1,5 @@ -const isPerceptor = (): boolean => - window.location.search.includes('?redirect=perceptor'); +const isPerceptor = (): boolean => { + return window.location.search.includes('?redirect=perceptor'); +}; export default isPerceptor; diff --git a/src/pages/ContentScripts/features/repo-activity-racing-bar/index.tsx b/src/pages/ContentScripts/features/repo-activity-racing-bar/index.tsx index 76bf23f5..e9b2fd7e 100644 --- a/src/pages/ContentScripts/features/repo-activity-racing-bar/index.tsx +++ b/src/pages/ContentScripts/features/repo-activity-racing-bar/index.tsx @@ -4,7 +4,10 @@ import $ from 'jquery'; import features from '../../../../feature-manager'; import isPerceptor from '../../../../helpers/is-perceptor'; -import { getRepoName } from '../../../../helpers/get-repo-info'; +import { + getRepoName, + isPublicRepoWithMeta, +} from '../../../../helpers/get-repo-info'; import { getActivityDetails } from '../../../../api/repo'; import View from './view'; import DataNotFound from '../repo-networks/DataNotFound'; @@ -52,7 +55,7 @@ const restore = async () => { }; features.add(featureId, { - asLongAs: [isPerceptor], + asLongAs: [isPerceptor, isPublicRepoWithMeta], awaitDomReady: false, init, restore,