github-url-detection 8.1.1 → 9.0.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.
@@ -1,6 +1,7 @@
1
1
  export declare const is404: () => boolean;
2
2
  export declare const is500: () => boolean;
3
3
  export declare const isPasswordConfirmation: () => boolean;
4
+ export declare const isLoggedIn: () => boolean;
4
5
  export declare const isBlame: (url?: URL | HTMLAnchorElement | Location) => boolean;
5
6
  export declare const isCommit: (url?: URL | HTMLAnchorElement | Location) => boolean;
6
7
  export declare const isCommitList: (url?: URL | HTMLAnchorElement | Location) => boolean;
@@ -1,369 +1,86 @@
1
- const reservedNames = [
2
- "300",
3
- "302",
4
- "400",
5
- "401",
6
- "402",
7
- "403",
8
- "404",
9
- "405",
10
- "406",
11
- "407",
12
- "408",
13
- "409",
14
- "410",
15
- "411",
16
- "412",
17
- "413",
18
- "414",
19
- "415",
20
- "416",
21
- "417",
22
- "418",
23
- "419",
24
- "420",
25
- "421",
26
- "422",
27
- "423",
28
- "424",
29
- "425",
30
- "426",
31
- "427",
32
- "428",
33
- "429",
34
- "430",
35
- "431",
36
- "500",
37
- "501",
38
- "502",
39
- "503",
40
- "504",
41
- "505",
42
- "506",
43
- "507",
44
- "508",
45
- "509",
46
- "510",
47
- "511",
48
- "693",
49
- "694",
50
- "695",
51
- "900",
52
- "about",
53
- "access",
54
- "account",
55
- "admin",
56
- "advisories",
57
- "anonymous",
58
- "any",
59
- "api",
60
- "apps",
61
- "attributes",
62
- "auth",
63
- "billing",
64
- "blob",
65
- "blog",
66
- "bounty",
67
- "branches",
68
- "business",
69
- "businesses",
70
- "c",
71
- "cache",
72
- "case-studies",
73
- "categories",
74
- "central",
75
- "certification",
76
- "changelog",
77
- "chat",
78
- "cla",
79
- "cloud",
80
- "codereview",
81
- "collection",
82
- "collections",
83
- "comments",
84
- "commit",
85
- "commits",
86
- "community",
87
- "companies",
88
- "compare",
89
- "contact",
90
- "contributing",
91
- "cookbook",
92
- "coupons",
93
- "customer-stories",
94
- "customer",
95
- "customers",
96
- "dashboard-feed",
97
- "dashboard",
98
- "dashboards",
99
- "design",
100
- "develop",
101
- "developer",
102
- "diff",
103
- "discover",
104
- "discussions",
105
- "docs",
106
- "downloads",
107
- "downtime",
108
- "editor",
109
- "editors",
110
- "edu",
111
- "enterprise",
112
- "events",
113
- "explore",
114
- "featured",
115
- "features",
116
- "files",
117
- "fixtures",
118
- "forked",
119
- "garage",
120
- "ghost",
121
- "gist",
122
- "gists",
123
- "graphs",
124
- "guide",
125
- "guides",
126
- "help",
127
- "help-wanted",
128
- "home",
129
- "hooks",
130
- "hosting",
131
- "hovercards",
132
- "identity",
133
- "images",
134
- "inbox",
135
- "individual",
136
- "info",
137
- "integration",
138
- "interfaces",
139
- "introduction",
140
- "invalid-email-address",
141
- "investors",
142
- "issues",
143
- "jobs",
144
- "join",
145
- "journal",
146
- "journals",
147
- "lab",
148
- "labs",
149
- "languages",
150
- "launch",
151
- "layouts",
152
- "learn",
153
- "legal",
154
- "library",
155
- "linux",
156
- "listings",
157
- "lists",
158
- "login",
159
- "logos",
160
- "logout",
161
- "mac",
162
- "maintenance",
163
- "malware",
164
- "man",
165
- "marketplace",
166
- "mention",
167
- "mentioned",
168
- "mentioning",
169
- "mentions",
170
- "migrating",
171
- "milestones",
172
- "mine",
173
- "mirrors",
174
- "mobile",
175
- "navigation",
176
- "network",
177
- "new",
178
- "news",
179
- "none",
180
- "nonprofit",
181
- "nonprofits",
182
- "notices",
183
- "notifications",
184
- "oauth",
185
- "offer",
186
- "open-source",
187
- "organisations",
188
- "organizations",
189
- "orgs",
190
- "pages",
191
- "partners",
192
- "payments",
193
- "personal",
194
- "plans",
195
- "plugins",
196
- "popular",
197
- "popularity",
198
- "posts",
199
- "press",
200
- "pricing",
201
- "professional",
202
- "projects",
203
- "pulls",
204
- "raw",
205
- "readme",
206
- "recommendations",
207
- "redeem",
208
- "releases",
209
- "render",
210
- "reply",
211
- "repositories",
212
- "resources",
213
- "restore",
214
- "revert",
215
- "save-net-neutrality",
216
- "saved",
217
- "scraping",
218
- "search",
219
- "security",
220
- "services",
221
- "sessions",
222
- "settings",
223
- "shareholders",
224
- "shop",
225
- "showcases",
226
- "signin",
227
- "signup",
228
- "site",
229
- "spam",
230
- "sponsors",
231
- "ssh",
232
- "staff",
233
- "starred",
234
- "stars",
235
- "static",
236
- "status",
237
- "statuses",
238
- "storage",
239
- "store",
240
- "stories",
241
- "styleguide",
242
- "subscriptions",
243
- "suggest",
244
- "suggestion",
245
- "suggestions",
246
- "support",
247
- "suspended",
248
- "talks",
249
- "teach",
250
- "teacher",
251
- "teachers",
252
- "teaching",
253
- "team",
254
- "teams",
255
- "ten",
256
- "terms",
257
- "timeline",
258
- "topic",
259
- "topics",
260
- "tos",
261
- "tour",
262
- "train",
263
- "training",
264
- "translations",
265
- "tree",
266
- "trending",
267
- "updates",
268
- "username",
269
- "users",
270
- "visualization",
271
- "w",
272
- "watching",
273
- "wiki",
274
- "windows",
275
- "works-with",
276
- "www0",
277
- "www1",
278
- "www2",
279
- "www3",
280
- "www4",
281
- "www5",
282
- "www6",
283
- "www7",
284
- "www8",
285
- "www9"
286
- ];
287
- const $ = (selector) => document.querySelector(selector);
288
- const exists = (selector) => Boolean($(selector));
289
- const is404 = () => /^(Page|File) not found · GitHub/.test(document.title);
290
- const is500 = () => document.title === "Server Error · GitHub" || document.title === "Unicorn! · GitHub" || document.title === "504 Gateway Time-out";
291
- const isPasswordConfirmation = () => document.title === "Confirm password" || document.title === "Confirm access";
292
- const isBlame = (url = location) => Boolean(getRepo(url)?.path.startsWith("blame/"));
293
- const isCommit = (url = location) => isSingleCommit(url) || isPRCommit(url);
294
- const isCommitList = (url = location) => isRepoCommitList(url) || isPRCommitList(url);
295
- const isRepoCommitList = (url = location) => Boolean(getRepo(url)?.path.startsWith("commits"));
296
- const isCompare = (url = location) => Boolean(getRepo(url)?.path.startsWith("compare"));
297
- const isCompareWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).split("/").slice(3, 5).includes("_compare");
298
- const isDashboard = (url = location) => !isGist(url) && /^$|^(orgs\/[^/]+\/)?dashboard(-feed)?(\/|$)/.test(getCleanPathname(url));
299
- const isEnterprise = (url = location) => url.hostname !== "github.com" && url.hostname !== "gist.github.com";
300
- const isGist = (url = location) => typeof getCleanGistPathname(url) === "string";
301
- const isGlobalIssueOrPRList = (url = location) => ["issues", "pulls"].includes(url.pathname.split("/", 2)[1]);
302
- const isGlobalSearchResults = (url = location) => url.pathname === "/search" && new URLSearchParams(url.search).get("q") !== null;
303
- const isIssue = (url = location) => /^issues\/\d+/.test(getRepo(url)?.path) && document.title !== "GitHub · Where software is built";
304
- const isIssueOrPRList = (url = location) => isGlobalIssueOrPRList(url) || isRepoIssueOrPRList(url) || isMilestone(url);
305
- const isConversation = (url = location) => isIssue(url) || isPRConversation(url);
306
- const isLabelList = (url = location) => getRepo(url)?.path === "labels";
307
- const isMilestone = (url = location) => /^milestone\/\d+/.test(getRepo(url)?.path);
308
- const isMilestoneList = (url = location) => getRepo(url)?.path === "milestones";
309
- const isNewFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("new"));
310
- const isNewIssue = (url = location) => getRepo(url)?.path === "issues/new";
311
- const isNewRelease = (url = location) => getRepo(url)?.path === "releases/new";
312
- const isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_new");
313
- const isNotifications = (url = location) => getCleanPathname(url) === "notifications";
314
- const isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
315
- const isOrganizationRepo = () => exists('.AppHeader-context-full [data-hovercard-type="organization"]');
316
- const isTeamDiscussion = (url = location) => Boolean(getOrg(url)?.path.startsWith("teams"));
317
- const isOwnUserProfile = () => getCleanPathname() === getUsername();
318
- const isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');
319
- const isProject = (url = location) => /^projects\/\d+/.test(getRepo(url)?.path);
320
- const isProjects = (url = location) => getRepo(url)?.path === "projects";
321
- const isDiscussion = (url = location) => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path);
322
- const isNewDiscussion = (url = location) => getRepo(url)?.path === "discussions/new" || getOrg(url)?.path === "discussions/new";
323
- const isDiscussionList = (url = location) => getRepo(url)?.path === "discussions" || getOrg(url)?.path === "discussions";
324
- const isPR = (url = location) => /^pull\/\d+/.test(getRepo(url)?.path) && !isPRConflicts(url);
325
- const isPRConflicts = (url = location) => /^pull\/\d+\/conflicts/.test(getRepo(url)?.path);
326
- const isPRList = (url = location) => url.pathname === "/pulls" || getRepo(url)?.path === "pulls";
327
- const isPRCommit = (url = location) => /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
328
- const isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found · Pull Request");
329
- const isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found · Pull Request");
330
- const isPRConversation = (url = location) => /^pull\/\d+$/.test(getRepo(url)?.path);
331
- const isPRCommitList = (url = location) => /^pull\/\d+\/commits$/.test(getRepo(url)?.path);
332
- const isPRFiles = (url = location) => /^pull\/\d+\/files/.test(getRepo(url)?.path) || isPRCommit(url);
333
- const isQuickPR = (url = location) => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search);
334
- const isDraftPR = () => exists("#partial-discussion-header .octicon-git-pull-request-draft");
335
- const isOpenPR = () => exists("#partial-discussion-header :is(.octicon-git-pull-request, .octicon-git-pull-request-draft)");
336
- const isMergedPR = () => exists("#partial-discussion-header .octicon-git-merge");
337
- const isClosedPR = () => exists("#partial-discussion-header :is(.octicon-git-pull-request-closed, .octicon-git-merge)");
338
- const isClosedIssue = () => exists("#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)");
339
- const isReleases = (url = location) => getRepo(url)?.path === "releases";
340
- const isTags = (url = location) => getRepo(url)?.path === "tags";
341
- const isSingleReleaseOrTag = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/tag"));
342
- const isReleasesOrTags = (url = location) => isReleases(url) || isTags(url);
343
- const isDeletingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("delete"));
344
- const isEditingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("edit"));
345
- const hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url);
346
- const isEditingRelease = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/edit"));
347
- const hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url);
348
- const isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");
349
- const hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url);
350
- const isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) && !reservedNames.includes(url.pathname.split("/", 2)[1]) && !isDashboard(url) && !isGist(url) && !isNewRepoTemplate(url);
351
- const hasRepoHeader = (url = location) => isRepo(url) && !isRepoSearch(url);
352
- const isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
353
- const isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]');
354
- const isPublicRepo = () => exists('meta[name="octolytics-dimension-repository_public"][content="true"]');
355
- const isArchivedRepo = () => Boolean(isRepo() && $("main > .flash-warn")?.textContent.includes("archived"));
356
- const isBlank = () => exists("main .blankslate:not([hidden] .blankslate)");
357
- const isRepoTaxonomyIssueOrPRList = (url = location) => /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(getRepo(url)?.path);
358
- const isRepoIssueOrPRList = (url = location) => isRepoPRList(url) || isRepoIssueList(url) || isRepoTaxonomyIssueOrPRList(url);
359
- const isRepoPRList = (url = location) => Boolean(getRepo(url)?.path.startsWith("pulls"));
360
- const isRepoIssueList = (url = location) => (
1
+ // index.ts
2
+ import reservedNames from "github-reserved-names/reserved-names.json" with { type: "json" };
3
+ var $ = (selector) => document.querySelector(selector);
4
+ var exists = (selector) => Boolean($(selector));
5
+ var is404 = () => /^(Page|File) not found · GitHub/.test(document.title);
6
+ var is500 = () => document.title === "Server Error \xB7 GitHub" || document.title === "Unicorn! \xB7 GitHub" || document.title === "504 Gateway Time-out";
7
+ var isPasswordConfirmation = () => document.title === "Confirm password" || document.title === "Confirm access";
8
+ var isLoggedIn = () => exists("body.logged-in");
9
+ var isBlame = (url = location) => Boolean(getRepo(url)?.path.startsWith("blame/"));
10
+ var isCommit = (url = location) => isSingleCommit(url) || isPRCommit(url);
11
+ var isCommitList = (url = location) => isRepoCommitList(url) || isPRCommitList(url);
12
+ var isRepoCommitList = (url = location) => Boolean(getRepo(url)?.path.startsWith("commits"));
13
+ var isCompare = (url = location) => Boolean(getRepo(url)?.path.startsWith("compare"));
14
+ var isCompareWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).split("/").slice(3, 5).includes("_compare");
15
+ var isDashboard = (url = location) => !isGist(url) && /^$|^(orgs\/[^/]+\/)?dashboard(-feed)?(\/|$)/.test(getCleanPathname(url));
16
+ var isEnterprise = (url = location) => url.hostname !== "github.com" && url.hostname !== "gist.github.com";
17
+ var isGist = (url = location) => typeof getCleanGistPathname(url) === "string";
18
+ var isGlobalIssueOrPRList = (url = location) => ["issues", "pulls"].includes(url.pathname.split("/", 2)[1]);
19
+ var isGlobalSearchResults = (url = location) => url.pathname === "/search" && new URLSearchParams(url.search).get("q") !== null;
20
+ var isIssue = (url = location) => /^issues\/\d+/.test(getRepo(url)?.path) && document.title !== "GitHub \xB7 Where software is built";
21
+ var isIssueOrPRList = (url = location) => isGlobalIssueOrPRList(url) || isRepoIssueOrPRList(url) || isMilestone(url);
22
+ var isConversation = (url = location) => isIssue(url) || isPRConversation(url);
23
+ var isLabelList = (url = location) => getRepo(url)?.path === "labels";
24
+ var isMilestone = (url = location) => /^milestone\/\d+/.test(getRepo(url)?.path);
25
+ var isMilestoneList = (url = location) => getRepo(url)?.path === "milestones";
26
+ var isNewFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("new"));
27
+ var isNewIssue = (url = location) => getRepo(url)?.path === "issues/new";
28
+ var isNewRelease = (url = location) => getRepo(url)?.path === "releases/new";
29
+ var isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_new");
30
+ var isNotifications = (url = location) => getCleanPathname(url) === "notifications";
31
+ var isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
32
+ var isOrganizationRepo = () => exists('.AppHeader-context-full [data-hovercard-type="organization"]');
33
+ var isTeamDiscussion = (url = location) => Boolean(getOrg(url)?.path.startsWith("teams"));
34
+ var isOwnUserProfile = () => getCleanPathname() === getUsername();
35
+ var isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');
36
+ var isProject = (url = location) => /^projects\/\d+/.test(getRepo(url)?.path);
37
+ var isProjects = (url = location) => getRepo(url)?.path === "projects";
38
+ var isDiscussion = (url = location) => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path);
39
+ var isNewDiscussion = (url = location) => getRepo(url)?.path === "discussions/new" || getOrg(url)?.path === "discussions/new";
40
+ var isDiscussionList = (url = location) => getRepo(url)?.path === "discussions" || getOrg(url)?.path === "discussions";
41
+ var isPR = (url = location) => /^pull\/\d+/.test(getRepo(url)?.path) && !isPRConflicts(url);
42
+ var isPRConflicts = (url = location) => /^pull\/\d+\/conflicts/.test(getRepo(url)?.path);
43
+ var isPRList = (url = location) => url.pathname === "/pulls" || getRepo(url)?.path === "pulls";
44
+ var isPRCommit = (url = location) => /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
45
+ var isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found \xB7 Pull Request");
46
+ var isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found \xB7 Pull Request");
47
+ var isPRConversation = (url = location) => /^pull\/\d+$/.test(getRepo(url)?.path);
48
+ var isPRCommitList = (url = location) => /^pull\/\d+\/commits$/.test(getRepo(url)?.path);
49
+ var isPRFiles = (url = location) => /^pull\/\d+\/files/.test(getRepo(url)?.path) || isPRCommit(url);
50
+ var isQuickPR = (url = location) => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search);
51
+ var isDraftPR = () => exists("#partial-discussion-header .octicon-git-pull-request-draft");
52
+ var isOpenPR = () => exists("#partial-discussion-header :is(.octicon-git-pull-request, .octicon-git-pull-request-draft)");
53
+ var isMergedPR = () => exists("#partial-discussion-header .octicon-git-merge");
54
+ var isClosedPR = () => exists("#partial-discussion-header :is(.octicon-git-pull-request-closed, .octicon-git-merge)");
55
+ var isClosedIssue = () => exists("#partial-discussion-header :is(.octicon-issue-closed, .octicon-skip)");
56
+ var isReleases = (url = location) => getRepo(url)?.path === "releases";
57
+ var isTags = (url = location) => getRepo(url)?.path === "tags";
58
+ var isSingleReleaseOrTag = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/tag"));
59
+ var isReleasesOrTags = (url = location) => isReleases(url) || isTags(url);
60
+ var isDeletingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("delete"));
61
+ var isEditingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("edit"));
62
+ var hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url);
63
+ var isEditingRelease = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/edit"));
64
+ var hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url);
65
+ var isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");
66
+ var hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url);
67
+ var isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) && !reservedNames.includes(url.pathname.split("/", 2)[1]) && !isDashboard(url) && !isGist(url) && !isNewRepoTemplate(url);
68
+ var hasRepoHeader = (url = location) => isRepo(url) && !isRepoSearch(url);
69
+ var isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
70
+ var isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]');
71
+ var isPublicRepo = () => exists('meta[name="octolytics-dimension-repository_public"][content="true"]');
72
+ var isArchivedRepo = () => Boolean(isRepo() && $("main > .flash-warn")?.textContent.includes("archived"));
73
+ var isBlank = () => exists("main .blankslate:not([hidden] .blankslate)");
74
+ var isRepoTaxonomyIssueOrPRList = (url = location) => /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(getRepo(url)?.path);
75
+ var isRepoIssueOrPRList = (url = location) => isRepoPRList(url) || isRepoIssueList(url) || isRepoTaxonomyIssueOrPRList(url);
76
+ var isRepoPRList = (url = location) => Boolean(getRepo(url)?.path.startsWith("pulls"));
77
+ var isRepoIssueList = (url = location) => (
361
78
  // `issues/fregante` is a list but `issues/1`, `issues/new`, `issues/new/choose`, `issues/templates/edit` aren’t
362
79
  /^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(getRepo(url)?.path)
363
80
  );
