ags-url-detection
v1.0.5
Published
Which AGS website page are you on? Is it a game? Is it a wiki entry? Perfect for your WebExtension or userscript.
Maintainers
Readme
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-detectionimport * 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
