Frage

Possible Duplicate:
How can I obfuscate JavaScript?

I was wondering if there's a way to just move javascript around. So let's say I have a javascript file. I like to be able to have the PHP function just move the JS functions, etc around so it's less readable.

  1. Set path to javascript file
  2. Read the JS file
  3. Grab each JS function or jquery selector and move them around and save the file. The hard part is figuring how how to make sure each block of code is complete... hmm... maybe use 2 \n\n returns as a separator? Another idea is make each JS block a single sentence and just use PHP line shuffle?

Curious if this is do-able...

Thanks

UPDATE: What do you guys think of this? Using /// between each function and converting everything into array and then I'll randomize array and output it back out again

<?php
$file_content = file_get_contents("js/js.js");
$content = explode("///", $file_content);
echo count($content);
print_r($content);
?>
War es hilfreich?

Lösung

Via PHP not sure but you can adapt UglifyJS. It has really good AST parsing, so you should probably read more on AST (abstract syntax tree) which is basically an outline of javascript code.

Definitely doable.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top