You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (pageDetect.isIssue(newURL(href))) { // Pass the URL as an `URL` object
29
+
alert('The passed URL is of an issue!')
29
30
}
30
31
32
+
if (pageDetect.isRepo()) { // Uses `window.location.href` by default
33
+
alert('You’re looking at a repo!')
34
+
}
31
35
32
36
if (pageDetect.isDiscussionList()) {
33
37
alert('You’re looking at a issues and PRs list!')
34
38
}
35
39
```
36
40
41
+
## API
42
+
37
43
In the source you can see the [full list of detections](https://www.unpkg.com/browse/github-url-detection@latest/esm/index.d.ts) and [their matching URLs.](https://github.com/fregante/github-url-detection/blob/master/source/index.ts)
38
44
39
-
Most tests are URL-based but a handful of them are DOM-based.
45
+
Most detections are URL-based while others need access to the current `document`. You can determine which ones are URL-based by looking at their signature: URL-based functions have a `url` parameter.
46
+
47
+
### URL-based detections
48
+
49
+
By default, URL-based detections use the `location` global if you don't pass a `url` argument.
50
+
51
+
```js
52
+
if (pageDetect.isDiscussionList()) {
53
+
alert('You’re looking at a issues or PRs list!')
54
+
}
55
+
```
56
+
57
+
```js
58
+
if (pageDetect.isDiscussionList(newURL('https://github.com/fregante/github-url-detection/pulls'))) {
59
+
alert('You’re looking at a issues or PRs list!')
60
+
}
61
+
```
62
+
63
+
Notice that the `url` parameter is not a plain string but it has to be a proper `URL` or `location` object.
64
+
65
+
### Document-based detections
66
+
67
+
By default, `document`-based detections use the `document` global, which means they can only be used if you have the whole page, you can't just test any random URL string.
68
+
69
+
70
+
```js
71
+
if (pageDetect.isOrganizationProfile()) {
72
+
alert('You’re on an organization profile, like https://github.com/babel')
0 commit comments