github-url-detection 5.7.1 → 5.10.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 +6 -0
- package/distribution/index.js +19 -7
- package/package.json +20 -25
- package/readme.md +4 -4
package/distribution/index.d.ts
CHANGED
|
@@ -52,11 +52,15 @@ export declare const isSingleTag: (url?: URL | HTMLAnchorElement | Location) =>
|
|
|
52
52
|
export declare const isReleasesOrTags: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
53
53
|
export declare const isDeletingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
54
54
|
export declare const isEditingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
55
|
+
export declare const hasFileEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
55
56
|
export declare const isEditingRelease: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
57
|
+
export declare const hasReleaseEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
56
58
|
export declare const isEditingWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
59
|
+
export declare const hasWikiPageEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
57
60
|
export declare const isRepo: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
58
61
|
export declare const isEmptyRepoRoot: () => boolean;
|
|
59
62
|
export declare const isEmptyRepo: () => boolean;
|
|
63
|
+
export declare const isBlank: () => boolean;
|
|
60
64
|
export declare const isRepoTaxonomyConversationList: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
61
65
|
export declare const isRepoConversationList: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
62
66
|
export declare const isRepoPRList: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -77,6 +81,7 @@ export declare const isRepoForksList: (url?: URL | HTMLAnchorElement | Location)
|
|
|
77
81
|
export declare const isRepoNetworkGraph: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
78
82
|
export declare const isForkedRepo: () => boolean;
|
|
79
83
|
export declare const isSingleGist: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
84
|
+
export declare const isGistRevision: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
80
85
|
export declare const isTrending: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
81
86
|
export declare const isBranches: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
82
87
|
export declare const isProfile: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
@@ -89,6 +94,7 @@ export declare const isUserProfileFollowingTab: (url?: URL | HTMLAnchorElement |
|
|
|
89
94
|
export declare const hasComments: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
90
95
|
export declare const hasRichTextEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
91
96
|
export declare const hasCode: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
97
|
+
export declare const hasFiles: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
92
98
|
export declare const isMarketplaceAction: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
93
99
|
export declare const isActionJobRun: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
94
100
|
export declare const isActionRun: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
package/distribution/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var reservedNames = [ "400", "401", "402", "403", "404", "405", "406", "407", "4
|
|
|
2
2
|
|
|
3
3
|
const exists = selector => Boolean(document.querySelector(selector));
|
|
4
4
|
|
|
5
|
-
const is404 = () => "Page not found · GitHub"
|
|
5
|
+
const is404 = () => document.title.startsWith("Page not found · GitHub");
|
|
6
6
|
|
|
7
7
|
const is500 = () => "Server Error · GitHub" === document.title || "Unicorn! · GitHub" === document.title || "504 Gateway Time-out" === document.title;
|
|
8
8
|
|
|
@@ -130,7 +130,7 @@ const isPRList = (url = location) => {
|
|
|
130
130
|
|
|
131
131
|
const isPRCommit = (url = location) => {
|
|
132
132
|
var _a;
|
|
133
|
-
return /^pull\/\d+\/commits\/[\da-f]{5,40}
|
|
133
|
+
return /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
const isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found · Pull Request");
|
|
@@ -189,19 +189,27 @@ const isEditingFile = (url = location) => {
|
|
|
189
189
|
return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("edit"));
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
+
const hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url);
|
|
193
|
+
|
|
192
194
|
const isEditingRelease = (url = location) => {
|
|
193
195
|
var _a;
|
|
194
196
|
return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("releases/edit"));
|
|
195
197
|
};
|
|
196
198
|
|
|
199
|
+
const hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url);
|
|
200
|
+
|
|
197
201
|
const isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");
|
|
198
202
|
|
|
203
|
+
const hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url);
|
|
204
|
+
|
|
199
205
|
const isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) && !reservedNames.includes(url.pathname.split("/", 2)[1]) && !isDashboard(url) && !isGist(url) && !isRepoSearch(url) && !isNewRepoTemplate(url);
|
|
200
206
|
|
|
201
207
|
const isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
|
|
202
208
|
|
|
203
209
|
const isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]');
|
|
204
210
|
|
|
211
|
+
const isBlank = () => exists("main .blankslate");
|
|
212
|
+
|
|
205
213
|
const isRepoTaxonomyConversationList = (url = location) => {
|
|
206
214
|
var _a;
|
|
207
215
|
return /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
|
|
@@ -257,7 +265,7 @@ const isRepoWiki = (url = location) => {
|
|
|
257
265
|
|
|
258
266
|
const isSingleCommit = (url = location) => {
|
|
259
267
|
var _a;
|
|
260
|
-
return /^commit\/[\da-f]{5,40}
|
|
268
|
+
return /^commit\/[\da-f]{5,40}$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
|
|
261
269
|
};
|
|
262
270
|
|
|
263
271
|
const isSingleFile = (url = location) => {
|
|
@@ -284,6 +292,8 @@ const isForkedRepo = () => exists('meta[name="octolytics-dimension-repository_is
|
|
|
284
292
|
|
|
285
293
|
const isSingleGist = (url = location) => isGist(url) && /^\/(gist\/)?[^/]+\/[\da-f]{32}$/.test(url.pathname);
|
|
286
294
|
|
|
295
|
+
const isGistRevision = (url = location) => isGist(url) && /^\/(gist\/)?[^/]+\/[\da-f]{32}\/revisions$/.test(url.pathname);
|
|
296
|
+
|
|
287
297
|
const isTrending = (url = location) => "/trending" === url.pathname || url.pathname.startsWith("/trending/");
|
|
288
298
|
|
|
289
299
|
const isBranches = (url = location) => {
|
|
@@ -293,7 +303,7 @@ const isBranches = (url = location) => {
|
|
|
293
303
|
|
|
294
304
|
const isProfile = (url = location) => {
|
|
295
305
|
const pathname = getCleanPathname(url);
|
|
296
|
-
return pathname.length > 0 && !pathname.includes("/") && !reservedNames.includes(pathname);
|
|
306
|
+
return pathname.length > 0 && !pathname.includes("/") && !pathname.includes(".") && !reservedNames.includes(pathname);
|
|
297
307
|
};
|
|
298
308
|
|
|
299
309
|
const isUserProfile = () => isProfile() && !isOrganizationProfile();
|
|
@@ -310,9 +320,11 @@ const isUserProfileFollowingTab = (url = location) => isProfile(url) && "followi
|
|
|
310
320
|
|
|
311
321
|
const hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isOrganizationDiscussion(url) || isSingleGist(url);
|
|
312
322
|
|
|
313
|
-
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) ||
|
|
323
|
+
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url);
|
|
324
|
+
|
|
325
|
+
const hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isBlame(url);
|
|
314
326
|
|
|
315
|
-
const
|
|
327
|
+
const hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url);
|
|
316
328
|
|
|
317
329
|
const isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/");
|
|
318
330
|
|
|
@@ -378,4 +390,4 @@ const utils = {
|
|
|
378
390
|
getRepositoryInfo: getRepo
|
|
379
391
|
};
|
|
380
392
|
|
|
381
|
-
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, isProjects, isQuickPR, isReleases, isReleasesOrTags, isRepliesSettings, isRepo, isRepoCommitList, isRepoConversationList, isRepoForksList, isRepoHome, isRepoIssueList, isRepoMainSettings, isRepoNetworkGraph, isRepoPRList, isRepoRoot, isRepoSearch, isRepoSettings, isRepoTaxonomyConversationList, isRepoTree, isRepoWiki, isRepositoryActions, isSingleCommit, isSingleFile, isSingleGist, isSingleTag, isTags, isTrending, isUserProfile, isUserProfileFollowersTab, isUserProfileFollowingTab, isUserProfileMainTab, isUserProfileRepoTab, isUserProfileStarsTab, isUserSettings, isUserTheOrganizationOwner, utils };
|
|
393
|
+
export { canUserEditOrganization, canUserEditRepo, hasCode, hasComments, hasFileEditor, hasFiles, hasReleaseEditor, hasRichTextEditor, hasWikiPageEditor, is404, is500, isActionJobRun, isActionRun, isBlame, isBlank, isBranches, isClosedPR, isCommit, isCommitList, isCompare, isConversation, isConversationList, isDashboard, isDeletingFile, isDiscussion, isDiscussionList, isDraftPR, isEditingFile, isEditingRelease, isEditingWikiPage, isEmptyRepo, isEmptyRepoRoot, isEnterprise, isFileFinder, isForkedRepo, isGist, isGistRevision, 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, isProjects, isQuickPR, isReleases, isReleasesOrTags, isRepliesSettings, isRepo, isRepoCommitList, isRepoConversationList, isRepoForksList, isRepoHome, isRepoIssueList, isRepoMainSettings, isRepoNetworkGraph, isRepoPRList, isRepoRoot, isRepoSearch, isRepoSettings, isRepoTaxonomyConversationList, isRepoTree, isRepoWiki, isRepositoryActions, isSingleCommit, isSingleFile, isSingleGist, isSingleTag, isTags, 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.10.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",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"test",
|
|
11
11
|
"extension"
|
|
12
12
|
],
|
|
13
|
-
"repository": "
|
|
13
|
+
"repository": "refined-github/github-url-detection",
|
|
14
|
+
"funding": "https://github.com/sponsors/fregante",
|
|
14
15
|
"license": "MIT",
|
|
15
16
|
"author": "Federico Brigante <me@fregante.com> (https://fregante.com)",
|
|
16
17
|
"sideEffects": false,
|
|
@@ -21,6 +22,10 @@
|
|
|
21
22
|
"distribution/index.js",
|
|
22
23
|
"distribution/index.d.ts"
|
|
23
24
|
],
|
|
25
|
+
"alias": {
|
|
26
|
+
"./this-stuff-is-just-for-local-parcel-tests": "./package.json",
|
|
27
|
+
"./collector.js": "./collector.ts"
|
|
28
|
+
},
|
|
24
29
|
"scripts": {
|
|
25
30
|
"ava": "ava --timeout 30s",
|
|
26
31
|
"build": "rollup -c",
|
|
@@ -54,28 +59,17 @@
|
|
|
54
59
|
"@typescript-eslint/no-non-null-assertion": "off",
|
|
55
60
|
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
56
61
|
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
|
|
57
|
-
"@typescript-eslint/
|
|
58
|
-
"error",
|
|
59
|
-
"always-multiline"
|
|
60
|
-
]
|
|
62
|
+
"@typescript-eslint/naming-convention": "off"
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
],
|
|
64
66
|
"rules": {
|
|
65
|
-
"camelcase": "off"
|
|
66
|
-
"comma-dangle": [
|
|
67
|
-
"error",
|
|
68
|
-
"always-multiline"
|
|
69
|
-
],
|
|
70
|
-
"import/extensions": "off",
|
|
71
|
-
"import/no-useless-path-segments": "off",
|
|
72
|
-
"unicorn/import-index": "off"
|
|
67
|
+
"camelcase": "off"
|
|
73
68
|
}
|
|
74
69
|
},
|
|
75
70
|
"ava": {
|
|
76
71
|
"environmentVariables": {
|
|
77
|
-
"TS_NODE_FILES": "true"
|
|
78
|
-
"TS_NODE_COMPILER_OPTIONS": "{\"module\": \"esnext\", \"allowSyntheticDefaultImports\": true}"
|
|
72
|
+
"TS_NODE_FILES": "true"
|
|
79
73
|
},
|
|
80
74
|
"extensions": {
|
|
81
75
|
"ts": "module"
|
|
@@ -90,25 +84,26 @@
|
|
|
90
84
|
},
|
|
91
85
|
"devDependencies": {
|
|
92
86
|
"@rollup/plugin-json": "^4.1.0",
|
|
93
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
94
|
-
"@rollup/plugin-typescript": "^8.
|
|
87
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
88
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
95
89
|
"@sindresorhus/tsconfig": "^2.0.0",
|
|
90
|
+
"@types/estree": "^0.0.50",
|
|
96
91
|
"@types/jsdom": "^16.2.13",
|
|
97
92
|
"ava": "^3.15.0",
|
|
98
93
|
"github-reserved-names": "^2.0.4",
|
|
99
|
-
"jsdom": "^
|
|
94
|
+
"jsdom": "^19.0.0",
|
|
100
95
|
"npm-run-all": "^4.1.5",
|
|
101
96
|
"parcel-bundler": "^1.12.4",
|
|
102
97
|
"parcel-plugin-svelte": "^4.0.9",
|
|
103
|
-
"rollup": "^2.
|
|
98
|
+
"rollup": "^2.60.2",
|
|
104
99
|
"rollup-plugin-terser": "^7.0.2",
|
|
105
100
|
"strip-indent": "^4.0.0",
|
|
106
|
-
"svelte": "^3.
|
|
107
|
-
"svelte-check": "^2.2.
|
|
108
|
-
"ts-node": "^10.
|
|
101
|
+
"svelte": "^3.44.2",
|
|
102
|
+
"svelte-check": "^2.2.10",
|
|
103
|
+
"ts-node": "^10.4.0",
|
|
109
104
|
"tslib": "^2.3.1",
|
|
110
|
-
"typescript": "^4.
|
|
111
|
-
"xo": "^0.
|
|
105
|
+
"typescript": "^4.5.2",
|
|
106
|
+
"xo": "^0.47.0"
|
|
112
107
|
},
|
|
113
108
|
"engines": {
|
|
114
109
|
"node": ">=12"
|
package/readme.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
Battle-tested by and extracted from the [Refined GitHub](https://github.com/sindresorhus/refined-github) extension.
|
|
6
6
|
|
|
7
|
-
- Try the live [demo](https://
|
|
8
|
-
- See the code and expected URLs for [every detection](https://github.com/
|
|
7
|
+
- Try the live [demo](https://refined-github.github.io/github-url-detection/)
|
|
8
|
+
- See the code and expected URLs for [every detection](https://github.com/refined-github/github-url-detection/blob/main/index.ts)
|
|
9
9
|
|
|
10
10
|
## Install
|
|
11
11
|
|
|
@@ -21,7 +21,7 @@ import * as pageDetect from 'github-url-detection';
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
const href = 'https://github.com/
|
|
24
|
+
const href = 'https://github.com/refined-github/github-url-detection/issues/1';
|
|
25
25
|
if (pageDetect.isIssue(new URL(href))) { // Pass the URL as an `URL` object
|
|
26
26
|
alert('The passed URL is of an issue!')
|
|
27
27
|
}
|
|
@@ -50,7 +50,7 @@ if (pageDetect.isConversationList()) {
|
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
```js
|
|
53
|
-
if (pageDetect.isConversationList(new URL('https://github.com/
|
|
53
|
+
if (pageDetect.isConversationList(new URL('https://github.com/refined-github/github-url-detection/pulls'))) {
|
|
54
54
|
alert('You’re looking at a issues or PRs list!')
|
|
55
55
|
}
|
|
56
56
|
```
|