364
- const hasSearchParameter = (url) => new URLSearchParams(url.search).get("search") === "1";
365
- const isRepoHome = (url = location) => getRepo(url)?.path === "" && !hasSearchParameter(url);
366
- const _isRepoRoot = (url) => {
81
+ var hasSearchParameter = (url) => new URLSearchParams(url.search).get("search") === "1";
82
+ var isRepoHome = (url = location) => getRepo(url)?.path === "" && !hasSearchParameter(url);
83
+ var _isRepoRoot = (url) => {
367
84
  const repository = getRepo(url ?? location);
368
85
  if (!repository) {
369
86
  return false;
@@ -376,52 +93,52 @@ const _isRepoRoot = (url) => {
376
93
  }
377
94
  return repository.path.startsWith("tree/") && document.title.startsWith(repository.nameWithOwner) && !document.title.endsWith(repository.nameWithOwner);
378
95
  };
379
- const isRepoRoot = (url) => !hasSearchParameter(url ?? location) && _isRepoRoot(url);
380
- const isRepoSearch = (url = location) => getRepo(url)?.path === "search";
381
- const isRepoSettings = (url = location) => Boolean(getRepo(url)?.path.startsWith("settings"));
382
- const isRepoMainSettings = (url = location) => getRepo(url)?.path === "settings";
383
- const isRepliesSettings = (url = location) => url.pathname.startsWith("/settings/replies");
384
- const isUserSettings = (url = location) => url.pathname.startsWith("/settings/");
385
- const isRepoTree = (url = location) => _isRepoRoot(url) || Boolean(getRepo(url)?.path.startsWith("tree/"));
386
- const isRepoWiki = (url = location) => Boolean(getRepo(url)?.path.startsWith("wiki"));
387
- const isSingleCommit = (url = location) => /^commit\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
388
- const isSingleFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("blob/"));
389
- const isFileFinder = (url = location) => Boolean(getRepo(url)?.path.startsWith("find/"));
390
- const isRepoFile404 = (url = location) => (isSingleFile(url) || isRepoTree(url)) && document.title.startsWith("File not found");
391
- const isRepoForksList = (url = location) => getRepo(url)?.path === "network/members";
392
- const isRepoNetworkGraph = (url = location) => getRepo(url)?.path === "network";
393
- const isForkedRepo = () => exists('meta[name="octolytics-dimension-repository_is_fork"][content="true"]');
394
- const isSingleGist = (url = location) => /^[^/]+\/[\da-f]{20,32}(\/[\da-f]{40})?$/.test(getCleanGistPathname(url));
395
- const isGistRevision = (url = location) => /^[^/]+\/[\da-f]{20,32}\/revisions$/.test(getCleanGistPathname(url));
396
- const isTrending = (url = location) => url.pathname === "/trending" || url.pathname.startsWith("/trending/");
397
- const isBranches = (url = location) => Boolean(getRepo(url)?.path.startsWith("branches"));
398
- const doesLookLikeAProfile = (string) => typeof string === "string" && string.length > 0 && !string.includes("/") && !string.includes(".") && !reservedNames.includes(string);
399
- const isProfile = (url = location) => !isGist(url) && doesLookLikeAProfile(getCleanPathname(url));
400
- const isGistProfile = (url = location) => doesLookLikeAProfile(getCleanGistPathname(url));
401
- const isUserProfile = () => isProfile() && !isOrganizationProfile();
402
- const isPrivateUserProfile = () => isUserProfile() && !exists('.UnderlineNav-item[href$="tab=stars"]');
403
- const isUserProfileMainTab = () => isUserProfile() && !new URLSearchParams(location.search).has("tab");
404
- const isUserProfileRepoTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "repositories";
405
- const isUserProfileStarsTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "stars";
406
- const isUserProfileFollowersTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "followers";
407
- const isUserProfileFollowingTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "following";
408
- const isProfileRepoList = (url = location) => isUserProfileRepoTab(url) || getOrg(url)?.path === "repositories";
409
- const hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isTeamDiscussion(url) || isSingleGist(url);
410
- const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url) || isNewDiscussion(url);
411
- const hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isCompareWikiPage(url) || isBlame(url);
412
- const hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url);
413
- const isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/");
414
- const isActionJobRun = (url = location) => Boolean(getRepo(url)?.path.startsWith("runs/"));
415
- const isActionRun = (url = location) => /^(actions\/)?runs/.test(getRepo(url)?.path);
416
- const isNewAction = (url = location) => getRepo(url)?.path === "actions/new";
417
- const isRepositoryActions = (url = location) => /^actions(\/workflows\/.+\.ya?ml)?$/.test(getRepo(url)?.path);
418
- const isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
419
- const canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
420
- const isNewRepo = (url = location) => url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));
421
- const isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate");
422
- const getUsername = () => $('meta[name="user-login"]')?.getAttribute("content");
423
- const getCleanPathname = (url = location) => url.pathname.replaceAll(/\/+/g, "/").slice(1, url.pathname.endsWith("/") ? -1 : void 0);
424
- const getCleanGistPathname = (url = location) => {
96
+ var isRepoRoot = (url) => !hasSearchParameter(url ?? location) && _isRepoRoot(url);
97
+ var isRepoSearch = (url = location) => getRepo(url)?.path === "search";
98
+ var isRepoSettings = (url = location) => Boolean(getRepo(url)?.path.startsWith("settings"));
99
+ var isRepoMainSettings = (url = location) => getRepo(url)?.path === "settings";
100
+ var isRepliesSettings = (url = location) => url.pathname.startsWith("/settings/replies");
101
+ var isUserSettings = (url = location) => url.pathname.startsWith("/settings/");
102
+ var isRepoTree = (url = location) => _isRepoRoot(url) || Boolean(getRepo(url)?.path.startsWith("tree/"));
103
+ var isRepoWiki = (url = location) => Boolean(getRepo(url)?.path.startsWith("wiki"));
104
+ var isSingleCommit = (url = location) => /^commit\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
105
+ var isSingleFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("blob/"));
106
+ var isFileFinder = (url = location) => Boolean(getRepo(url)?.path.startsWith("find/"));
107
+ var isRepoFile404 = (url = location) => (isSingleFile(url) || isRepoTree(url)) && document.title.startsWith("File not found");
108
+ var isRepoForksList = (url = location) => getRepo(url)?.path === "network/members";
109
+ var isRepoNetworkGraph = (url = location) => getRepo(url)?.path === "network";
110
+ var isForkedRepo = () => exists('meta[name="octolytics-dimension-repository_is_fork"][content="true"]');
111
+ var isSingleGist = (url = location) => /^[^/]+\/[\da-f]{20,32}(\/[\da-f]{40})?$/.test(getCleanGistPathname(url));
112
+ var isGistRevision = (url = location) => /^[^/]+\/[\da-f]{20,32}\/revisions$/.test(getCleanGistPathname(url));
113
+ var isTrending = (url = location) => url.pathname === "/trending" || url.pathname.startsWith("/trending/");
114
+ var isBranches = (url = location) => Boolean(getRepo(url)?.path.startsWith("branches"));
115
+ var doesLookLikeAProfile = (string) => typeof string === "string" && string.length > 0 && !string.includes("/") && !string.includes(".") && !reservedNames.includes(string);
116
+ var isProfile = (url = location) => !isGist(url) && doesLookLikeAProfile(getCleanPathname(url));
117
+ var isGistProfile = (url = location) => doesLookLikeAProfile(getCleanGistPathname(url));
118
+ var isUserProfile = () => isProfile() && !isOrganizationProfile();
119
+ var isPrivateUserProfile = () => isUserProfile() && !exists('.UnderlineNav-item[href$="tab=stars"]');
120
+ var isUserProfileMainTab = () => isUserProfile() && !new URLSearchParams(location.search).has("tab");
121
+ var isUserProfileRepoTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "repositories";
122
+ var isUserProfileStarsTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "stars";
123
+ var isUserProfileFollowersTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "followers";
124
+ var isUserProfileFollowingTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "following";
125
+ var isProfileRepoList = (url = location) => isUserProfileRepoTab(url) || getOrg(url)?.path === "repositories";
126
+ var hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isTeamDiscussion(url) || isSingleGist(url);
127
+ var hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url) || isNewDiscussion(url);
128
+ var hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isCompareWikiPage(url) || isBlame(url);
129
+ var hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url);
130
+ var isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/");
131
+ var isActionJobRun = (url = location) => Boolean(getRepo(url)?.path.startsWith("runs/"));
132
+ var isActionRun = (url = location) => /^(actions\/)?runs/.test(getRepo(url)?.path);
133
+ var isNewAction = (url = location) => getRepo(url)?.path === "actions/new";
134
+ var isRepositoryActions = (url = location) => /^actions(\/workflows\/.+\.ya?ml)?$/.test(getRepo(url)?.path);
135
+ var isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
136
+ var canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
137
+ var isNewRepo = (url = location) => url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));
138
+ var isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate");
139
+ var getUsername = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0;
140
+ var getCleanPathname = (url = location) => url.pathname.replaceAll(/\/+/g, "/").slice(1, url.pathname.endsWith("/") ? -1 : void 0);
141
+ var getCleanGistPathname = (url = location) => {
425
142
  const pathname = getCleanPathname(url);
426
143
  if (url.hostname.startsWith("gist.")) {
427
144
  return pathname;
@@ -429,14 +146,14 @@ const getCleanGistPathname = (url = location) => {
429
146
  const [gist, ...parts] = pathname.split("/");
430
147
  return gist === "gist" ? parts.join("/") : void 0;
431
148
  };
432
- const getOrg = (url = location) => {
149
+ var getOrg = (url = location) => {
433
150
  const [, orgs, name, ...path] = url.pathname.split("/");
434
151
  if (orgs === "orgs" && name) {
435
152
  return { name, path: path.join("/") };
436
153
  }
437
154
  return void 0;
438
155
  };
439
- const getRepo = (url) => {
156
+ var getRepo = (url) => {
440
157
  if (!url) {
441
158
  const canonical = $('[property="og:url"]');
442
159
  if (canonical) {
@@ -460,7 +177,7 @@ const getRepo = (url) => {
460
177
  path: path.join("/")
461
178
  };
462
179
  };
463
- const utils = {
180
+ var utils = {
464
181
  getOrg,
465
182
  getUsername,
466
183
  getCleanPathname,
@@ -513,6 +230,7 @@ export {
513
230
  isIssue,
514
231
  isIssueOrPRList,
515
232
  isLabelList,
233
+ isLoggedIn,
516
234
  isMarketplaceAction,
517
235
  isMergedPR,
518
236
  isMilestone,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-url-detection",
3
- "version": "8.1.1",
3
+ "version": "9.0.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",
@@ -25,17 +25,17 @@
25
25
  ],
26
26
  "scripts": {
27
27
  "build": "run-p build:*",
28
- "build:vite": "vite build",
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
- "demo:build": "vite build demo",
31
- "demo:test": "svelte-check",
32
- "demo:watch": "vite preview demo & vite build demo --watch # vite serve isn't real",
30
+ "build:demo": "vite build demo",
33
31
  "prepack": "npm run build",
34
- "test": "run-p build test:unit xo",
35
- "test:unit": "bun test",
36
- "watch": "run-p watch:typescript demo:watch # vite watch doesn’t generate the lib, so just use the demo",
32
+ "test": "run-p build test:* xo",
33
+ "test:unit": "vitest",
34
+ "test:demo": "svelte-check",
35
+ "watch": "run-p watch:*",
37
36
  "watch:typescript": "tsc --watch --noEmit",
38
- "watch:test:unit": "run-p 'test:unit -- --watch' 'watch:typescript -- --watch'",
37
+ "watch:test:unit": "npm run test:unit -- --watch",
38
+ "watch:demo": "vite preview demo & npm run build:demo -- --watch # vite serve isn't real",
39
39
  "xo": "xo"
40
40
  },
41
41
  "xo": {
@@ -49,34 +49,30 @@
49
49
  ],
50
50
  "rules": {
51
51
  "@typescript-eslint/triple-slash-reference": "off",
52
- "@typescript-eslint/dot-notation": "off",
53
- "@typescript-eslint/no-non-null-assertion": "off",
54
- "@typescript-eslint/no-unsafe-member-access": "off",
55
- "@typescript-eslint/no-non-null-asserted-optional-chain": "off",
56
52
  "@typescript-eslint/naming-convention": "off",
57
- "n/prefer-global/process": "off"
53
+ "no-unused-labels": "off",
54
+ "no-labels": "off"
58
55
  }
59
56
  }
60
- ],
61
- "rules": {
62
- "camelcase": "off"
63
- }
57
+ ]
58
+ },
59
+ "dependencies": {
60
+ "github-reserved-names": "^2.0.5"
64
61
  },
65
62
  "devDependencies": {
66
- "@sindresorhus/tsconfig": "^4.0.0",
67
- "@sveltejs/vite-plugin-svelte": "^2.4.6",
68
- "bun": "^1.0.3",
69
- "bun-types": "^1.0.3",
70
- "github-reserved-names": "^2.0.5",
63
+ "@sindresorhus/tsconfig": "^5.0.0",
64
+ "@sveltejs/vite-plugin-svelte": "^3.1.1",
65
+ "esbuild": "^0.21.5",
71
66
  "npm-run-all": "^4.1.5",
72
67
  "strip-indent": "^4.0.0",
73
- "svelte": "^4.2.1",
74
- "svelte-check": "^3.5.2",
75
- "typescript": "^5.2.2",
76
- "vite": "^4.4.9",
77
- "xo": "^0.56.0"
68
+ "svelte": "^4.2.17",
69
+ "svelte-check": "^3.8.0",
70
+ "typescript": "^5.4.5",
71
+ "vite": "^5.2.12",
72
+ "vitest": "^1.6.0",
73
+ "xo": "^0.58.0"
78
74
  },
79
75
  "engines": {
80
- "node": ">=18"
76
+ "node": ">=20.10"
81
77
  }
82
78
  }