Skip to content

Instantly share code, notes, and snippets.

@terinjokes
Created February 8, 2013 21:10
Show Gist options
  • Save terinjokes/4741938 to your computer and use it in GitHub Desktop.
Save terinjokes/4741938 to your computer and use it in GitHub Desktop.
function globalEval(text) {
/**
* Modified version of runScriptText() from FuseJS
* Copyright (c) 2008-2010 John-David Dalton, https://github.com/jdalton/fusejs
*
* FuseJS is distributed under an MIT license. <https://github.com/jdalton/fusejs>
*/
var suid = _.uniqueId('fused_'),
script,
result,
head;
if (text && text !== '') {
CloudFlare[suid] = {'text': String(text)};
head = document.getElementsByTagName('head')[0];
text = 'CloudFlare.' + suid + '.returned=eval(' +
'CloudFlare.' + suid + '.text);';
text = 'if("arguments" in this){' + text +
'}else{arguments=void 0;' + text +
'delete arguments}';
script = document.createElement('script');
script.async = true;
(script.firstChild || script.appendChild(script.ownerDocument.createTextNode(''))).data = text === null ? '' : text;
head.insertBefore(script, head.firstChild);
head.removeChild(script);
result = CloudFlare[suid].returned;
delete CloudFlare[suid];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment