github-url-detection 5.3.0 → 5.5.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 +9 -5
- package/distribution/index.js +25 -10
- package/package.json +16 -15
- package/readme.md +1 -4
package/distribution/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export declare const isOpenPR: () => boolean;
|
|
|
46
46
|
export declare const isMergedPR: () => boolean;
|
|
47
47
|
export declare const isClosedPR: () => boolean;
|
|
48
48
|
export declare const isReleasesOrTags: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
49
|
+
export declare const isDeletingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
49
50
|
export declare const isEditingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
50
51
|
export declare const isEditingRelease: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
51
52
|
export declare const isEditingWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -74,12 +75,13 @@ export declare const isForkedRepo: () => boolean;
|
|
|
74
75
|
export declare const isSingleGist: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
75
76
|
export declare const isTrending: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
76
77
|
export declare const isBranches: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
78
|
+
export declare const isProfile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
77
79
|
export declare const isUserProfile: () => boolean;
|
|
78
80
|
export declare const isUserProfileMainTab: () => boolean;
|
|
79
|
-
export declare const isUserProfileRepoTab: () => boolean;
|
|
80
|
-
export declare const isUserProfileStarsTab: () => boolean;
|
|
81
|
-
export declare const isUserProfileFollowersTab: () => boolean;
|
|
82
|
-
export declare const isUserProfileFollowingTab: () => boolean;
|
|
81
|
+
export declare const isUserProfileRepoTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
82
|
+
export declare const isUserProfileStarsTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
83
|
+
export declare const isUserProfileFollowersTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
84
|
+
export declare const isUserProfileFollowingTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
83
85
|
export declare const isSingleTag: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
84
86
|
export declare const hasComments: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
85
87
|
export declare const hasRichTextEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -89,6 +91,8 @@ export declare const isActionJobRun: (url?: URL | HTMLAnchorElement | Location)
|
|
|
89
91
|
export declare const isActionRun: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
90
92
|
export declare const isNewAction: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
91
93
|
export declare const isRepositoryActions: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
94
|
+
export declare const isUserTheOrganizationOwner: () => boolean;
|
|
95
|
+
/** @deprecated use isUserTheOrganizationOwner instead */
|
|
92
96
|
export declare const canUserEditOrganization: () => boolean;
|
|
93
97
|
export declare const canUserEditRepo: () => boolean;
|
|
94
98
|
export declare const isNewRepo: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -105,7 +109,7 @@ export interface RepositoryInfo {
|
|
|
105
109
|
path: string;
|
|
106
110
|
}
|
|
107
111
|
export declare const utils: {
|
|
108
|
-
getUsername: () => string;
|
|
112
|
+
getUsername: () => string | undefined;
|
|
109
113
|
getCleanPathname: (url?: URL | HTMLAnchorElement | Location) => string;
|
|
110
114
|
getRepositoryInfo: (url?: string | URL | HTMLAnchorElement | Location | undefined) => RepositoryInfo | undefined;
|
|
111
115
|
};
|
package/distribution/index.js
CHANGED
|
@@ -162,6 +162,11 @@ const isReleasesOrTags = (url = location) => {
|
|
|
162
162
|
return /^tags$|^releases($|\/tag)/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
+
const isDeletingFile = (url = location) => {
|
|
166
|
+
var _a;
|
|
167
|
+
return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("delete"));
|
|
168
|
+
};
|
|
169
|
+
|
|
165
170
|
const isEditingFile = (url = location) => {
|
|
166
171
|
var _a;
|
|
167
172
|
return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("edit"));
|
|
@@ -269,17 +274,22 @@ const isBranches = (url = location) => {
|
|
|
269
274
|
return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("branches"));
|
|
270
275
|
};
|
|
271
276
|
|
|
272
|
-
const
|
|
277
|
+
const isProfile = (url = location) => {
|
|
278
|
+
const pathname = getCleanPathname(url);
|
|
279
|
+
return pathname.length > 0 && !pathname.includes("/") && !reservedNames.includes(pathname);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const isUserProfile = () => isProfile() && !isOrganizationProfile();
|
|
273
283
|
|
|
274
|
-
const isUserProfileMainTab = () =>
|
|
284
|
+
const isUserProfileMainTab = () => isUserProfile() && !new URLSearchParams(location.search).has("tab");
|
|
275
285
|
|
|
276
|
-
const isUserProfileRepoTab = () =>
|
|
286
|
+
const isUserProfileRepoTab = (url = location) => isProfile(url) && "repositories" === new URLSearchParams(url.search).get("tab");
|
|
277
287
|
|
|
278
|
-
const isUserProfileStarsTab = () =>
|
|
288
|
+
const isUserProfileStarsTab = (url = location) => isProfile(url) && "stars" === new URLSearchParams(url.search).get("tab");
|
|
279
289
|
|
|
280
|
-
const isUserProfileFollowersTab = () =>
|
|
290
|
+
const isUserProfileFollowersTab = (url = location) => isProfile(url) && "followers" === new URLSearchParams(url.search).get("tab");
|
|
281
291
|
|
|
282
|
-
const isUserProfileFollowingTab = () =>
|
|
292
|
+
const isUserProfileFollowingTab = (url = location) => isProfile(url) && "following" === new URLSearchParams(url.search).get("tab");
|
|
283
293
|
|
|
284
294
|
const isSingleTag = (url = location) => {
|
|
285
295
|
var _a;
|
|
@@ -288,7 +298,7 @@ const isSingleTag = (url = location) => {
|
|
|
288
298
|
|
|
289
299
|
const hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isOrganizationDiscussion(url) || isSingleGist(url);
|
|
290
300
|
|
|
291
|
-
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || isDiscussion(url);
|
|
301
|
+
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || isNewRelease(url) || isDiscussion(url);
|
|
292
302
|
|
|
293
303
|
const hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isBlame(url);
|
|
294
304
|
|
|
@@ -314,7 +324,9 @@ const isRepositoryActions = (url = location) => {
|
|
|
314
324
|
return /^actions(\/workflows\/.+\.ya?ml)?$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
|
|
315
325
|
};
|
|
316
326
|
|
|
317
|
-
const
|
|
327
|
+
const isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
|
|
328
|
+
|
|
329
|
+
const canUserEditOrganization = isUserTheOrganizationOwner;
|
|
318
330
|
|
|
319
331
|
const canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
|
|
320
332
|
|
|
@@ -322,7 +334,10 @@ const isNewRepo = (url = location) => "/new" === url.pathname || /^organizations
|
|
|
322
334
|
|
|
323
335
|
const isNewRepoTemplate = (url = location) => Boolean("generate" === url.pathname.split("/")[3]);
|
|
324
336
|
|
|
325
|
-
const getUsername = () =>
|
|
337
|
+
const getUsername = () => {
|
|
338
|
+
var _a;
|
|
339
|
+
return null === (_a = document.querySelector('meta[name="user-login"]')) || void 0 === _a ? void 0 : _a.getAttribute("content");
|
|
340
|
+
};
|
|
326
341
|
|
|
327
342
|
const getCleanPathname = (url = location) => url.pathname.slice(1, url.pathname.endsWith("/") ? -1 : void 0);
|
|
328
343
|
|
|
@@ -351,4 +366,4 @@ const utils = {
|
|
|
351
366
|
getRepositoryInfo: getRepo
|
|
352
367
|
};
|
|
353
368
|
|
|
354
|
-
export { canUserEditOrganization, canUserEditRepo, hasCode, hasComments, hasRichTextEditor, is404, is500, isActionJobRun, isActionRun, isBlame, isBranches, isClosedPR, isCommit, isCommitList, isCompare, isConversation, isConversationList, isDashboard, isDiscussion, isDiscussionList, isDraftPR, isEditingFile, isEditingRelease, isEditingWikiPage, isEmptyRepo, isEmptyRepoRoot, isEnterprise, isFileFinder, isForkedRepo, isGist, isGlobalConversationList, isGlobalSearchResults, isIssue, isLabelList, isMarketplaceAction, isMergedPR, isMilestone, isMilestoneList, isNewAction, isNewFile, isNewIssue, isNewRelease, isNewRepo, isNewRepoTemplate, isNewWikiPage, isNotifications, isOpenPR, isOrganizationDiscussion, isOrganizationProfile, isOrganizationRepo, isOwnOrganizationProfile, isOwnUserProfile, isPR, isPRCommit, isPRCommit404, isPRCommitList, isPRConflicts, isPRConversation, isPRFile404, isPRFiles, isPRList, isPasswordConfirmation, isProject, isQuickPR, isReleasesOrTags, isRepliesSettings, isRepo, isRepoCommitList, isRepoConversationList, isRepoForksList, isRepoHome, isRepoIssueList, isRepoMainSettings, isRepoNetworkGraph, isRepoPRList, isRepoRoot, isRepoSearch, isRepoSettings, isRepoTaxonomyConversationList, isRepoTree, isRepoWiki, isRepositoryActions, isSingleCommit, isSingleFile, isSingleGist, isSingleTag, isTrending, isUserProfile, isUserProfileFollowersTab, isUserProfileFollowingTab, isUserProfileMainTab, isUserProfileRepoTab, isUserProfileStarsTab, isUserSettings, utils };
|
|
369
|
+
export { canUserEditOrganization, canUserEditRepo, hasCode, hasComments, hasRichTextEditor, is404, is500, isActionJobRun, isActionRun, isBlame, isBranches, isClosedPR, isCommit, isCommitList, isCompare, isConversation, isConversationList, isDashboard, isDeletingFile, isDiscussion, isDiscussionList, isDraftPR, isEditingFile, isEditingRelease, isEditingWikiPage, isEmptyRepo, isEmptyRepoRoot, isEnterprise, isFileFinder, isForkedRepo, isGist, isGlobalConversationList, isGlobalSearchResults, isIssue, isLabelList, isMarketplaceAction, isMergedPR, isMilestone, isMilestoneList, isNewAction, isNewFile, isNewIssue, isNewRelease, isNewRepo, isNewRepoTemplate, isNewWikiPage, isNotifications, isOpenPR, isOrganizationDiscussion, isOrganizationProfile, isOrganizationRepo, isOwnOrganizationProfile, isOwnUserProfile, isPR, isPRCommit, isPRCommit404, isPRCommitList, isPRConflicts, isPRConversation, isPRFile404, isPRFiles, isPRList, isPasswordConfirmation, isProfile, isProject, isQuickPR, isReleasesOrTags, isRepliesSettings, isRepo, isRepoCommitList, isRepoConversationList, isRepoForksList, isRepoHome, isRepoIssueList, isRepoMainSettings, isRepoNetworkGraph, isRepoPRList, isRepoRoot, isRepoSearch, isRepoSettings, isRepoTaxonomyConversationList, isRepoTree, isRepoWiki, isRepositoryActions, isSingleCommit, isSingleFile, isSingleGist, isSingleTag, isTrending, isUserProfile, isUserProfileFollowersTab, isUserProfileFollowingTab, isUserProfileMainTab, isUserProfileRepoTab, isUserProfileStarsTab, isUserSettings, isUserTheOrganizationOwner, utils };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-url-detection",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.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",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"ava/assertion-arguments": "off",
|
|
53
53
|
"@typescript-eslint/dot-notation": "off",
|
|
54
54
|
"@typescript-eslint/no-non-null-assertion": "off",
|
|
55
|
+
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
55
56
|
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
|
|
56
57
|
"@typescript-eslint/comma-dangle": [
|
|
57
58
|
"error",
|
|
@@ -89,25 +90,25 @@
|
|
|
89
90
|
},
|
|
90
91
|
"devDependencies": {
|
|
91
92
|
"@rollup/plugin-json": "^4.1.0",
|
|
92
|
-
"@rollup/plugin-node-resolve": "^
|
|
93
|
-
"@rollup/plugin-typescript": "^8.2.
|
|
94
|
-
"@sindresorhus/tsconfig": "^
|
|
95
|
-
"@types/jsdom": "^16.2.
|
|
93
|
+
"@rollup/plugin-node-resolve": "^13.0.5",
|
|
94
|
+
"@rollup/plugin-typescript": "^8.2.5",
|
|
95
|
+
"@sindresorhus/tsconfig": "^2.0.0",
|
|
96
|
+
"@types/jsdom": "^16.2.13",
|
|
96
97
|
"ava": "^3.15.0",
|
|
97
98
|
"github-reserved-names": "^2.0.4",
|
|
98
|
-
"jsdom": "^
|
|
99
|
+
"jsdom": "^17.0.0",
|
|
99
100
|
"npm-run-all": "^4.1.5",
|
|
100
101
|
"parcel-bundler": "^1.12.4",
|
|
101
|
-
"parcel-plugin-svelte": "^4.0.
|
|
102
|
-
"rollup": "^2.
|
|
102
|
+
"parcel-plugin-svelte": "^4.0.9",
|
|
103
|
+
"rollup": "^2.57.0",
|
|
103
104
|
"rollup-plugin-terser": "^7.0.2",
|
|
104
|
-
"strip-indent": "^
|
|
105
|
-
"svelte": "^3.
|
|
106
|
-
"svelte-check": "^
|
|
107
|
-
"ts-node": "^
|
|
108
|
-
"tslib": "^2.
|
|
109
|
-
"typescript": "^4.
|
|
110
|
-
"xo": "^0.
|
|
105
|
+
"strip-indent": "^4.0.0",
|
|
106
|
+
"svelte": "^3.43.0",
|
|
107
|
+
"svelte-check": "^2.2.6",
|
|
108
|
+
"ts-node": "^10.2.1",
|
|
109
|
+
"tslib": "^2.3.1",
|
|
110
|
+
"typescript": "^4.4.3",
|
|
111
|
+
"xo": "^0.44.0"
|
|
111
112
|
},
|
|
112
113
|
"engines": {
|
|
113
114
|
"node": ">=12"
|
package/readme.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Battle-tested by and extracted from the [Refined GitHub](https://github.com/sindresorhus/refined-github) extension.
|
|
6
6
|
|
|
7
7
|
- Try the live [demo](https://fregante.github.io/github-url-detection/)
|
|
8
|
-
- See the code and expected URLs for [every detection](https://github.com/fregante/github-url-detection/blob/
|
|
8
|
+
- See the code and expected URLs for [every detection](https://github.com/fregante/github-url-detection/blob/main/index.ts)
|
|
9
9
|
|
|
10
10
|
## Install
|
|
11
11
|
|
|
@@ -37,8 +37,6 @@ if (pageDetect.isConversationList()) {
|
|
|
37
37
|
|
|
38
38
|
## API
|
|
39
39
|
|
|
40
|
-
In the source you can see the [full list of detections](https://www.unpkg.com/browse/github-url-detection@latest/esm/index.d.ts) and [their matching URLs.](https://github.com/fregante/github-url-detection/blob/master/index.ts)
|
|
41
|
-
|
|
42
40
|
Most detections are URL-based while others need access to the current `document`. You can determine which ones are URL-based by looking at their signature: URL-based functions have a `url` parameter.
|
|
43
41
|
|
|
44
42
|
### URL-based detections
|
|
@@ -63,7 +61,6 @@ Notice that the `url` parameter is not a plain string but it has to be a proper
|
|
|
63
61
|
|
|
64
62
|
By default, `document`-based detections use the `document` global, which means they can only be used if you have the whole page, you can't just test any random URL string.
|
|
65
63
|
|
|
66
|
-
|
|
67
64
|
```js
|
|
68
65
|
if (pageDetect.isOrganizationProfile()) {
|
|
69
66
|
alert('You’re on an organization profile, like https://github.com/babel')
|