Alexander I. Zaytsev 11 years ago
parent
commit
dda47b0948
1 changed files with 21 additions and 13 deletions
  1. 21 13
      jsfuck.js

+ 21 - 13
jsfuck.js

@@ -229,21 +229,29 @@
       return "";
     }
 
-    input.replace(/./g, function(c){
-
-      var replacement = MAPPING[c];
+    var r = "";
+    for (var i in SIMPLE) {
+      r += i + "|";
+    }
+    r+=".";
 
-      if (replacement){
-        output.push(MAPPING[c]); 
+    input.replace(new RegExp(r, 'g'), function(c) {
+      var replacement = SIMPLE[c];
+      if (replacement) {
+        output.push("[" + replacement + "]+[]");
       } else {
-
-        replacement =
-          "([]+[])[" + encode("constructor") + "]" +
-          "[" + encode("fromCharCode") + "]" +
-          "(" + encode(c.charCodeAt(0) + "") + ")";
- 
-        output.push(replacement);
-        MAPPING[c] = replacement;
+        replacement = MAPPING[c];
+        if (replacement){
+          output.push(replacement);
+        } else {
+          replacement =
+            "([]+[])[" + encode("constructor") + "]" +
+            "[" + encode("fromCharCode") + "]" +
+            "(" + encode(c.charCodeAt(0) + "") + ")";
+   
+          output.push(replacement);
+          MAPPING[c] = replacement;
+        }
       }
     });