github-url-detection 10.0.1 → 10.0.2
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 +6 -0
- package/distribution/index.js +33 -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;
|
|
@@ -147,4 +152,5 @@ export declare const utils: {
|
|
|
147
152
|
getCleanPathname: (url?: URL | HTMLAnchorElement | Location) => string;
|
|
148
153
|
getCleanGistPathname: (url?: URL | HTMLAnchorElement | Location) => string | undefined;
|
|
149
154
|
getRepositoryInfo: (url?: URL | HTMLAnchorElement | Location | string) => RepositoryInfo | undefined;
|
|
155
|
+
parseRepoExplorerTitle: (pathname: string, title: string) => RepoExplorerInfo | undefined;
|
|
150
156
|
};
|
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";
|
|
@@ -152,7 +176,7 @@ var isRepositoryActions = (url = location) => /^actions(\/workflows\/.+\.ya?ml)?
|
|
|
152
176
|
var isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
|
|
153
177
|
var canUserAdminRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
|
|
154
178
|
var canUserEditRepo = canUserAdminRepo;
|
|
155
|
-
var isNewRepo = (url = location) => url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));
|
|
179
|
+
var isNewRepo = (url = location) => !isGist(url) && (url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url)));
|
|
156
180
|
var isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate");
|
|
157
181
|
var getLoggedInUser = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0;
|
|
158
182
|
var getCleanPathname = (url = location) => url.pathname.replaceAll(/\/\/+/g, "/").replace(/\/$/, "").slice(1);
|
|
@@ -202,7 +226,8 @@ var utils = {
|
|
|
202
226
|
getLoggedInUser,
|
|
203
227
|
getCleanPathname,
|
|
204
228
|
getCleanGistPathname,
|
|
205
|
-
getRepositoryInfo: getRepo
|
|
229
|
+
getRepositoryInfo: getRepo,
|
|
230
|
+
parseRepoExplorerTitle
|
|
206
231
|
};
|
|
207
232
|
export {
|
|
208
233
|
canUserAdminRepo,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-url-detection",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.2",
|
|
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",
|