In addition to Solution 1, here is a hint for you: you can get the code of your script in the same script.
For starters, here is how you can get the code of some function in a string:
function A(a, b) { }
var codeOfA = A.toString();
Moreover, you can get the full text of some script, as an element of the HTML page. This is how:
var scripts = document.getElementsByTagName("script");
for (var index = 0; index < scripts.length; ++index) {
var scriptText = scripts[index].text;
}
Note that the script should be embedded in the HTML where you are using your script; if the script is in some separate file, its
text
property returns empty string.
—SA