github-url-detection 5.5.0 → 5.8.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.
@@ -28,6 +28,7 @@ export declare const isOrganizationDiscussion: (url?: URL | HTMLAnchorElement |
28
28
  export declare const isOwnUserProfile: () => boolean;
29
29
  export declare const isOwnOrganizationProfile: () => boolean;
30
30
  export declare const isProject: (url?: URL | HTMLAnchorElement | Location) => boolean;
31
+ export declare const isProjects: (url?: URL | HTMLAnchorElement | Location) => boolean;
31
32
  export declare const isDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean;
32
33
  export declare const isDiscussionList: (url?: URL | HTMLAnchorElement | Location) => boolean;
33
34
  export declare const isPR: (url?: URL | HTMLAnchorElement | Location) => boolean;
@@ -45,11 +46,17 @@ export declare const isDraftPR: () => boolean;
45
46
  export declare const isOpenPR: () => boolean;
46
47
  export declare const isMergedPR: () => boolean;
47
48
  export declare const isClosedPR: () => boolean;
49
+ export declare const isReleases: (url?: URL | HTMLAnchorElement | Location) => boolean;
50
+ export declare const isTags: (url?: URL | HTMLAnchorElement | Location) => boolean;
51
+ export declare const isSingleTag: (url?: URL | HTMLAnchorElement | Location) => boolean;
48
52
  export declare const isReleasesOrTags: (url?: URL | HTMLAnchorElement | Location) => boolean;
49
53
  export declare const isDeletingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
50
54
  export declare const isEditingFile: (url?: URL | HTMLAnchorElement | Location) => boolean;
55
+ export declare const hasFileEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
51
56
  export declare const isEditingRelease: (url?: URL | HTMLAnchorElement | Location) => boolean;
57
+ export declare const hasReleaseEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
52
58
  export declare const isEditingWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean;
59
+ export declare const hasWikiPageEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
53
60
  export declare const isRepo: (url?: URL | HTMLAnchorElement | Location) => boolean;
54
61
  export declare const isEmptyRepoRoot: () => boolean;
55
62
  export declare const isEmptyRepo: () => boolean;
@@ -82,7 +89,6 @@ export declare const isUserProfileRepoTab: (url?: URL | HTMLAnchorElement | Loca
82
89
  export declare const isUserProfileStarsTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
83
90
  export declare const isUserProfileFollowersTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
84
91
  export declare const isUserProfileFollowingTab: (url?: URL | HTMLAnchorElement | Location) => boolean;
85
- export declare const isSingleTag: (url?: URL | HTMLAnchorElement | Location) => boolean;
86
92
  export declare const hasComments: (url?: URL | HTMLAnchorElement | Location) => boolean;
87
93
  export declare const hasRichTextEditor: (url?: URL | HTMLAnchorElement | Location) => boolean;
88
94
  export declare const hasCode: (url?: URL | HTMLAnchorElement | Location) => boolean;
@@ -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" === document.title;
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
 
@@ -98,6 +98,11 @@ const isProject = (url = location) => {
98
98
  return /^projects\/\d+/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
99
99
  };
100
100
 
101
+ const isProjects = (url = location) => {
102
+ var _a;
103
+ return "projects" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
104
+ };
105
+
101
106
  const isDiscussion = (url = location) => {
102
107
  var _a;
103
108
  return /^discussions\/\d+/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
@@ -157,11 +162,23 @@ const isMergedPR = () => exists('#partial-discussion-header [title="Status: Merg
157
162
 
158
163
  const isClosedPR = () => exists('#partial-discussion-header [title="Status: Closed"], #partial-discussion-header [title="Status: Merged"]');
159
164
 
160
- const isReleasesOrTags = (url = location) => {
165
+ const isReleases = (url = location) => {
166
+ var _a;
167
+ return "releases" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
168
+ };
169
+
170
+ const isTags = (url = location) => {
171
+ var _a;
172
+ return "tags" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
173
+ };
174
+
175
+ const isSingleTag = (url = location) => {
161
176
  var _a;
162
- return /^tags$|^releases($|\/tag)/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
177
+ return /^(releases\/tag)/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
163
178
  };
164
179
 
180
+ const isReleasesOrTags = (url = location) => isReleases(url) || isTags(url) || isSingleTag(url);
181
+
165
182
  const isDeletingFile = (url = location) => {
166
183
  var _a;
167
184
  return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("delete"));
@@ -172,13 +189,19 @@ const isEditingFile = (url = location) => {
172
189
  return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("edit"));
173
190
  };
174
191
 
192
+ const hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url);
193
+
175
194
  const isEditingRelease = (url = location) => {
176
195
  var _a;
177
196
  return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("releases/edit"));
178
197
  };
179
198
 
199
+ const hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url);
200
+
180
201
  const isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");
181
202
 
203
+ const hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url);
204
+
182
205
  const isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) && !reservedNames.includes(url.pathname.split("/", 2)[1]) && !isDashboard(url) && !isGist(url) && !isRepoSearch(url) && !isNewRepoTemplate(url);
183
206
 
184
207
  const isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
@@ -291,14 +314,9 @@ const isUserProfileFollowersTab = (url = location) => isProfile(url) && "followe
291
314
 
292
315
  const isUserProfileFollowingTab = (url = location) => isProfile(url) && "following" === new URLSearchParams(url.search).get("tab");
293
316
 
294
- const isSingleTag = (url = location) => {
295
- var _a;
296
- return /^(releases\/tag)/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
297
- };
298
-
299
317
  const hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isOrganizationDiscussion(url) || isSingleGist(url);
300
318
 
301
- const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || isNewRelease(url) || isDiscussion(url);
319
+ const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url);
302
320
 
303
321
  const hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isBlame(url);
304
322
 
@@ -339,7 +357,7 @@ const getUsername = () => {
339
357
  return null === (_a = document.querySelector('meta[name="user-login"]')) || void 0 === _a ? void 0 : _a.getAttribute("content");
340
358
  };
341
359
 
342
- const getCleanPathname = (url = location) => url.pathname.slice(1, url.pathname.endsWith("/") ? -1 : void 0);
360
+ const getCleanPathname = (url = location) => url.pathname.replace(/\/+/g, "/").slice(1, url.pathname.endsWith("/") ? -1 : void 0);
343
361
 
344
362
  const getRepo = url => {
345
363
  if (!url) {
@@ -366,4 +384,4 @@ const utils = {
366
384
  getRepositoryInfo: getRepo
367
385
  };
368
386
 
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 };
387
+ export { canUserEditOrganization, canUserEditRepo, hasCode, hasComments, hasFileEditor, hasReleaseEditor, hasRichTextEditor, hasWikiPageEditor, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-url-detection",
3
- "version": "5.5.0",
3
+ "version": "5.8.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",
@@ -11,6 +11,7 @@
11
11
  "extension"
12
12
  ],
13
13
  "repository": "fregante/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,