Skip to content

Instantly share code, notes, and snippets.

@arantius
Created September 5, 2012 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arantius/3644903 to your computer and use it in GitHub Desktop.
Save arantius/3644903 to your computer and use it in GitHub Desktop.
User Script Scope Test
// ==UserScript==
// @name User Script Scope Test
// @namespace http://arantius.com/misc/greasemonkey
// @description Test the affect of assigning to various scopes in a script, on the content page
// @include http://jsbin.com/abemus/*
// @version 1
// @grant GM_log
// ==/UserScript==
bare_val = 'grant-ed bare';
var var_val = 'grant-ed var';
window.window_val = 'grant-ed window';
document.body.innerHTML += 'Script sees content_val: '
+ (typeof content_val == 'undefined' ? 'undefined' : content_val)
+ '<br>';
document.body.innerHTML += 'Script sees window.content_val: '
+ (typeof window.content_val == 'undefined' ? 'undefined' : window.content_val)
+ '<br>';
document.body.innerHTML += 'Script sees unsafeWindow.content_val: '
+ (typeof unsafeWindow.content_val == 'undefined' ? 'undefined' : unsafeWindow.content_val)
+ '<br>';
// ==UserScript==
// @name User Script Scope Test
// @namespace http://arantius.com/misc/greasemonkey
// @description Test the affect of assigning to various scopes in a script, on the content page
// @include http://jsbin.com/abemus/*
// @version 1
// @grant none
// ==/UserScript==
bare_val = 'grant-less bare';
var var_val = 'grant-less var';
window.window_val = 'grant-less window';
document.body.innerHTML += 'Script sees content_val: '
+ (typeof content_val == 'undefined' ? 'undefined' : content_val)
+ '<br>';
document.body.innerHTML += 'Script sees window.content_val: '
+ (typeof window.content_val == 'undefined' ? 'undefined' : window.content_val)
+ '<br>';
document.body.innerHTML += 'Script sees unsafeWindow.content_val: '
+ (typeof unsafeWindow.content_val == 'undefined' ? 'undefined' : unsafeWindow.content_val)
+ '<br>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment