ags-url-detection
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

ags-url-detection

Which AGS website page are you on? Is it a game? Is it a wiki entry? Perfect for your WebExtension or userscript.

Install

npm install ags-url-detection
import * as pageDetect from 'ags-url-detection';
const pageDetect = require('ags-url-detection');

Usage

const href = 'https://www.adventuregamestudio.co.uk/site/games/game/2492-duty-first/';
if (pageDetect.isGame(new URL(href))) { // Pass the URL as an `URL` object
	alert('The passed URL is of a game!')
}

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

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.isGame()) {
	alert('You’re looking at a game!')
}
if (pageDetect.isGame(new URL('https://www.adventuregamestudio.co.uk/site/games/game/2492-duty-first/'))) {
	alert('You’re looking at a game!')
}

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

License

MIT © Peder Johnsen

Package Sidebar

Install

npm i ags-url-detection

Weekly Downloads

59

Version

1.0.5

License

MIT

Unpacked Size

18.9 kB

Total Files

8

Last publish

Collaborators

  • pederjohnsen