github-url-detection 7.1.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distribution/index.d.ts +3 -1
- package/distribution/index.js +19 -13
- package/package.json +8 -11
package/distribution/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare const isOwnOrganizationProfile: () => boolean;
|
|
|
31
31
|
export declare const isProject: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
32
32
|
export declare const isProjects: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
33
33
|
export declare const isDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
34
|
+
export declare const isNewDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
34
35
|
export declare const isDiscussionList: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
35
36
|
export declare const isPR: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
36
37
|
export declare const isPRConflicts: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -50,7 +51,7 @@ export declare const isClosedPR: () => boolean;
|
|
|
50
51
|
export declare const isClosedIssue: () => boolean;
|
|
51
52
|
export declare const isReleases: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
52
53
|
export declare const isTags: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
53
|
-
export declare const
|
|
54
|
+
export declare const isSingleReleaseOrTag: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
54
55
|
export declare const isReleasesOrTags: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
55
56
|
export declare const isDeletingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
56
57
|
export declare const isEditingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -98,6 +99,7 @@ export declare const isUserProfileRepoTab: (url?: URL | HTMLAnchorElement | Loca
|
|
|
98
99
|
export declare const isUserProfileStarsTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
99
100
|
export declare const isUserProfileFollowersTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
100
101
|
export declare const isUserProfileFollowingTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
102
|
+
export declare const isProfileRepoList: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
101
103
|
export declare const hasComments: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
102
104
|
export declare const hasRichTextEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
103
105
|
/** Static code, not the code editor */
|
package/distribution/index.js
CHANGED
|
@@ -278,7 +278,7 @@ const reservedNames = [
|
|
|
278
278
|
];
|
|
279
279
|
const $ = (selector) => document.querySelector(selector);
|
|
280
280
|
const exists = (selector) => Boolean($(selector));
|
|
281
|
-
const is404 = () =>
|
|
281
|
+
const is404 = () => /^(Page|File) not found · GitHub/.test(document.title);
|
|
282
282
|
const is500 = () => document.title === "Server Error · GitHub" || document.title === "Unicorn! · GitHub" || document.title === "504 Gateway Time-out";
|
|
283
283
|
const isPasswordConfirmation = () => document.title === "Confirm password" || document.title === "Confirm access";
|
|
284
284
|
const isBlame = (url = location) => Boolean(getRepo(url)?.path.startsWith("blame/"));
|
|
@@ -304,13 +304,14 @@ const isNewRelease = (url = location) => getRepo(url)?.path === "releases/new";
|
|
|
304
304
|
const isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_new");
|
|
305
305
|
const isNotifications = (url = location) => getCleanPathname(url) === "notifications";
|
|
306
306
|
const isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
|
|
307
|
-
const isOrganizationRepo = () =>
|
|
307
|
+
const isOrganizationRepo = () => exists('.AppHeader-context-full [data-hovercard-type="organization"]');
|
|
308
308
|
const isTeamDiscussion = (url = location) => Boolean(getOrg(url)?.path.startsWith("teams"));
|
|
309
309
|
const isOwnUserProfile = () => getCleanPathname() === getUsername();
|
|
310
310
|
const isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');
|
|
311
311
|
const isProject = (url = location) => /^projects\/\d+/.test(getRepo(url)?.path);
|
|
312
312
|
const isProjects = (url = location) => getRepo(url)?.path === "projects";
|
|
313
313
|
const isDiscussion = (url = location) => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path);
|
|
314
|
+
const isNewDiscussion = (url = location) => getRepo(url)?.path === "discussions/new" || getOrg(url)?.path === "discussions/new";
|
|
314
315
|
const isDiscussionList = (url = location) => getRepo(url)?.path === "discussions" || getOrg(url)?.path === "discussions";
|
|
315
316
|
const isPR = (url = location) => /^pull\/\d+/.test(getRepo(url)?.path) && !isPRConflicts(url);
|
|
316
317
|
const isPRConflicts = (url = location) => /^pull\/\d+\/conflicts/.test(getRepo(url)?.path);
|
|
@@ -320,7 +321,7 @@ const isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit ra
|
|
|
320
321
|
const isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found · Pull Request");
|
|
321
322
|
const isPRConversation = (url = location) => /^pull\/\d+$/.test(getRepo(url)?.path);
|
|
322
323
|
const isPRCommitList = (url = location) => /^pull\/\d+\/commits$/.test(getRepo(url)?.path);
|
|
323
|
-
const isPRFiles = (url = location) => /^pull\/\d+\/files/.test(getRepo(url)?.path);
|
|
324
|
+
const isPRFiles = (url = location) => /^pull\/\d+\/files/.test(getRepo(url)?.path) || isPRCommit(url);
|
|
324
325
|
const isQuickPR = (url = location) => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search);
|
|
325
326
|
const isDraftPR = () => exists("#partial-discussion-header .octicon-git-pull-request-draft");
|
|
326
327
|
const isOpenPR = () => exists("#partial-discussion-header :is(.octicon-git-pull-request, .octicon-git-pull-request-draft)");
|
|
@@ -329,8 +330,8 @@ const isClosedPR = () => exists("#partial-discussion-header :is(.octicon-git-pul
|
|
|
329
330
|
const isClosedIssue = () => exists("#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)");
|
|
330
331
|
const isReleases = (url = location) => getRepo(url)?.path === "releases";
|
|
331
332
|
const isTags = (url = location) => getRepo(url)?.path === "tags";
|
|
332
|
-
const
|
|
333
|
-
const isReleasesOrTags = (url = location) => isReleases(url) || isTags(url)
|
|
333
|
+
const isSingleReleaseOrTag = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/tag"));
|
|
334
|
+
const isReleasesOrTags = (url = location) => isReleases(url) || isTags(url);
|
|
334
335
|
const isDeletingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("delete"));
|
|
335
336
|
const isEditingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("edit"));
|
|
336
337
|
const hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url);
|
|
@@ -352,8 +353,9 @@ const isRepoIssueList = (url = location) => (
|
|
|
352
353
|
// `issues/fregante` is a list but `issues/1`, `issues/new`, `issues/new/choose`, `issues/templates/edit` aren’t
|
|
353
354
|
/^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(getRepo(url)?.path)
|
|
354
355
|
);
|
|
355
|
-
const
|
|
356
|
-
const
|
|
356
|
+
const hasSearchParameter = (url) => new URLSearchParams(url.search).get("search") === "1";
|
|
357
|
+
const isRepoHome = (url = location) => getRepo(url)?.path === "" && !hasSearchParameter(url);
|
|
358
|
+
const _isRepoRoot = (url) => {
|
|
357
359
|
const repository = getRepo(url ?? location);
|
|
358
360
|
if (!repository) {
|
|
359
361
|
return false;
|
|
@@ -366,12 +368,13 @@ const isRepoRoot = (url) => {
|
|
|
366
368
|
}
|
|
367
369
|
return repository.path.startsWith("tree/") && document.title.startsWith(repository.nameWithOwner) && !document.title.endsWith(repository.nameWithOwner);
|
|
368
370
|
};
|
|
371
|
+
const isRepoRoot = (url) => !hasSearchParameter(url ?? location) && _isRepoRoot(url);
|
|
369
372
|
const isRepoSearch = (url = location) => getRepo(url)?.path === "search";
|
|
370
373
|
const isRepoSettings = (url = location) => Boolean(getRepo(url)?.path.startsWith("settings"));
|
|
371
374
|
const isRepoMainSettings = (url = location) => getRepo(url)?.path === "settings";
|
|
372
375
|
const isRepliesSettings = (url = location) => url.pathname.startsWith("/settings/replies");
|
|
373
376
|
const isUserSettings = (url = location) => url.pathname.startsWith("/settings/");
|
|
374
|
-
const isRepoTree = (url = location) =>
|
|
377
|
+
const isRepoTree = (url = location) => _isRepoRoot(url) || Boolean(getRepo(url)?.path.startsWith("tree/"));
|
|
375
378
|
const isRepoWiki = (url = location) => Boolean(getRepo(url)?.path.startsWith("wiki"));
|
|
376
379
|
const isSingleCommit = (url = location) => /^commit\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
|
|
377
380
|
const isSingleFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("blob/"));
|
|
@@ -393,8 +396,9 @@ const isUserProfileRepoTab = (url = location) => isProfile(url) && new URLSearch
|
|
|
393
396
|
const isUserProfileStarsTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "stars";
|
|
394
397
|
const isUserProfileFollowersTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "followers";
|
|
395
398
|
const isUserProfileFollowingTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "following";
|
|
399
|
+
const isProfileRepoList = (url = location) => isUserProfileRepoTab(url) || getOrg(url)?.path === "repositories";
|
|
396
400
|
const hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isTeamDiscussion(url) || isSingleGist(url);
|
|
397
|
-
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url);
|
|
401
|
+
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url) || isNewDiscussion(url);
|
|
398
402
|
const hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isCompareWikiPage(url) || isBlame(url);
|
|
399
403
|
const hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url);
|
|
400
404
|
const isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/");
|
|
@@ -406,8 +410,8 @@ const isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[ari
|
|
|
406
410
|
const canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
|
|
407
411
|
const isNewRepo = (url = location) => url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));
|
|
408
412
|
const isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate");
|
|
409
|
-
const getUsername = () =>
|
|
410
|
-
const getCleanPathname = (url = location) => url.pathname.
|
|
413
|
+
const getUsername = () => $('meta[name="user-login"]')?.getAttribute("content");
|
|
414
|
+
const getCleanPathname = (url = location) => url.pathname.replaceAll(/\/+/g, "/").slice(1, url.pathname.endsWith("/") ? -1 : void 0);
|
|
411
415
|
const getCleanGistPathname = (url = location) => {
|
|
412
416
|
const pathname = getCleanPathname(url);
|
|
413
417
|
if (url.hostname.startsWith("gist.")) {
|
|
@@ -425,7 +429,7 @@ const getOrg = (url = location) => {
|
|
|
425
429
|
};
|
|
426
430
|
const getRepo = (url) => {
|
|
427
431
|
if (!url) {
|
|
428
|
-
const canonical =
|
|
432
|
+
const canonical = $('[property="og:url"]');
|
|
429
433
|
if (canonical) {
|
|
430
434
|
const canonicalUrl = new URL(canonical.content, location.origin);
|
|
431
435
|
if (getCleanPathname(canonicalUrl).toLowerCase() === getCleanPathname(location).toLowerCase()) {
|
|
@@ -505,6 +509,7 @@ export {
|
|
|
505
509
|
isMilestone,
|
|
506
510
|
isMilestoneList,
|
|
507
511
|
isNewAction,
|
|
512
|
+
isNewDiscussion,
|
|
508
513
|
isNewFile,
|
|
509
514
|
isNewIssue,
|
|
510
515
|
isNewRelease,
|
|
@@ -529,6 +534,7 @@ export {
|
|
|
529
534
|
isPasswordConfirmation,
|
|
530
535
|
isPrivateUserProfile,
|
|
531
536
|
isProfile,
|
|
537
|
+
isProfileRepoList,
|
|
532
538
|
isProject,
|
|
533
539
|
isProjects,
|
|
534
540
|
isPublicRepo,
|
|
@@ -555,7 +561,7 @@ export {
|
|
|
555
561
|
isSingleCommit,
|
|
556
562
|
isSingleFile,
|
|
557
563
|
isSingleGist,
|
|
558
|
-
|
|
564
|
+
isSingleReleaseOrTag,
|
|
559
565
|
isTags,
|
|
560
566
|
isTeamDiscussion,
|
|
561
567
|
isTrending,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-url-detection",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -73,21 +73,18 @@
|
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@esbuild-kit/esm-loader": "^2.5.5",
|
|
75
75
|
"@sindresorhus/tsconfig": "^3.0.1",
|
|
76
|
-
"@sveltejs/vite-plugin-svelte": "^2.
|
|
77
|
-
"ava": "^5.
|
|
76
|
+
"@sveltejs/vite-plugin-svelte": "^2.4.3",
|
|
77
|
+
"ava": "^5.3.1",
|
|
78
78
|
"github-reserved-names": "^2.0.4",
|
|
79
79
|
"npm-run-all": "^4.1.5",
|
|
80
80
|
"strip-indent": "^4.0.0",
|
|
81
|
-
"svelte": "^
|
|
82
|
-
"svelte-check": "^3.
|
|
83
|
-
"typescript": "^5.
|
|
84
|
-
"vite": "^4.
|
|
85
|
-
"xo": "^0.
|
|
81
|
+
"svelte": "^4.1.2",
|
|
82
|
+
"svelte-check": "^3.4.6",
|
|
83
|
+
"typescript": "^5.1.6",
|
|
84
|
+
"vite": "^4.4.7",
|
|
85
|
+
"xo": "^0.55.0"
|
|
86
86
|
},
|
|
87
87
|
"engines": {
|
|
88
88
|
"node": ">=18"
|
|
89
|
-
},
|
|
90
|
-
"overrides": {
|
|
91
|
-
"vite": "^4.3.0-beta.4"
|
|
92
89
|
}
|
|
93
90
|
}
|