github-url-detection 10.0.1 → 10.1.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 +8 -0
- package/distribution/index.js +35 -8
- package/package.json +2 -1
package/distribution/index.d.ts
CHANGED
|
@@ -72,6 +72,11 @@ export declare const isRepoIssueOrPRList: (url?: URL | HTMLAnchorElement | Locat
|
|
|
72
72
|
export declare const isRepoPRList: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
73
73
|
export declare const isRepoIssueList: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
74
74
|
export declare const isRepoHome: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
75
|
+
export type RepoExplorerInfo = {
|
|
76
|
+
nameWithOwner: string;
|
|
77
|
+
branch: string;
|
|
78
|
+
filePath: string;
|
|
79
|
+
};
|
|
75
80
|
export declare const isRepoRoot: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
76
81
|
export declare const isRepoSearch: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
77
82
|
export declare const isRepoSettings: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -109,6 +114,8 @@ export declare const hasComments: (url?: URL | HTMLAnchorElement | Location) =>
|
|
|
109
114
|
export declare const hasRichTextEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
110
115
|
/** Static code, not the code editor */
|
|
111
116
|
export declare const hasCode: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
117
|
+
/** Covers blob, trees and blame pages */
|
|
118
|
+
export declare const isRepoGitObject: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
112
119
|
/** Has a list of files */
|
|
113
120
|
export declare const hasFiles: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
114
121
|
export declare const isMarketplaceAction: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -147,4 +154,5 @@ export declare const utils: {
|
|
|
147
154
|
getCleanPathname: (url?: URL | HTMLAnchorElement | Location) => string;
|
|
148
155
|
getCleanGistPathname: (url?: URL | HTMLAnchorElement | Location) => string | undefined;
|
|
149
156
|
getRepositoryInfo: (url?: URL | HTMLAnchorElement | Location | string) => RepositoryInfo | undefined;
|
|
157
|
+
parseRepoExplorerTitle: (pathname: string, title: string) => RepoExplorerInfo | undefined;
|
|
150
158
|
};
|
package/distribution/index.js
CHANGED
|
@@ -97,18 +97,42 @@ var isRepoIssueList = (url = location) => (
|
|
|
97
97
|
);
|
|
98
98
|
var hasSearchParameter = (url) => new URLSearchParams(url.search).get("search") === "1";
|
|
99
99
|
var isRepoHome = (url = location) => getRepo(url)?.path === "" && !hasSearchParameter(url);
|
|
100
|
+
var titleParseRegex = /^(?:(?<nameWithOwner>[^ ]+) at (?<branch>[^ ]+)|[^/ ]+(?:\/(?<filePath>[^ ]*))? at (?<branch2>[^ ]+)(?: · (?<nameWithOwner2>[^ ]+))?)$/;
|
|
101
|
+
var parseRepoExplorerTitle = (pathname, title) => {
|
|
102
|
+
const match = titleParseRegex.exec(title);
|
|
103
|
+
if (!match?.groups) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let { nameWithOwner, branch, filePath, nameWithOwner2, branch2 } = match.groups;
|
|
107
|
+
nameWithOwner ??= nameWithOwner2;
|
|
108
|
+
branch ??= branch2;
|
|
109
|
+
filePath ??= "";
|
|
110
|
+
if (!nameWithOwner || !branch || !pathname.startsWith(`/${nameWithOwner}/tree/`)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
return { nameWithOwner, branch, filePath };
|
|
114
|
+
};
|
|
100
115
|
var _isRepoRoot = (url) => {
|
|
101
116
|
const repository = getRepo(url ?? location);
|
|
102
117
|
if (!repository) {
|
|
103
118
|
return false;
|
|
104
119
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
120
|
+
const path = repository.path ? repository.path.split("/") : [];
|
|
121
|
+
switch (path.length) {
|
|
122
|
+
case 0: {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
case 2: {
|
|
126
|
+
return path[0] === "tree";
|
|
127
|
+
}
|
|
128
|
+
default: {
|
|
129
|
+
if (url) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const titleInfo = parseRepoExplorerTitle(location.pathname, document.title);
|
|
133
|
+
return titleInfo?.filePath === "";
|
|
134
|
+
}
|
|
110
135
|
}
|
|
111
|
-
return repository.path.startsWith("tree/") && document.title.startsWith(repository.nameWithOwner) && !document.title.endsWith(repository.nameWithOwner);
|
|
112
136
|
};
|
|
113
137
|
var isRepoRoot = (url) => !hasSearchParameter(url ?? location) && _isRepoRoot(url);
|
|
114
138
|
var isRepoSearch = (url = location) => getRepo(url)?.path === "search";
|
|
@@ -143,6 +167,7 @@ var isProfileRepoList = (url = location) => isUserProfileRepoTab(url) || getOrg(
|
|
|
143
167
|
var hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isTeamDiscussion(url) || isSingleGist(url);
|
|
144
168
|
var hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url) || isNewDiscussion(url);
|
|
145
169
|
var hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isCompareWikiPage(url) || isBlame(url);
|
|
170
|
+
var isRepoGitObject = (url = location) => isRepo(url) && [void 0, "blob", "tree", "blame"].includes(getCleanPathname(url).split("/")[2]);
|
|
146
171
|
var hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url);
|
|
147
172
|
var isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/");
|
|
148
173
|
var isActionJobRun = (url = location) => Boolean(getRepo(url)?.path.startsWith("runs/"));
|
|
@@ -152,7 +177,7 @@ var isRepositoryActions = (url = location) => /^actions(\/workflows\/.+\.ya?ml)?
|
|
|
152
177
|
var isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
|
|
153
178
|
var canUserAdminRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
|
|
154
179
|
var canUserEditRepo = canUserAdminRepo;
|
|
155
|
-
var isNewRepo = (url = location) => url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));
|
|
180
|
+
var isNewRepo = (url = location) => !isGist(url) && (url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url)));
|
|
156
181
|
var isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate");
|
|
157
182
|
var getLoggedInUser = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0;
|
|
158
183
|
var getCleanPathname = (url = location) => url.pathname.replaceAll(/\/\/+/g, "/").replace(/\/$/, "").slice(1);
|
|
@@ -202,7 +227,8 @@ var utils = {
|
|
|
202
227
|
getLoggedInUser,
|
|
203
228
|
getCleanPathname,
|
|
204
229
|
getCleanGistPathname,
|
|
205
|
-
getRepositoryInfo: getRepo
|
|
230
|
+
getRepositoryInfo: getRepo,
|
|
231
|
+
parseRepoExplorerTitle
|
|
206
232
|
};
|
|
207
233
|
export {
|
|
208
234
|
canUserAdminRepo,
|
|
@@ -293,6 +319,7 @@ export {
|
|
|
293
319
|
isRepoCommitList,
|
|
294
320
|
isRepoFile404,
|
|
295
321
|
isRepoForksList,
|
|
322
|
+
isRepoGitObject,
|
|
296
323
|
isRepoHome,
|
|
297
324
|
isRepoIssueList,
|
|
298
325
|
isRepoIssueOrPRList,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-url-detection",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.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",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"build:esbuild": "esbuild index.ts --bundle --external:github-reserved-names --outdir=distribution --format=esm --drop-labels=TEST",
|
|
29
29
|
"build:typescript": "tsc --declaration --emitDeclarationOnly",
|
|
30
30
|
"build:demo": "vite build demo",
|
|
31
|
+
"try": "esbuild index.ts --bundle --global-name=x --format=iife | pbcopy && echo 'Copied to clipboard'",
|
|
31
32
|
"fix": "xo --fix",
|
|
32
33
|
"prepack": "npm run build",
|
|
33
34
|
"test": "run-p build test:* xo",
|