Last active
July 2, 2019 11:51
-
-
Save guillaumegarcia13/c1564d6420f9f1b7e0bd383e2e31a694 to your computer and use it in GitHub Desktop.
Exposing internals of a Launchpad-launched Neptune app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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