Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ThomasR
Last active December 9, 2015 15:16
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 ThomasR/9b7c94e506f236ae4ba2 to your computer and use it in GitHub Desktop.
Save ThomasR/9b7c94e506f236ae4ba2 to your computer and use it in GitHub Desktop.
A Greasemonkey script template that injects the main script into the global scope, thus escaping the sandbox.
// ==UserScript==
// @name %name%
// @namespace %namespace%
// @description %description%
// @include %include%
// @exclude %exclude%
// @version 1
// @noframes
// @grant none
// @run-at document-end
// ==/UserScript==
(main => {
// http://stackoverflow.com/a/5006952/27862
var script = document.createElement('script');
script.textContent = `try {(${main})();} catch (e) {console.log(e);}`;
document.body.appendChild(script).parentNode.removeChild(script);
})(() => {
// script content here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment