Skip to content

Instantly share code, notes, and snippets.

@guillaumegarcia13
Last active July 2, 2019 11:51
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 guillaumegarcia13/c1564d6420f9f1b7e0bd383e2e31a694 to your computer and use it in GitHub Desktop.
Save guillaumegarcia13/c1564d6420f9f1b7e0bd383e2e31a694 to your computer and use it in GitHub Desktop.
Exposing internals of a Launchpad-launched Neptune app
// Expose variable when launched from Launchpad
if (sap.n) {
var attr; // optional (fill with the name of the window attribute you want, eg. 'APPxxx')
var exposed = (attr) ? window[attr] = {}
: window;
var regex = /var (\w*) \= new /gm; // regexp to determine all variable names (and a few wrong ones)
var funcCode = arguments.callee + '';
var match;
while ((match = regex.exec(funcCode)) !== null) {
if (match.index === regex.lastIndex) {
regex.lastIndex++;
}
if (match) {
var variableName = match[1];
try {
exposed[variableName] = eval(variableName);
} catch(e) {
// never mind, might be variable names within
// event handlers we are not interested in
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment