1.0.5 • Published 3 years ago

ags-url-detection v1.0.5

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

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

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago