diff --git a/src/helpers/get-developer-info.ts b/src/helpers/get-developer-info.ts index a5dc75ff..271bdf41 100644 --- a/src/helpers/get-developer-info.ts +++ b/src/helpers/get-developer-info.ts @@ -4,8 +4,20 @@ import $ from 'jquery'; import * as pageDetect from 'github-url-detection'; export function getDeveloperName() { + const developerNameByUrl = getDeveloperNameByUrl(); + const developerNameByPage = getDeveloperNameByPage(); + if (developerNameByUrl.toLowerCase() === developerNameByPage.toLowerCase()) { + return developerNameByPage; + } + return developerNameByUrl; +} + +export function getDeveloperNameByPage() { return $('.p-nickname.vcard-username.d-block').text().trim().split(' ')[0]; } +export function getDeveloperNameByUrl() { + return pageDetect.utils.getUsername()!; +} export async function isDeveloperWithMeta() { return pageDetect.isUserProfile() && (await metaStore.has(getDeveloperName())); diff --git a/src/helpers/get-repo-info.ts b/src/helpers/get-repo-info.ts index 08b0bfe2..f74acef6 100644 --- a/src/helpers/get-repo-info.ts +++ b/src/helpers/get-repo-info.ts @@ -5,6 +5,24 @@ import * as pageDetect from 'github-url-detection'; import elementReady from 'element-ready'; export function getRepoName() { + const repoNameByUrl = getRepoNameByUrl(); + const repoNameByPage = getRepoNameByPage(); + if (repoNameByUrl.toLowerCase() === repoNameByPage.toLowerCase()) { + return repoNameByPage; + } + return repoNameByUrl; +} + +export function getRepoNameByPage() { + let repoName: string[] = []; + $('header span.AppHeader-context-item-label').map(function () { + repoName.push($(this).text().trim()); + }); + let repoFullName = repoName[0] + '/' + repoName[1]; + return repoFullName; +} + +export function getRepoNameByUrl() { return pageDetect.utils.getRepositoryInfo(window.location)!.nameWithOwner; } @@ -29,5 +47,5 @@ export async function isPublicRepo() { } export async function isPublicRepoWithMeta() { - return (await isPublicRepo()) && (await metaStore.has(getRepoName())); + return (await isPublicRepo()) && ((await metaStore.has(getRepoName())) || (await metaStore.has(getRepoNameByPage()))); }