github-url-detection 11.1.3 → 11.2.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 +50 -2
- package/distribution/index.js +16 -1
- package/package.json +2 -2
- package/readme.md +24 -0
package/distribution/index.d.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
/* Examples added by add-examples-to-dts.ts */
|
|
2
|
+
/**
|
|
3
|
+
* Waits for a detection to return true by repeatedly checking it on each animation frame.
|
|
4
|
+
* Useful for DOM-based detections that need to wait for elements to appear.
|
|
5
|
+
* @param detection - A detection function to check repeatedly
|
|
6
|
+
* @returns A promise that resolves to the final result of the detection
|
|
7
|
+
* @example
|
|
8
|
+
* ```
|
|
9
|
+
* import {utils} from 'github-url-detection';
|
|
10
|
+
*
|
|
11
|
+
* async function init() {
|
|
12
|
+
* if (!await utils.waitFor(isOrganizationProfile)) {
|
|
13
|
+
* return;
|
|
14
|
+
* }
|
|
15
|
+
* // Do something when on organization profile
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function waitFor(detection: () => boolean): Promise<boolean>;
|
|
2
20
|
export declare const is404: () => boolean;
|
|
3
21
|
export declare const is500: () => boolean;
|
|
4
22
|
export declare const isPasswordConfirmation: () => boolean;
|
|
@@ -42,15 +60,16 @@ export declare const isCompare: (url?: URL | HTMLAnchorElement | Location) => bo
|
|
|
42
60
|
*/
|
|
43
61
|
export declare const isCompareWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
44
62
|
/**
|
|
63
|
+
* @deprecated Use `isHome` and/or `isFeed` instead
|
|
64
|
+
*
|
|
45
65
|
* @example https://github.com///
|
|
46
66
|
* @example https://github.com//
|
|
47
67
|
* @example https://github.com/
|
|
48
68
|
* @example https://github.com
|
|
49
|
-
* @example https://github.com/orgs/
|
|
69
|
+
* @example https://github.com/orgs/refined-github/dashboard
|
|
50
70
|
* @example https://github.com/dashboard/index/2
|
|
51
71
|
* @example https://github.com//dashboard
|
|
52
72
|
* @example https://github.com/dashboard
|
|
53
|
-
* @example https://github.com/orgs/edit/dashboard
|
|
54
73
|
* @example https://github.big-corp.com/
|
|
55
74
|
* @example https://not-github.com/
|
|
56
75
|
* @example https://my-little-hub.com/
|
|
@@ -63,6 +82,29 @@ export declare const isCompareWikiPage: (url?: URL | HTMLAnchorElement | Locatio
|
|
|
63
82
|
* @example https://github.com/dashboard-feed
|
|
64
83
|
*/
|
|
65
84
|
export declare const isDashboard: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
85
|
+
/**
|
|
86
|
+
* @example https://github.com
|
|
87
|
+
* @example https://github.com//dashboard
|
|
88
|
+
* @example https://github.com///
|
|
89
|
+
* @example https://github.com//
|
|
90
|
+
* @example https://github.com/
|
|
91
|
+
* @example https://github.com/dashboard
|
|
92
|
+
* @example https://github.big-corp.com/
|
|
93
|
+
* @example https://not-github.com/
|
|
94
|
+
* @example https://my-little-hub.com/
|
|
95
|
+
* @example https://github.com/?tab=repositories
|
|
96
|
+
* @example https://github.com/?tab=stars
|
|
97
|
+
* @example https://github.com/?tab=followers
|
|
98
|
+
* @example https://github.com/?tab=following
|
|
99
|
+
* @example https://github.com/?tab=overview
|
|
100
|
+
* @example https://github.com?search=1
|
|
101
|
+
*/
|
|
102
|
+
export declare const isHome: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
103
|
+
/**
|
|
104
|
+
* @example https://github.com/feed
|
|
105
|
+
* @example https://github.com/orgs/refined-github/dashboard
|
|
106
|
+
*/
|
|
107
|
+
export declare const isFeed: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
66
108
|
/**
|
|
67
109
|
* @example https://github.big-corp.com/
|
|
68
110
|
* @example https://not-github.com/
|
|
@@ -602,7 +644,11 @@ export declare const isNewAction: (url?: URL | HTMLAnchorElement | Location) =>
|
|
|
602
644
|
*/
|
|
603
645
|
export declare const isRepositoryActions: (url?: URL | HTMLAnchorElement | Location) => boolean;
|
|
604
646
|
export declare const isUserTheOrganizationOwner: () => boolean;
|
|
647
|
+
/**
|
|
648
|
+
* @deprecated Use canUserAccessRepoSettings or API instead.
|
|
649
|
+
*/
|
|
605
650
|
export declare const canUserAdminRepo: () => boolean;
|
|
651
|
+
export declare const canUserAccessRepoSettings: () => boolean;
|
|
606
652
|
/**
|
|
607
653
|
* @example https://github.com/new
|
|
608
654
|
* @example https://github.com/organizations/npmhub/repositories/new
|
|
@@ -639,4 +685,6 @@ export declare const utils: {
|
|
|
639
685
|
getCleanGistPathname: (url?: URL | HTMLAnchorElement | Location) => string | undefined;
|
|
640
686
|
getRepositoryInfo: (url?: URL | HTMLAnchorElement | Location | string) => RepositoryInfo | undefined;
|
|
641
687
|
parseRepoExplorerTitle: (pathname: string, title: string) => RepoExplorerInfo | undefined;
|
|
688
|
+
waitFor: typeof waitFor;
|
|
642
689
|
};
|
|
690
|
+
export {};
|
package/distribution/index.js
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
import reservedNames from "github-reserved-names/reserved-names.json" with { type: "json" };
|
|
3
3
|
var $ = (selector) => document.querySelector(selector);
|
|
4
4
|
var exists = (selector) => Boolean($(selector));
|
|
5
|
+
async function waitFor(detection) {
|
|
6
|
+
while (!detection() && document.readyState !== "complete") {
|
|
7
|
+
await new Promise((resolve) => {
|
|
8
|
+
requestAnimationFrame(resolve);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return detection();
|
|
12
|
+
}
|
|
5
13
|
var is404 = () => /^(Page|File) not found · GitHub/.test(document.title);
|
|
6
14
|
var is500 = () => document.title === "Server Error \xB7 GitHub" || document.title === "Unicorn! \xB7 GitHub" || document.title === "504 Gateway Time-out";
|
|
7
15
|
var isPasswordConfirmation = () => document.title === "Confirm password" || document.title === "Confirm access";
|
|
@@ -13,6 +21,8 @@ var isRepoCommitList = (url = location) => Boolean(getRepo(url)?.path.startsWith
|
|
|
13
21
|
var isCompare = (url = location) => Boolean(getRepo(url)?.path.startsWith("compare"));
|
|
14
22
|
var isCompareWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).split("/").slice(3, 5).includes("_compare");
|
|
15
23
|
var isDashboard = (url = location) => !isGist(url) && /^$|^(orgs\/[^/]+\/)?dashboard(-feed)?(\/|$)/.test(getCleanPathname(url));
|
|
24
|
+
var isHome = (url = location) => !isGist(url) && /^$|^dashboard\/?$/.test(getCleanPathname(url));
|
|
25
|
+
var isFeed = (url = location) => !isGist(url) && /^(feed|orgs\/[^/]+\/dashboard)\/?$/.test(getCleanPathname(url));
|
|
16
26
|
var isEnterprise = (url = location) => url.hostname !== "github.com" && url.hostname !== "gist.github.com";
|
|
17
27
|
var isGist = (url = location) => typeof getCleanGistPathname(url) === "string";
|
|
18
28
|
var isGlobalIssueOrPRList = (url = location) => ["issues", "pulls"].includes(url.pathname.split("/", 2)[1]);
|
|
@@ -198,6 +208,7 @@ var canUserAdminRepo = () => {
|
|
|
198
208
|
".js-repo-nav"
|
|
199
209
|
].join(",")}) a[href="/${repo.nameWithOwner}/settings"]`));
|
|
200
210
|
};
|
|
211
|
+
var canUserAccessRepoSettings = canUserAdminRepo;
|
|
201
212
|
var isNewRepo = (url = location) => !isGist(url) && (url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url)));
|
|
202
213
|
var isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate");
|
|
203
214
|
var getLoggedInUser = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0;
|
|
@@ -248,9 +259,11 @@ var utils = {
|
|
|
248
259
|
getCleanPathname,
|
|
249
260
|
getCleanGistPathname,
|
|
250
261
|
getRepositoryInfo: getRepo,
|
|
251
|
-
parseRepoExplorerTitle
|
|
262
|
+
parseRepoExplorerTitle,
|
|
263
|
+
waitFor
|
|
252
264
|
};
|
|
253
265
|
export {
|
|
266
|
+
canUserAccessRepoSettings,
|
|
254
267
|
canUserAdminRepo,
|
|
255
268
|
hasCode,
|
|
256
269
|
hasComments,
|
|
@@ -286,6 +299,7 @@ export {
|
|
|
286
299
|
isEmptyRepo,
|
|
287
300
|
isEmptyRepoRoot,
|
|
288
301
|
isEnterprise,
|
|
302
|
+
isFeed,
|
|
289
303
|
isFileFinder,
|
|
290
304
|
isForkedRepo,
|
|
291
305
|
isForkingRepo,
|
|
@@ -295,6 +309,7 @@ export {
|
|
|
295
309
|
isGistRevision,
|
|
296
310
|
isGlobalIssueOrPRList,
|
|
297
311
|
isGlobalSearchResults,
|
|
312
|
+
isHome,
|
|
298
313
|
isIssue,
|
|
299
314
|
isIssueOrPRList,
|
|
300
315
|
isLabelList,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-url-detection",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.2.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",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"xo": "xo"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"github-reserved-names": "^2.1.
|
|
45
|
+
"github-reserved-names": "^2.1.3"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@sindresorhus/tsconfig": "^8.1.0",
|
package/readme.md
CHANGED
|
@@ -67,6 +67,30 @@ if (pageDetect.isOrganizationProfile()) {
|
|
|
67
67
|
}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
### Async detections with `waitFor`
|
|
71
|
+
|
|
72
|
+
The `waitFor` helper function allows you to wait for a detection to become true by repeatedly checking it on each animation frame. This is useful for DOM-based detections that need to wait for elements to appear before the document is fully loaded.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
import {utils, isOrganizationProfile} from 'github-url-detection';
|
|
76
|
+
|
|
77
|
+
async function init() {
|
|
78
|
+
// Wait for the detection to return true or for the document to be complete
|
|
79
|
+
if (!await utils.waitFor(isOrganizationProfile)) {
|
|
80
|
+
return; // Not an organization profile
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The page is now confirmed to be an organization profile
|
|
84
|
+
console.log('On organization profile!');
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The `waitFor` function:
|
|
89
|
+
- Repeatedly calls the detection function on each animation frame
|
|
90
|
+
- Stops when the detection returns `true` or when `document.readyState` is `'complete'`
|
|
91
|
+
- Returns the final result of the detection
|
|
92
|
+
- Works with any detection function that returns a boolean
|
|
93
|
+
|
|
70
94
|
## Related
|
|
71
95
|
|
|
72
96
|
- [github-reserved-names](https://github.com/Mottie/github-reserved-names) - Get a list, or check if a user or organization name is reserved by GitHub.
|