This is best done in a language such as python, perl, or bash shell. You will want to look into: regular expressions, conditional statements, for loops, read line, open/close files, read/write files, python file arguments. Those are the python topics you should look up.
We will not write your code for you but we will help you along the way. If you already have a script written but need to trouble shoot it then post your source code and we will assist you with finding a solution.
Go ahead and try to write a script based on the topics I've stated and we'll work from there as a team.
Once you have the script you're looking for then you can use the shell to recursively list the files which you would need to write your commands.
Code:
for x in `find . -name "*\.js" -type f`;do /path/to/python/script/myscript.py $x;done
for x in `find . -name "*\.htm*" -type f`;do /path/to/python/script/myscript.py $x;done
for x in `find . -name "*\.php" -type f`;do /path/to/python/script/myscript.py $x;done
You can also do it all using for loops in the shell with grep which would allow your files to be modified using only the terminal. Just research bash shell programing, how to pipe commands, shell regular expressions, grep man page, find man page, xargs man page, sed man page, sed regex. This way you can skip python and php scripts altogether.
That should be more than enough information to get you started.