JSPM

  • Created
  • Published
  • Downloads 279
  • Score
    100M100P100Q89700F
  • License MIT

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

Package Exports

  • github-url-detection

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (github-url-detection) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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
import * as pageDetect from 'github-url-detection';
const pageDetect = require('github-url-detection');

Usage

const href = 'https://github.com/fregante/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.isConversationList()) {
    alert('You’re looking at a issues and PRs list!')
}

API

In the source you can see the full list of detections and their matching URLs.

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.isConversationList()) {
    alert('You’re looking at a issues or PRs list!')
}
if (pageDetect.isConversationList(new URL('https://github.com/fregante/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')
}
  • github-reserved-names - Get a list, or check if a user or organization name is reserved by GitHub.
  • shorten-repo-url - Shorten GitHub links like GitHub shortens Issues and Commit links.

License

MIT © Federico Brigante