Greasy Fork is available in English.

Userscript Manager Detection

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

Ce script ne doit pas être installé directement. C'est une librairie destinée à être incluse dans d'autres scripts avec la méta-directive // @require https://update.greatest.deepsurf.us/scripts/453189/1106477/Userscript%20Manager%20Detection.js

  1. // ==UserScript==
  2. // @name Userscript Manager Detection
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description A Code Snippet for detecting if the script is being ran in an Userscript Manager.
  6. // @author Taureon
  7. // @include *
  8. // @grant none
  9. // @license Unlicense
  10. // ==/UserScript==
  11.  
  12. // Detect GreaseMonkey API objects
  13. //data type: boolean
  14. //true = It is being ran in an Userscript Manager
  15. //false = It is being ran as a bookmarklet or it is being ran in an Userscript Manager that does not have GreaseMonkey API objects
  16. var isInUserscriptContext = typeof GM === 'object' || typeof GM_info === 'object';
  17.  
  18. //example of using it
  19. //alert(isInUserscriptContext ? 'I am being ran in an Userscript' : 'I am not being ran in an Userscript');