Created
June 24, 2011 02:04
-
-
Save johnkpaul/1044075 to your computer and use it in GitHub Desktop.
Add to JavaScript function prototype ability to find source in file
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
if(typeof _scriptsRecorded == "undefined"){ | |
var scriptBodies = {} | |
var scripts = document.querySelectorAll("script"); | |
for(var i = 0, len = scripts.length;i<len;i++){ | |
var script = scripts[i]; | |
(function(src){ | |
$.get(src, function(data){ | |
scriptBodies[src] = data; | |
}) | |
})(script.src) | |
} | |
} | |
_scriptsRecorded = true; | |
Function.prototype.findFile = function(){ | |
var source = this.toSource(); | |
for(var key in scriptBodies){ | |
var script = scriptBodies[key]; | |
if(script.indexOf(source) > -1){ | |
return key; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently this assumes jQuery is present, but I would like to remove that requirement.