function blah(_x)
{
console.info(_x.toSource().match(/\/\/\s*@version\s+(.*)\s*\n/i));
}
function foobar()
{
// ==UserScript==
// @version 1.2.3.4
// ==/UserScript==
blah(arguments.callee);
}
foobar();
Is there any way to do this using JavaScript? I want to detect the version number / other attributes in a Greasemonkey script but as I understand it, .toSource()
and .toString()
strip out comments1.
I don't want to wrap the header block in <><![CDATA[ ]><>
if I can avoid it, and I want to avoid having to duplicate the header block outside of the comments if possible.
Is this possible? Are there alternatives to toSource()
/ .toString()
that would make this possible?