8.1.1 • Published 7 months ago

github-url-detection v8.1.1

Weekly downloads
688
License
MIT
Repository
github
Last release
7 months ago

github-url-detection

Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.

Battle-tested by and extracted from the Refined GitHub extension.

Install

npm install github-url-detection
// This package is pure ESM
import * as pageDetect from 'github-url-detection';

Usage

const href = 'https://github.com/refined-github/github-url-detection/issues/1';
if (pageDetect.isIssue(new URL(href))) { // Pass the URL as an `URL` object
	alert('The passed URL is of an issue!')
}

if (pageDetect.isRepo()) { // Uses `window.location.href` by default
	alert('You’re looking at a repo!')
}

if (pageDetect.isIssueOrPRList()) {
	alert('You’re looking at a issues and PRs list!')
}

API

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.

URL-based detections

By default, URL-based detections use the location global if you don't pass a url argument.

if (pageDetect.isIssueOrPRList()) {
	alert('You’re looking at a issues or PRs list!')
}
if (pageDetect.isIssueOrPRList(new URL('https://github.com/refined-github/github-url-detection/pulls'))) {
	alert('You’re looking at a issues or PRs list!')
}

Notice that the url parameter is not a plain string but it has to be a proper URL or location object.

Document-based detections

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.

if (pageDetect.isOrganizationProfile()) {
	alert('You’re on an organization profile, like https://github.com/babel')
}

Related

License

MIT © Federico Brigante

8.1.1

7 months ago

8.1.0

9 months ago

8.0.0

9 months ago

7.1.2

1 year ago

7.1.1

1 year ago

7.1.0

1 year ago

7.0.1-0

1 year ago

7.0.0

1 year ago

6.1.0

2 years ago

5.13.0

2 years ago

5.11.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.2

2 years ago

5.12.1

2 years ago

5.12.0

2 years ago

5.10.0

2 years ago

5.9.0

2 years ago

5.8.0

2 years ago

5.7.1

2 years ago

5.7.0

3 years ago

5.6.0

3 years ago

5.5.0

3 years ago

5.4.0

3 years ago

5.4.0-0

3 years ago

5.3.1

3 years ago

5.3.0

3 years ago

5.1.0

3 years ago

5.2.0

3 years ago

5.0.0

3 years ago

4.11.0

3 years ago

4.10.0

3 years ago

4.9.1

3 years ago

4.9.0

3 years ago

4.8.0

3 years ago

4.7.0

3 years ago

4.6.0

3 years ago

4.5.2

3 years ago

4.5.1

3 years ago

4.5.0

3 years ago

4.4.0

3 years ago

4.3.0

4 years ago

4.3.0-1

4 years ago

4.3.0-0

4 years ago

4.2.0

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.0

4 years ago

2.2.1-0

4 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago