Userscript Manager Detection

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

Verzia zo dňa 16.10.2022. Pozri najnovšiu verziu.

Tento skript by nemal byť nainštalovaný priamo. Je to knižnica pre ďalšie skripty, ktorú by mali používať cez meta príkaz // @require https://updategreasyfork.deno.dev/scripts/453189/1105660/Userscript%20Manager%20Detection.js

// ==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';

// Show result
//NOTE: This is not required, as it only serves for demonstration purposes.
alert(isInUserscriptContext ? 'I am being ran in an Userscript' : 'I am not being ran in an Userscript');