github-url-detection 7.0.0 → 7.1.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.
@@ -113,7 +113,7 @@ export declare const isUserTheOrganizationOwner: () => boolean;
113
113
  export declare const canUserEditRepo: () => boolean;
114
114
  export declare const isNewRepo: (url?: URL | HTMLAnchorElement | Location) => boolean;
115
115
  export declare const isNewRepoTemplate: (url?: URL | HTMLAnchorElement | Location) => boolean;
116
- export declare type RepositoryInfo = {
116
+ export type RepositoryInfo = {
117
117
  owner: string;
118
118
  name: string;
119
119
  /** The 'user/repo' part from an URL */
@@ -278,8 +278,8 @@ const reservedNames = [
278
278
  ];
279
279
  const $ = (selector) => document.querySelector(selector);
280
280
  const exists = (selector) => Boolean($(selector));
281
- const is404 = () => document.title.startsWith("Page not found \xB7 GitHub");
282
- const is500 = () => document.title === "Server Error \xB7 GitHub" || document.title === "Unicorn! \xB7 GitHub" || document.title === "504 Gateway Time-out";
281
+ const is404 = () => document.title.startsWith("Page not found · GitHub");
282
+ const is500 = () => document.title === "Server Error · GitHub" || document.title === "Unicorn! · GitHub" || document.title === "504 Gateway Time-out";
283
283
  const isPasswordConfirmation = () => document.title === "Confirm password" || document.title === "Confirm access";
284
284
  const isBlame = (url = location) => Boolean(getRepo(url)?.path.startsWith("blame/"));
285
285
  const isCommit = (url = location) => isSingleCommit(url) || isPRCommit(url);
@@ -292,7 +292,7 @@ const isEnterprise = (url = location) => url.hostname !== "github.com" && url.ho
292
292
  const isGist = (url = location) => typeof getCleanGistPathname(url) === "string";
293
293
  const isGlobalIssueOrPRList = (url = location) => ["issues", "pulls"].includes(url.pathname.split("/", 2)[1]);
294
294
  const isGlobalSearchResults = (url = location) => url.pathname === "/search" && new URLSearchParams(url.search).get("q") !== null;
295
- const isIssue = (url = location) => /^issues\/\d+/.test(getRepo(url)?.path) && document.title !== "GitHub \xB7 Where software is built";
295
+ const isIssue = (url = location) => /^issues\/\d+/.test(getRepo(url)?.path) && document.title !== "GitHub · Where software is built";
296
296
  const isIssueOrPRList = (url = location) => isGlobalIssueOrPRList(url) || isRepoIssueOrPRList(url) || isMilestone(url);
297
297
  const isConversation = (url = location) => isIssue(url) || isPRConversation(url);
298
298
  const isLabelList = (url = location) => getRepo(url)?.path === "labels";
@@ -305,19 +305,19 @@ const isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(ur
305
305
  const isNotifications = (url = location) => getCleanPathname(url) === "notifications";
306
306
  const isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
307
307
  const isOrganizationRepo = () => Boolean(document.querySelector("[data-owner-scoped-search-url]")?.dataset["ownerScopedSearchUrl"].startsWith("/org"));
308
- const isTeamDiscussion = (url = location) => /^orgs\/[^/]+\/teams\/[^/]+($|\/discussions)/.test(getCleanPathname(url));
308
+ const isTeamDiscussion = (url = location) => Boolean(getOrg(url)?.path.startsWith("teams"));
309
309
  const isOwnUserProfile = () => getCleanPathname() === getUsername();
310
310
  const isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');
311
311
  const isProject = (url = location) => /^projects\/\d+/.test(getRepo(url)?.path);
312
312
  const isProjects = (url = location) => getRepo(url)?.path === "projects";
313
- const isDiscussion = (url = location) => /^discussions\/\d+/.test(getRepo(url)?.path);
314
- const isDiscussionList = (url = location) => getRepo(url)?.path === "discussions";
313
+ const isDiscussion = (url = location) => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path);
314
+ const isDiscussionList = (url = location) => getRepo(url)?.path === "discussions" || getOrg(url)?.path === "discussions";
315
315
  const isPR = (url = location) => /^pull\/\d+/.test(getRepo(url)?.path) && !isPRConflicts(url);
316
316
  const isPRConflicts = (url = location) => /^pull\/\d+\/conflicts/.test(getRepo(url)?.path);
317
317
  const isPRList = (url = location) => url.pathname === "/pulls" || getRepo(url)?.path === "pulls";
318
318
  const isPRCommit = (url = location) => /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
319
- const isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found \xB7 Pull Request");
320
- const isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found \xB7 Pull Request");
319
+ const isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found · Pull Request");
320
+ const isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found · Pull Request");
321
321
  const isPRConversation = (url = location) => /^pull\/\d+$/.test(getRepo(url)?.path);
322
322
  const isPRCommitList = (url = location) => /^pull\/\d+\/commits$/.test(getRepo(url)?.path);
323
323
  const isPRFiles = (url = location) => /^pull\/\d+\/files/.test(getRepo(url)?.path);
@@ -342,13 +342,16 @@ const isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) &
342
342
  const hasRepoHeader = (url = location) => isRepo(url) && !isRepoSearch(url);
343
343
  const isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
344
344
  const isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]');
345
- const isPublicRepo = () => Boolean(isRepo() && $("#repository-container-header .Label").textContent.startsWith("Public"));
346
- const isArchivedRepo = () => Boolean(isRepo() && $("#repository-container-header .Label").textContent.endsWith("archive"));
345
+ const isPublicRepo = () => exists('meta[name="octolytics-dimension-repository_public"][content="true"]');
346
+ const isArchivedRepo = () => Boolean(isRepo() && $("main > .flash-warn")?.textContent.includes("archived"));
347
347
  const isBlank = () => exists("main .blankslate");
348
348
  const isRepoTaxonomyIssueOrPRList = (url = location) => /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(getRepo(url)?.path);
349
349
  const isRepoIssueOrPRList = (url = location) => isRepoPRList(url) || isRepoIssueList(url) || isRepoTaxonomyIssueOrPRList(url);
350
350
  const isRepoPRList = (url = location) => Boolean(getRepo(url)?.path.startsWith("pulls"));
351
- const isRepoIssueList = (url = location) => /^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(getRepo(url)?.path);
351
+ const isRepoIssueList = (url = location) => (
352
+ // `issues/fregante` is a list but `issues/1`, `issues/new`, `issues/new/choose`, `issues/templates/edit` aren’t
353
+ /^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(getRepo(url)?.path)
354
+ );
352
355
  const isRepoHome = (url = location) => getRepo(url)?.path === "";
353
356
  const isRepoRoot = (url) => {
354
357
  const repository = getRepo(url ?? location);
@@ -413,6 +416,13 @@ const getCleanGistPathname = (url = location) => {
413
416
  const [gist, ...parts] = pathname.split("/");
414
417
  return gist === "gist" ? parts.join("/") : void 0;
415
418
  };
419
+ const getOrg = (url = location) => {
420
+ const [, orgs, name, ...path] = url.pathname.split("/");
421
+ if (orgs === "orgs" && name) {
422
+ return { name, path: path.join("/") };
423
+ }
424
+ return void 0;
425
+ };
416
426
  const getRepo = (url) => {
417
427
  if (!url) {
418
428
  const canonical = document.querySelector('[property="og:url"]');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-url-detection",
3
- "version": "7.0.0",
3
+ "version": "7.1.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",
@@ -71,21 +71,23 @@
71
71
  ]
72
72
  },
73
73
  "devDependencies": {
74
- "@esbuild-kit/esm-loader": "^2.5.0",
74
+ "@esbuild-kit/esm-loader": "^2.5.5",
75
75
  "@sindresorhus/tsconfig": "^3.0.1",
76
- "@sveltejs/vite-plugin-svelte": "^1.1.0",
77
- "ava": "^5.0.1",
76
+ "@sveltejs/vite-plugin-svelte": "^2.0.4",
77
+ "ava": "^5.2.0",
78
78
  "github-reserved-names": "^2.0.4",
79
79
  "npm-run-all": "^4.1.5",
80
80
  "strip-indent": "^4.0.0",
81
- "svelte": "^3.52.0",
82
- "svelte-check": "^2.9.2",
83
- "tslib": "^2.4.0",
84
- "typescript": "^4.8.4",
85
- "vite": "^3.1.8",
86
- "xo": "^0.52.4"
81
+ "svelte": "^3.58.0",
82
+ "svelte-check": "^3.2.0",
83
+ "typescript": "^5.0.4",
84
+ "vite": "^4.3.0-beta.4",
85
+ "xo": "^0.54.0"
87
86
  },
88
87
  "engines": {
89
88
  "node": ">=18"
89
+ },
90
+ "overrides": {
91
+ "vite": "^4.3.0-beta.4"
90
92
  }
91
93
  }