Userscript Manager Detection

A Code Snippet for detecting if the script is being ran in an Userscript Manager.

Detta skript bör inte installeras direkt. Det är ett bibliotek för andra skript att inkludera med meta-direktivet // @require https://update.greasyfork.org/scripts/453189/1106477/Userscript%20Manager%20Detection.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Userscript Manager Detection
// @namespace    http://tampermonkey.net/
// @version      1
// @description  A Code Snippet for detecting if the script is being ran in an Userscript Manager.
// @author       Taureon
// @include      *
// @grant        none
// @license      Unlicense
// ==/UserScript==

// Detect GreaseMonkey API objects
//data type: boolean
//true = It is being ran in an Userscript Manager
//false = It is being ran as a bookmarklet or it is being ran in an Userscript Manager that does not have GreaseMonkey API objects
var isInUserscriptContext = typeof GM === 'object' || typeof GM_info === 'object';

//example of using it
//alert(isInUserscriptContext ? 'I am being ran in an Userscript' : 'I am not being ran in an Userscript');