├── CNAME ├── LICENSE ├── README.md ├── index.html ├── scripts ├── index.js └── js-obfuscator.js └── styles └── common.css /CNAME: -------------------------------------------------------------------------------- 1 | js.retn0.kr -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2025 nbsp1221 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaScript Obfuscator 2 | 3 | ![image](https://user-images.githubusercontent.com/50603255/150691116-e58ca4d4-fbd8-4501-a227-e825fb8b4cb8.png) 4 | 5 | https://js.retn0.kr 6 | 7 | You can use it for bypassing string filtering. When numbers or special characters are filtered, blacklist them to bypass. When obfuscated code is too long, use variables. 8 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | JavaScript Obfuscator 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 17 |
18 |
19 |
20 |
21 | 22 |
Length: 0
23 |
24 |
25 | 26 |
27 |
28 | 29 |
Length: 0
30 |
31 |
32 |
33 | Options 34 |
35 |
36 |
Variable
37 |
38 |
39 | 40 | 41 |
42 |
43 |
44 |
List to use as a variable name except for '$' and '_'
45 |
46 | 47 |
48 |
49 |
50 |
Iteration count of the random function
51 |

The larger this value, the slower running time, but the probability to get short code would be increased.

52 |
53 | 54 |
55 |
56 |
57 |
58 |
NodeJS
59 |
60 |
61 | 62 | 63 |
64 |

Make 'require', 'module', 'exports', and other NodeJS functions available in the obfuscated code scope.

65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | Blacklist 73 |
74 |
75 |
Basic
76 |
77 |
78 | 79 | 80 |
81 |
82 | 83 | 84 |
85 |
86 | 87 | 88 |
89 |
90 |
91 |
92 |
Special
93 |
94 |
95 | 96 | 97 |
98 |
99 | 100 | 101 |
102 |
103 | 104 | 105 |
106 |
107 | 108 | 109 |
110 |
111 | 112 | 113 |
114 |
115 | 116 | 117 |
118 |
119 | 120 | 121 |
122 |
123 | 124 | 125 |
126 |
127 | 128 | 129 |
130 |
131 | 132 | 133 |
134 |
135 |
136 |
137 | 138 | 139 |
140 |
141 | 142 | 143 |
144 |
145 | 146 | 147 |
148 |
149 | 150 | 151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 | 162 | 163 | -------------------------------------------------------------------------------- /scripts/index.js: -------------------------------------------------------------------------------- 1 | let inputCode; 2 | let outputCode; 3 | let optionVariableCandidates; 4 | let optionIterationCount; 5 | 6 | window.onload = () => { 7 | inputCode = document.getElementById('input-code'); 8 | outputCode = document.getElementById('output-code'); 9 | optionVariableCandidates = document.getElementById('option-variable-candidates'); 10 | optionIterationCount = document.getElementById('option-iteration-count'); 11 | 12 | initCodeArea(); 13 | initOptionArea(); 14 | initBlacklistArea(); 15 | }; 16 | 17 | const initCodeArea = () => { 18 | const inputCodeLength = document.getElementById('input-code-length'); 19 | const outputCodeLength = document.getElementById('output-code-length'); 20 | 21 | inputCode.oninput = () => { 22 | inputCodeLength.innerText = inputCode.value.length; 23 | }; 24 | 25 | outputCode.oninput = () => { 26 | outputCodeLength.innerText = outputCode.value.length; 27 | }; 28 | 29 | document.getElementById('obfuscate-button').onclick = () => { 30 | const iterationCount = parseInt(optionIterationCount.value); 31 | 32 | if (inputCode.value === '') { 33 | return; 34 | } 35 | 36 | if (iterationCount < 1) { 37 | alert('The iteration count of the random function must be a natural number.'); 38 | return; 39 | } 40 | 41 | outputCode.value = obfuscate(inputCode.value, optionVariableCandidates.value.split(''), iterationCount); 42 | outputCode.oninput(); 43 | }; 44 | 45 | document.getElementById('run-button').onclick = () => { 46 | eval(outputCode.value); 47 | }; 48 | 49 | inputCode.oninput(); 50 | outputCode.oninput(); 51 | }; 52 | 53 | const initOptionArea = () => { 54 | const optionUseVariable = document.getElementById('option-use-variable'); 55 | const optionNodeJS = document.getElementById('option-nodejs'); 56 | const blacklistEquals = document.getElementById('blacklist-equals'); 57 | 58 | 59 | optionUseVariable.onchange = () => { 60 | optionVariableCandidates.disabled = !optionUseVariable.checked; 61 | optionIterationCount.disabled = !optionUseVariable.checked; 62 | blacklistEquals.checked = false; 63 | blacklistEquals.disabled = optionUseVariable.checked; 64 | option.useVariable = !option.useVariable; 65 | }; 66 | optionNodeJS.onchange = () => { 67 | option.nodejs = !option.nodejs; 68 | }; 69 | }; 70 | 71 | const initBlacklistArea = () => { 72 | document.getElementById('blacklist-upper-case').onchange = () => { 73 | blacklist.upperCase = !blacklist.upperCase; 74 | resetResults(); 75 | }; 76 | 77 | document.getElementById('blacklist-lower-case').onchange = () => { 78 | blacklist.lowerCase = !blacklist.lowerCase; 79 | resetResults(); 80 | }; 81 | 82 | document.getElementById('blacklist-number').onchange = () => { 83 | blacklist.number = !blacklist.number; 84 | resetResults(); 85 | }; 86 | 87 | document.getElementById('blacklist-space').onchange = () => { 88 | blacklist.space = !blacklist.space; 89 | resetResults(); 90 | }; 91 | 92 | document.getElementById('blacklist-dollar').onchange = () => { 93 | blacklist.dollar = !blacklist.dollar; 94 | resetResults(); 95 | }; 96 | 97 | document.getElementById('blacklist-percent').onchange = () => { 98 | blacklist.percent = !blacklist.percent; 99 | resetResults(); 100 | }; 101 | 102 | document.getElementById('blacklist-asterisk').onchange = () => { 103 | blacklist.asterisk = !blacklist.asterisk; 104 | resetResults(); 105 | }; 106 | 107 | document.getElementById('blacklist-underscore').onchange = () => { 108 | blacklist.underscore = !blacklist.underscore; 109 | resetResults(); 110 | }; 111 | 112 | document.getElementById('blacklist-equals').onchange = () => { 113 | blacklist.equals = !blacklist.equals; 114 | resetResults(); 115 | }; 116 | 117 | document.getElementById('blacklist-single-quotes').onchange = () => { 118 | blacklist.singleQuotes = !blacklist.singleQuotes; 119 | resetResults(); 120 | }; 121 | 122 | document.getElementById('blacklist-double-quotes').onchange = () => { 123 | blacklist.doubleQuotes = !blacklist.doubleQuotes; 124 | resetResults(); 125 | }; 126 | 127 | document.getElementById('blacklist-backtick').onchange = () => { 128 | blacklist.backtick = !blacklist.backtick; 129 | resetResults(); 130 | }; 131 | 132 | document.getElementById('blacklist-dot').onchange = () => { 133 | blacklist.dot = !blacklist.dot; 134 | resetResults(); 135 | }; 136 | 137 | document.getElementById('blacklist-slash').onchange = () => { 138 | blacklist.slash = !blacklist.slash; 139 | resetResults(); 140 | }; 141 | 142 | document.getElementById('blacklist-backslash').onchange = () => { 143 | blacklist.backslash = !blacklist.backslash; 144 | resetResults(); 145 | }; 146 | 147 | document.getElementById('blacklist-curly-brackets').onchange = () => { 148 | blacklist.curlyBrackets = !blacklist.curlyBrackets; 149 | resetResults(); 150 | }; 151 | 152 | document.getElementById('blacklist-angle-brackets').onchange = () => { 153 | blacklist.angleBrackets = !blacklist.angleBrackets; 154 | resetResults(); 155 | }; 156 | }; -------------------------------------------------------------------------------- /scripts/js-obfuscator.js: -------------------------------------------------------------------------------- 1 | /* 2 | * JavaScript Obfuscator (https://js.retn0.kr) 3 | * 4 | * Copyright nbsp1221. All rights reserved. 5 | * License: MIT 6 | * GitHub Repository: https://github.com/nbsp1221/javascript-obfuscator 7 | */ 8 | 9 | const option = { 10 | useVariable: true, 11 | nodejs: false 12 | }; 13 | 14 | const blacklist = { 15 | // Basic 16 | upperCase: true, 17 | lowerCase: true, 18 | number: false, 19 | 20 | // Special 21 | space: false, 22 | dollar: false, // $ 23 | percent: false, // % 24 | asterisk: false, // * 25 | underscore: false, // _ 26 | equals: false, // = 27 | singleQuotes: false, // ' 28 | doubleQuotes: false, // " 29 | backtick: false, // ` 30 | dot: false, // . 31 | slash: false, // / 32 | backslash: false, // \ 33 | curlyBrackets: false, // { or } 34 | angleBrackets: false // < or > 35 | }; 36 | 37 | // Memoization 38 | let internalResults = {}; 39 | let digitResults = {}; 40 | let characterResults = {}; 41 | 42 | const resetResults = () => { 43 | internalResults = {}; 44 | digitResults = {}; 45 | characterResults = {}; 46 | }; 47 | 48 | const INTERNAL = { 49 | false: { 50 | isWrap: () => { 51 | return false; 52 | }, 53 | result: () => { 54 | return `![]`; 55 | } 56 | }, 57 | true: { 58 | isWrap: () => { 59 | return false; 60 | }, 61 | result: () => { 62 | return `!![]`; 63 | } 64 | }, 65 | undefined: { 66 | isWrap: () => { 67 | return true; 68 | }, 69 | result: () => { 70 | return `[][[]]`; 71 | } 72 | }, 73 | NaN: { 74 | isWrap: () => { 75 | return false; 76 | }, 77 | result: () => { 78 | return `+[![]]`; 79 | } 80 | }, 81 | Infinity: { 82 | isWrap: () => { 83 | return false; 84 | }, 85 | result: () => { 86 | if (!blacklist.slash) return `${makeDigit(1)}/${makeDigit(0)}`; 87 | if (!blacklist.number) return `+(1+${makeCharacter('e')}+1000)`; 88 | return `+(${makeDigit(1)}+${makeCharacter('e')}+[${makeDigit(1)}]+[${makeDigit(0)}]+[${makeDigit(0)}]+[${makeDigit(0)}])`; 89 | } 90 | }, 91 | 1.1e+101: { 92 | isWrap: () => { 93 | return false; 94 | }, 95 | result: () => { 96 | if (!blacklist.number) return `+(11+${makeCharacter('e')}+100)`; 97 | return `+(${makeDigit(1)}+[${makeDigit(1)}]+${makeCharacter('e')}+[${makeDigit(1)}]+[${makeDigit(0)}]+[${makeDigit(0)}])`; 98 | } 99 | }, 100 | 'function flat() { [native code] }': { 101 | isWrap: () => { 102 | return false; 103 | }, 104 | result: () => { 105 | return `[][${makeString('flat')}]+[]`; 106 | } 107 | }, 108 | 'function String() { [native code] }': { 109 | isWrap: () => { 110 | return false; 111 | }, 112 | result: () => { 113 | return `([]+[])[${makeString('constructor')}]+[]`; 114 | } 115 | }, 116 | '[object Object]': { 117 | isWrap: () => { 118 | return false; 119 | }, 120 | result: () => { 121 | return `[]+{}`; 122 | } 123 | }, 124 | '[object Array Iterator]': { 125 | isWrap: () => { 126 | return false; 127 | }, 128 | result: () => { 129 | return `[][${makeString('entries')}]()+[]`; 130 | } 131 | }, 132 | '': { 133 | isWrap: () => { 134 | return true; 135 | }, 136 | result: () => { 137 | return `([]+[])[${makeString('sub')}]()`; 138 | } 139 | }, 140 | '': { 141 | isWrap: () => { 142 | return true; 143 | }, 144 | result: () => { 145 | return `([]+[])[${makeString('fontcolor')}]()`; 146 | } 147 | }, 148 | 'function%20flat%28%29%20%7B%20%5Bnative%20code%5D%20%7D': { 149 | isWrap: () => { 150 | return true; 151 | }, 152 | result: () => { 153 | return makeEval(makeString('return escape([]["flat"])')); 154 | } 155 | }, 156 | '%3Csub%3E%3C/sub%3E': { 157 | isWrap: () => { 158 | return true; 159 | }, 160 | result: () => { 161 | return makeEval(makeString('return escape(([]+[])["sub"]())')); 162 | } 163 | } 164 | }; 165 | 166 | const DIGIT = { 167 | 0: { 168 | isWrap: () => { 169 | if (!blacklist.number) return true; 170 | return false; 171 | }, 172 | result: () => { 173 | if (!blacklist.number) return 0; 174 | return `+[]`; 175 | } 176 | }, 177 | 1: { 178 | isWrap: () => { 179 | if (!blacklist.number) return true; 180 | return false; 181 | }, 182 | result: () => { 183 | if (!blacklist.number) return 1; 184 | return `+${makeInternal(true)}`; 185 | } 186 | }, 187 | 2: { 188 | isWrap: () => { 189 | if (!blacklist.number) return true; 190 | return false; 191 | }, 192 | result: () => { 193 | if (!blacklist.number) return 2; 194 | return `${makeInternal(true)}+${makeInternal(true)}`; 195 | } 196 | }, 197 | 3: { 198 | isWrap: () => { 199 | if (!blacklist.number) return true; 200 | return false; 201 | }, 202 | result: () => { 203 | if (!blacklist.number) return 3; 204 | return `${makeDigit(2)}+${makeInternal(true)}`; 205 | } 206 | }, 207 | 4: { 208 | isWrap: () => { 209 | if (!blacklist.number) return true; 210 | return false; 211 | }, 212 | result: () => { 213 | if (!blacklist.number) return 4; 214 | if (!blacklist.angleBrackets) return `${makeDigit(2)}<<${makeInternal(true)}`; 215 | return `${makeDigit(3)}+${makeInternal(true)}`; 216 | } 217 | }, 218 | 5: { 219 | isWrap: () => { 220 | if (!blacklist.number) return true; 221 | return false; 222 | }, 223 | result: () => { 224 | if (!blacklist.number) return 5; 225 | if (!blacklist.angleBrackets) return `${makeDigit(4, true)}+${makeInternal(true)}`; 226 | return `${makeDigit(4)}+${makeInternal(true)}`; 227 | } 228 | }, 229 | 6: { 230 | isWrap: () => { 231 | if (!blacklist.number) return true; 232 | return false; 233 | }, 234 | result: () => { 235 | if (!blacklist.number) return 6; 236 | if (!blacklist.angleBrackets) return `${makeDigit(3)}<<${makeInternal(true)}`; 237 | if (!blacklist.asterisk) return `${makeDigit(3, true)}*${makeDigit(2, true)}`; 238 | return `${makeDigit(5)}+${makeInternal(true)}`; 239 | } 240 | }, 241 | 7: { 242 | isWrap: () => { 243 | if (!blacklist.number) return true; 244 | return false; 245 | }, 246 | result: () => { 247 | if (!blacklist.number) return 7; 248 | if (!blacklist.angleBrackets) return `${makeDigit(6, true)}+${makeInternal(true)}`; 249 | return `${makeDigit(6)}+${makeInternal(true)}`; 250 | } 251 | }, 252 | 8: { 253 | isWrap: () => { 254 | if (!blacklist.number) return true; 255 | return false; 256 | }, 257 | result: () => { 258 | if (!blacklist.number) return 8; 259 | if (!blacklist.angleBrackets) return `${makeDigit(2)}<<${makeDigit(2)}`; 260 | if (!blacklist.asterisk) return `${makeDigit(2, true)}**${makeDigit(3, true)}`; 261 | return `${makeDigit(7)}+${makeInternal(true)}`; 262 | } 263 | }, 264 | 9: { 265 | isWrap: () => { 266 | if (!blacklist.number) return true; 267 | return false; 268 | }, 269 | result: () => { 270 | if (!blacklist.number) return 9; 271 | if (!blacklist.angleBrackets) return `${makeDigit(8, true)}+${makeInternal(true)}`; 272 | if (!blacklist.asterisk) return `${makeDigit(3, true)}**${makeDigit(2, true)}`; 273 | return `${makeDigit(8)}+${makeInternal(true)}`; 274 | } 275 | } 276 | }; 277 | 278 | const CHARACTER = { 279 | 'a': { 280 | isWrap: () => { 281 | return true; 282 | }, 283 | result: () => { 284 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('a'); 285 | return `(${makeInternal(false)}+[])[${makeDigit(1)}]`; 286 | } 287 | }, 288 | 'b': { 289 | isWrap: () => { 290 | return true; 291 | }, 292 | result: () => { 293 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('b'); 294 | if (!blacklist.curlyBrackets) return `${makeInternal('[object Object]', true)}[${makeDigit(2)}]`; 295 | return `${makeInternal('[object Array Iterator]', true)}[${makeDigit(2)}]`; 296 | } 297 | }, 298 | 'c': { 299 | isWrap: () => { 300 | return true; 301 | }, 302 | result: () => { 303 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('c'); 304 | if (!blacklist.curlyBrackets) return `${makeInternal('[object Object]', true)}[${makeDigit(5)}]`; 305 | return `${makeInternal('function flat() { [native code] }', true)}[${makeDigit(3)}]`; 306 | } 307 | }, 308 | 'd': { 309 | isWrap: () => { 310 | return true; 311 | }, 312 | result: () => { 313 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('d'); 314 | return `(${makeInternal(undefined)}+[])[${makeDigit(2)}]`; 315 | } 316 | }, 317 | 'e': { 318 | isWrap: () => { 319 | return true; 320 | }, 321 | result: () => { 322 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('e'); 323 | return `(${makeInternal(true)}+[])[${makeDigit(3)}]`; 324 | } 325 | }, 326 | 'f': { 327 | isWrap: () => { 328 | return true; 329 | }, 330 | result: () => { 331 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('f'); 332 | return `(${makeInternal(false)}+[])[${makeDigit(0)}]`; 333 | } 334 | }, 335 | 'g': { 336 | isWrap: () => { 337 | return true; 338 | }, 339 | result: () => { 340 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('g'); 341 | if (!blacklist.number) return `${makeInternal('function String() { [native code] }', true)}[14]`; 342 | return `${makeInternal('function String() { [native code] }', true)}[${makeDigit(1)}+[${makeDigit(4)}]]`; 343 | } 344 | }, 345 | 'h': { 346 | isWrap: () => { 347 | return true; 348 | }, 349 | result: () => { 350 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('h'); 351 | if (!blacklist.number) return `(17)[${makeString('toString')}](20)`; 352 | return `(+(${makeDigit(1)}+[${makeDigit(7)}]))[${makeString('toString')}](${makeDigit(2)}+[${makeDigit(0)}])`; 353 | } 354 | }, 355 | 'i': { 356 | isWrap: () => { 357 | return true; 358 | }, 359 | result: () => { 360 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('i'); 361 | if (!blacklist.number) return `(${makeInternal(undefined)}+[])[5]`; 362 | return `([${makeInternal(false)}]+${makeInternal(undefined)})[${makeDigit(1)}+[${makeDigit(0)}]]`; 363 | } 364 | }, 365 | 'j': { 366 | isWrap: () => { 367 | return true; 368 | }, 369 | result: () => { 370 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('j'); 371 | if (!blacklist.curlyBrackets) return `${makeInternal('[object Object]', true)}[${makeDigit(3)}]`; 372 | return `${makeInternal('[object Array Iterator]', true)}[${makeDigit(3)}]`; 373 | } 374 | }, 375 | 'k': { 376 | isWrap: () => { 377 | return true; 378 | }, 379 | result: () => { 380 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('k'); 381 | if (!blacklist.number) return `(20)[${makeString('toString')}](21)`; 382 | return `(+(${makeDigit(2)}+[${makeDigit(0)}]))[${makeString('toString')}](${makeDigit(2)}+[${makeDigit(1)}])`; 383 | } 384 | }, 385 | 'l': { 386 | isWrap: () => { 387 | return true; 388 | }, 389 | result: () => { 390 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('l'); 391 | return `(${makeInternal(false)}+[])[${makeDigit(2)}]`; 392 | } 393 | }, 394 | 'm': { 395 | isWrap: () => { 396 | return true; 397 | }, 398 | result: () => { 399 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('m'); 400 | if (!blacklist.number) return `((${makeDigit(0)})[${makeString('constructor')}]+[])[11]`; 401 | return `((${makeDigit(0)})[${makeString('constructor')}]+[])[${makeDigit(1)}+[${makeDigit(1)}]]`; 402 | } 403 | }, 404 | 'n': { 405 | isWrap: () => { 406 | return true; 407 | }, 408 | result: () => { 409 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('n'); 410 | return `(${makeInternal(undefined)}+[])[${makeDigit(1)}]`; 411 | } 412 | }, 413 | 'o': { 414 | isWrap: () => { 415 | return true; 416 | }, 417 | result: () => { 418 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('o'); 419 | if (!blacklist.curlyBrackets) return `${makeInternal('[object Object]', true)}[${makeDigit(1)}]`; 420 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[6]`; 421 | return `(${makeInternal(true)}+${makeInternal('function flat() { [native code] }')})[${makeDigit(1)}+[${makeDigit(0)}]]`; 422 | } 423 | }, 424 | 'p': { 425 | isWrap: () => { 426 | return true; 427 | }, 428 | result: () => { 429 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('p'); 430 | if (!blacklist.number) return `(25)[${makeString('toString')}](30)`; 431 | return `(+(${makeDigit(2)}+[${makeDigit(5)}]))[${makeString('toString')}](${makeDigit(3)}+[${makeDigit(0)}])`; 432 | } 433 | }, 434 | 'q': { 435 | isWrap: () => { 436 | return true; 437 | }, 438 | result: () => { 439 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('q'); 440 | if (!blacklist.number) return `(26)[${makeString('toString')}](30)`; 441 | return `(+(${makeDigit(2)}+[${makeDigit(6)}]))[${makeString('toString')}](${makeDigit(3)}+[${makeDigit(0)}])`; 442 | } 443 | }, 444 | 'r': { 445 | isWrap: () => { 446 | return true; 447 | }, 448 | result: () => { 449 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('r'); 450 | return `(${makeInternal(true)}+[])[${makeDigit(1)}]`; 451 | } 452 | }, 453 | 's': { 454 | isWrap: () => { 455 | return true; 456 | }, 457 | result: () => { 458 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('s'); 459 | return `(${makeInternal(false)}+[])[${makeDigit(3)}]`; 460 | } 461 | }, 462 | 't': { 463 | isWrap: () => { 464 | return true; 465 | }, 466 | result: () => { 467 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('t'); 468 | return `(${makeInternal(true)}+[])[${makeDigit(0)}]`; 469 | } 470 | }, 471 | 'u': { 472 | isWrap: () => { 473 | return true; 474 | }, 475 | result: () => { 476 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('u'); 477 | return `(${makeInternal(undefined)}+[])[${makeDigit(0)}]`; 478 | } 479 | }, 480 | 'v': { 481 | isWrap: () => { 482 | return true; 483 | }, 484 | result: () => { 485 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('v'); 486 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[23]`; 487 | return `${makeInternal('function flat() { [native code] }', true)}[${makeDigit(2)}+[${makeDigit(3)}]]`; 488 | } 489 | }, 490 | 'w': { 491 | isWrap: () => { 492 | return true; 493 | }, 494 | result: () => { 495 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('w'); 496 | if (!blacklist.number) return `(32)[${makeString('toString')}](33)`; 497 | return `(+(${makeDigit(3)}+[${makeDigit(2)}]))[${makeString('toString')}](${makeDigit(3)}+[${makeDigit(3)}])`; 498 | } 499 | }, 500 | 'x': { 501 | isWrap: () => { 502 | return true; 503 | }, 504 | result: () => { 505 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('x'); 506 | if (!blacklist.number) return `(33)[${makeString('toString')}](34)`; 507 | return `(+(${makeDigit(1)}+[${makeDigit(0)}]+[${makeDigit(1)}]))[${makeString('toString')}](${makeDigit(3)}+[${makeDigit(4)}])[${makeDigit(1)}]`; 508 | } 509 | }, 510 | 'y': { 511 | isWrap: () => { 512 | return true; 513 | }, 514 | result: () => { 515 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('y'); 516 | if (!blacklist.number) return `(${makeInternal(Infinity)}+[])[${makeDigit(7)}]`; 517 | return `(${makeInternal(NaN)}+[${makeInternal(Infinity)}])[${makeDigit(1)}+[${makeDigit(0)}]]`; 518 | } 519 | }, 520 | 'z': { 521 | isWrap: () => { 522 | return true; 523 | }, 524 | result: () => { 525 | if (!blacklist.lowerCase && !isNoWrapString()) return wrapString('z'); 526 | if (!blacklist.number) return `(35)[${makeString('toString')}](36)`; 527 | return `(+(${makeDigit(3)}+[${makeDigit(5)}]))[${makeString('toString')}](${makeDigit(3)}+[${makeDigit(6)}])`; 528 | } 529 | }, 530 | 531 | 'A': { 532 | isWrap: () => { 533 | return true; 534 | }, 535 | result: () => { 536 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('A'); 537 | return `${makeInternal('[object Array Iterator]', true)}[${makeDigit(8)}]`; 538 | } 539 | }, 540 | 'B': { 541 | isWrap: () => { 542 | return true; 543 | }, 544 | result: () => { 545 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('B'); 546 | if (!blacklist.number) return `((${makeInternal(false)})[${makeString('constructor')}]+[])[9]`; 547 | return `([${makeDigit(0)}]+(${makeInternal(false)})[${makeString('constructor')}])[${makeDigit(1)}+[${makeDigit(0)}]]`; 548 | } 549 | }, 550 | 'C': { 551 | isWrap: () => { 552 | return true; 553 | }, 554 | result: () => { 555 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('C'); 556 | return `${makeInternal('%3Csub%3E%3C/sub%3E', true)}[${makeDigit(2)}]`; 557 | } 558 | }, 559 | 'D': { 560 | isWrap: () => { 561 | return true; 562 | }, 563 | result: () => { 564 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('D'); 565 | if (!blacklist.number) return `${makeInternal('function%20flat%28%29%20%7B%20%5Bnative%20code%5D%20%7D', true)}[48]`; 566 | return `${makeInternal('function%20flat%28%29%20%7B%20%5Bnative%20code%5D%20%7D', true)}[[${makeDigit(4)}]+[${makeDigit(8)}]]`; 567 | } 568 | }, 569 | 'E': { 570 | isWrap: () => { 571 | return true; 572 | }, 573 | result: () => { 574 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('E'); 575 | return `${makeInternal('%3Csub%3E%3C/sub%3E', true)}[${makeDigit(8)}]`; 576 | } 577 | }, 578 | 'I': { 579 | isWrap: () => { 580 | return true; 581 | }, 582 | result: () => { 583 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('I'); 584 | return `(${makeInternal(Infinity)}+[])[${makeDigit(0)}]`; 585 | } 586 | }, 587 | 'N': { 588 | isWrap: () => { 589 | return true; 590 | }, 591 | result: () => { 592 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('N'); 593 | return `(${makeInternal(NaN)}+[])[${makeDigit(0)}]`; 594 | } 595 | }, 596 | 'O': { 597 | isWrap: () => { 598 | return true; 599 | }, 600 | result: () => { 601 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('O'); 602 | if (!blacklist.curlyBrackets) return `${makeInternal('[object Object]', true)}[${makeDigit(8)}]`; 603 | return makeEval(makeString('return unescape("%4f")')); 604 | } 605 | }, 606 | 'S': { 607 | isWrap: () => { 608 | return true; 609 | }, 610 | result: () => { 611 | if (!blacklist.upperCase && !isNoWrapString()) return wrapString('S'); 612 | if (!blacklist.number) return `${makeInternal('function String() { [native code] }', true)}[9]`; 613 | return `(${makeDigit(0)}+${makeInternal('function String() { [native code] }')})[${makeDigit(1)}+[${makeDigit(0)}]]`; 614 | } 615 | }, 616 | 617 | '0': { 618 | isWrap: () => { 619 | if (!blacklist.number) return true; 620 | return false; 621 | }, 622 | result: () => { 623 | if (!blacklist.number && !isNoWrapString()) return wrapString('0'); 624 | return `${makeDigit(0, true)}+[]`; 625 | } 626 | }, 627 | '1': { 628 | isWrap: () => { 629 | if (!blacklist.number) return true; 630 | return false; 631 | }, 632 | result: () => { 633 | if (!blacklist.number && !isNoWrapString()) return wrapString('1'); 634 | return `${makeDigit(1, true)}+[]`; 635 | } 636 | }, 637 | '2': { 638 | isWrap: () => { 639 | if (!blacklist.number) return true; 640 | return false; 641 | }, 642 | result: () => { 643 | if (!blacklist.number && !isNoWrapString()) return wrapString('2'); 644 | return `${makeDigit(2, true)}+[]`; 645 | } 646 | }, 647 | '3': { 648 | isWrap: () => { 649 | if (!blacklist.number) return true; 650 | return false; 651 | }, 652 | result: () => { 653 | if (!blacklist.number && !isNoWrapString()) return wrapString('3'); 654 | return `${makeDigit(3, true)}+[]`; 655 | } 656 | }, 657 | '4': { 658 | isWrap: () => { 659 | if (!blacklist.number) return true; 660 | return false; 661 | }, 662 | result: () => { 663 | if (!blacklist.number && !isNoWrapString()) return wrapString('4'); 664 | return `${makeDigit(4, true)}+[]`; 665 | } 666 | }, 667 | '5': { 668 | isWrap: () => { 669 | if (!blacklist.number) return true; 670 | return false; 671 | }, 672 | result: () => { 673 | if (!blacklist.number && !isNoWrapString()) return wrapString('5'); 674 | return `${makeDigit(5, true)}+[]`; 675 | } 676 | }, 677 | '6': { 678 | isWrap: () => { 679 | if (!blacklist.number) return true; 680 | return false; 681 | }, 682 | result: () => { 683 | if (!blacklist.number && !isNoWrapString()) return wrapString('6'); 684 | return `${makeDigit(6, true)}+[]`; 685 | } 686 | }, 687 | '7': { 688 | isWrap: () => { 689 | if (!blacklist.number) return true; 690 | return false; 691 | }, 692 | result: () => { 693 | if (!blacklist.number && !isNoWrapString()) return wrapString('7'); 694 | return `${makeDigit(7, true)}+[]`; 695 | } 696 | }, 697 | '8': { 698 | isWrap: () => { 699 | if (!blacklist.number) return true; 700 | return false; 701 | }, 702 | result: () => { 703 | if (!blacklist.number && !isNoWrapString()) return wrapString('8'); 704 | return `${makeDigit(8, true)}+[]`; 705 | } 706 | }, 707 | '9': { 708 | isWrap: () => { 709 | if (!blacklist.number) return true; 710 | return false; 711 | }, 712 | result: () => { 713 | if (!blacklist.number && !isNoWrapString()) return wrapString('9'); 714 | return `${makeDigit(9, true)}+[]`; 715 | } 716 | }, 717 | 718 | ' ': { 719 | isWrap: () => { 720 | return true; 721 | }, 722 | result: () => { 723 | if (!blacklist.space && !isNoWrapString()) return wrapString(' '); 724 | if (!blacklist.curlyBrackets) return `${makeInternal('[object Object]', true)}[${makeDigit(7)}]`; 725 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[8]`; 726 | return `(${makeInternal(false)}+${makeInternal('function flat() { [native code] }')})[${makeDigit(2)}+[${makeDigit(0)}]]`; 727 | } 728 | }, 729 | '$': { 730 | isWrap: () => { 731 | return true; 732 | }, 733 | result: () => { 734 | if (!blacklist.dollar && !isNoWrapString()) return wrapString('$'); 735 | return makeEval(makeString('return unescape("%24")')); 736 | } 737 | }, 738 | '\n': { 739 | isWrap: () => { 740 | return true; 741 | }, 742 | result: () => { 743 | if (!blacklist.lowerCase && !blacklist.backslash && !isNoWrapString()) return wrapString('\\n'); 744 | return makeEval(makeString('return unescape("%0a")')); 745 | } 746 | }, 747 | '%': { 748 | isWrap: () => { 749 | return true; 750 | }, 751 | result: () => { 752 | if (!blacklist.percent && !isNoWrapString()) return wrapString('%'); 753 | if (!blacklist.number) return `${makeInternal('function%20flat%28%29%20%7B%20%5Bnative%20code%5D%20%7D', true)}[8]`; 754 | return `${makeInternal('function%20flat%28%29%20%7B%20%5Bnative%20code%5D%20%7D', true)}[${makeDigit(3)}+[${makeDigit(0)}]]`; 755 | } 756 | }, 757 | '*': { 758 | isWrap: () => { 759 | return true; 760 | }, 761 | result: () => { 762 | if (!blacklist.asterisk && !isNoWrapString()) return wrapString('*'); 763 | return makeEval(makeString('return unescape("%38")')); 764 | } 765 | }, 766 | '_': { 767 | isWrap: () => { 768 | return true; 769 | }, 770 | result: () => { 771 | if (!blacklist.underscore && !isNoWrapString()) return wrapString('_'); 772 | return makeEval(makeString('return unescape("%5f")')); 773 | } 774 | }, 775 | '=': { 776 | isWrap: () => { 777 | return true; 778 | }, 779 | result: () => { 780 | if (!blacklist.equals && !isNoWrapString()) return wrapString('='); 781 | if (!blacklist.number) return `${makeInternal('', true)}[11]`; 782 | return `${makeInternal('', true)}[${makeDigit(1)}+[${makeDigit(1)}]]`; 783 | } 784 | }, 785 | '+': { 786 | isWrap: () => { 787 | return true; 788 | }, 789 | result: () => { 790 | if (!isNoWrapString()) return wrapString('+'); 791 | return `(${makeInternal(1.1e+101)}+[])[${makeDigit(4)}]`; 792 | } 793 | }, 794 | "'": { 795 | isWrap: () => { 796 | return true; 797 | }, 798 | result: () => { 799 | if (!blacklist.singleQuotes) { 800 | if (!blacklist.doubleQuotes) return `"'"`; 801 | if (!blacklist.backtick) return "`'`"; 802 | if (!blacklist.backslash) return `'\\''`; 803 | } 804 | 805 | return makeEval(makeString('return unescape("%27")')); 806 | } 807 | }, 808 | '"': { 809 | isWrap: () => { 810 | return true; 811 | }, 812 | result: () => { 813 | if (!blacklist.doubleQuotes) { 814 | if (!blacklist.singleQuotes) return `'"'`; 815 | if (!blacklist.backtick) return '`"`'; 816 | if (!blacklist.backslash) return `"\\""`; 817 | } 818 | 819 | if (!blacklist.number) return `${makeInternal('', true)}[12]`; 820 | return `${makeInternal('', true)}[${makeDigit(1)}+[${makeDigit(2)}]]`; 821 | } 822 | }, 823 | '.': { 824 | isWrap: () => { 825 | return true; 826 | }, 827 | result: () => { 828 | if (!blacklist.dot && !isNoWrapString()) return wrapString('.'); 829 | if (!blacklist.slash) return `((${makeDigit(1, true)}/${makeDigit(2, true)})+[])[${makeDigit(1)}]`; 830 | return `(${makeInternal(1.1e+101)}+[])[${makeDigit(1)}]`; 831 | } 832 | }, 833 | '/': { 834 | isWrap: () => { 835 | return true; 836 | }, 837 | result: () => { 838 | if (!blacklist.slash && !isNoWrapString()) return wrapString('/'); 839 | if (!blacklist.number) return `${makeInternal('', true)}[6]`; 840 | return `(${makeInternal(true)}+${makeInternal('')})[${makeDigit(1)}+[${makeDigit(0)}]]`; 841 | } 842 | }, 843 | '\\': { 844 | isWrap: () => { 845 | return true; 846 | }, 847 | result: () => { 848 | if (!blacklist.backslash && !isNoWrapString()) return wrapString('\\\\'); 849 | return makeEval(makeString('return unescape("%5c")')); 850 | } 851 | }, 852 | '(': { 853 | isWrap: () => { 854 | return true; 855 | }, 856 | result: () => { 857 | if (!isNoWrapString()) return wrapString('('); 858 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[13]`; 859 | return `${makeInternal('function flat() { [native code] }', true)}[${makeDigit(1)}+[${makeDigit(3)}]]`; 860 | } 861 | }, 862 | ')': { 863 | isWrap: () => { 864 | return true; 865 | }, 866 | result: () => { 867 | if (!isNoWrapString()) return wrapString(')'); 868 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[14]`; 869 | return `${makeInternal('function flat() { [native code] }', true)}[${makeDigit(1)}+[${makeDigit(4)}]]`; 870 | } 871 | }, 872 | '{': { 873 | isWrap: () => { 874 | return true; 875 | }, 876 | result: () => { 877 | if (!blacklist.curlyBrackets && !isNoWrapString()) return wrapString('{'); 878 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[16]`; 879 | return `(${makeInternal(true)}+${makeInternal('function flat() { [native code] }')})[${makeDigit(2)}+[${makeDigit(0)}]]`; 880 | } 881 | }, 882 | '}': { 883 | isWrap: () => { 884 | return true; 885 | }, 886 | result: () => { 887 | if (!blacklist.curlyBrackets && !isNoWrapString()) return wrapString('}'); 888 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[32]`; 889 | return `${makeInternal('function flat() { [native code] }', true)}[${makeDigit(3)}+[${makeDigit(2)}]]`; 890 | } 891 | }, 892 | '[': { 893 | isWrap: () => { 894 | return true; 895 | }, 896 | result: () => { 897 | if (!isNoWrapString()) return wrapString('['); 898 | if (!blacklist.curlyBrackets) return `${makeInternal('[object Object]', true)}[${makeDigit(0)}]`; 899 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[18]`; 900 | return `${makeInternal('function flat() { [native code] }', true)}[${makeDigit(1)}+[${makeDigit(8)}]]`; 901 | } 902 | }, 903 | ']': { 904 | isWrap: () => { 905 | return true; 906 | }, 907 | result: () => { 908 | if (!isNoWrapString()) return wrapString(']'); 909 | 910 | if (!blacklist.curlyBrackets) { 911 | if (!blacklist.number) return `${makeInternal('[object Object]', true)}[14]`; 912 | return `${makeInternal('[object Object]', true)}[${makeDigit(1)}+[${makeDigit(4)}]]`; 913 | } 914 | 915 | if (!blacklist.number) return `${makeInternal('function flat() { [native code] }', true)}[30]`; 916 | return `${makeInternal('function flat() { [native code] }', true)}[${makeDigit(3)}+[${makeDigit(0)}]]`; 917 | } 918 | }, 919 | '<': { 920 | isWrap: () => { 921 | return true; 922 | }, 923 | result: () => { 924 | if (!blacklist.angleBrackets && !isNoWrapString()) return wrapString('<'); 925 | return `${makeInternal('', true)}[${makeDigit(0)}]`; 926 | } 927 | }, 928 | '>': { 929 | isWrap: () => { 930 | return true; 931 | }, 932 | result: () => { 933 | if (!blacklist.angleBrackets && !isNoWrapString()) return wrapString('>'); 934 | return `${makeInternal('', true)}[${makeDigit(4)}]`; 935 | } 936 | } 937 | }; 938 | 939 | const wrapString = (value) => { 940 | if (!blacklist.singleQuotes) return `'${value}'`; 941 | if (!blacklist.doubleQuotes) return `"${value}"`; 942 | if (!blacklist.backtick) return '`' + value + '`'; 943 | 944 | console.error('wrapString() Error!'); 945 | }; 946 | 947 | const isNoWrapString = () => { 948 | return blacklist.singleQuotes && blacklist.doubleQuotes && blacklist.backtick; 949 | }; 950 | 951 | const makeInternal = (value, wrap = false) => { 952 | if (!internalResults.hasOwnProperty(value)) { 953 | internalResults[value] = INTERNAL[value].result(); 954 | } 955 | 956 | if (wrap && !INTERNAL[value].isWrap()) { 957 | return '(' + internalResults[value] + ')'; 958 | } 959 | else { 960 | return internalResults[value]; 961 | } 962 | }; 963 | 964 | const makeDigit = (value, wrap = false) => { 965 | if (!digitResults.hasOwnProperty(value)) { 966 | digitResults[value] = DIGIT[value].result(); 967 | } 968 | 969 | if (wrap && !DIGIT[value].isWrap()) { 970 | return '(' + digitResults[value] + ')'; 971 | } 972 | else { 973 | return digitResults[value]; 974 | } 975 | }; 976 | 977 | const makeCharacter = (value, wrap = false) => { 978 | if (!characterResults.hasOwnProperty(value)) { 979 | characterResults[value] = CHARACTER[value].result(); 980 | } 981 | 982 | if (wrap && !CHARACTER[value].isWrap()) { 983 | return '(' + characterResults[value] + ')'; 984 | } 985 | else { 986 | return characterResults[value]; 987 | } 988 | }; 989 | 990 | const makeString = (value, wrap = false) => { 991 | const results = []; 992 | 993 | for (const char of value) { 994 | results.push(makeCharacter(char, true)); 995 | } 996 | 997 | if (wrap) { 998 | return '(' + results.join('+') + ')'; 999 | } 1000 | else { 1001 | return results.join('+'); 1002 | } 1003 | }; 1004 | 1005 | const makeEval = (value) => { 1006 | if (option.nodejs) { 1007 | const args = ['require', 'module', 'exports', '__dirname', '__filename']; 1008 | const argsStr = args.map(makeString).join(', '); 1009 | const callArgsStr = args.join(', '); 1010 | 1011 | return `[][${makeString('flat')}][${makeString('constructor')}](${argsStr}, ${value})(${callArgsStr})`; 1012 | } 1013 | else { 1014 | return `[][${makeString('flat')}][${makeString('constructor')}](${value})()`; 1015 | } 1016 | }; 1017 | 1018 | const createVariableNames = (candidates, variableCount) => { 1019 | const results = []; 1020 | let length = 1; 1021 | 1022 | const createPermutation = (goalLength, variableName = '') => { 1023 | if (results.length === variableCount) { 1024 | return; 1025 | } 1026 | 1027 | if (variableName.length === goalLength) { 1028 | results.push(variableName); 1029 | return; 1030 | } 1031 | 1032 | candidates.forEach((v) => { 1033 | createPermutation(goalLength, variableName + v); 1034 | }); 1035 | }; 1036 | 1037 | if (candidates.length > 0) { 1038 | while (results.length < variableCount) { 1039 | createPermutation(length); 1040 | length++; 1041 | } 1042 | } 1043 | 1044 | return results; 1045 | }; 1046 | 1047 | const obfuscate = (jsCode, variableCandidates = [], iterationCount = 50) => { 1048 | const results = []; 1049 | 1050 | for (const char of jsCode) { 1051 | let makedCode; 1052 | 1053 | if (CHARACTER.hasOwnProperty(char)) { 1054 | makedCode = makeCharacter(char, true); 1055 | } 1056 | else { 1057 | if (blacklist.upperCase && char >= 'A' && char <= 'Z' || isNoWrapString()) { 1058 | const hexCode = char.charCodeAt().toString(16); 1059 | makedCode = makeEval(makeString(`return unescape("${hexCode.length === 4 ? `\\u${hexCode}` : `%${hexCode}`}")`)); 1060 | } 1061 | else { 1062 | makedCode = wrapString(char); 1063 | } 1064 | } 1065 | 1066 | results.push(makedCode); 1067 | } 1068 | 1069 | let presetCode = ''; 1070 | let resultCode = makeEval(results.join('+')); 1071 | 1072 | if (!option.useVariable) { 1073 | return resultCode; 1074 | } 1075 | 1076 | if (!blacklist.dollar) variableCandidates.push('$'); 1077 | if (!blacklist.underscore) variableCandidates.push('_'); 1078 | 1079 | variableCandidates = [... new Set(variableCandidates)]; 1080 | let variableNames = createVariableNames(variableCandidates, 50); 1081 | 1082 | const makeShorter = (targetCode) => { 1083 | if (variableNames.length === 0) { 1084 | return; 1085 | } 1086 | 1087 | let variableCode = `${variableNames[0]}=${targetCode};`; 1088 | let replaceCode = replaceAll(resultCode, targetCode, variableNames[0]); 1089 | 1090 | if (replaceCode.length + variableCode.length < resultCode.length) { 1091 | presetCode += variableCode; 1092 | resultCode = replaceCode; 1093 | variableNames = variableNames.slice(1); 1094 | } 1095 | }; 1096 | 1097 | makeShorter(makeString('toString')); 1098 | makeShorter(makeString('constructor')); 1099 | makeShorter(makeString('flat')); 1100 | 1101 | const copyPresetCode = presetCode; 1102 | const copyResultCode = resultCode; 1103 | const copyvariableNames = [...variableNames]; 1104 | 1105 | let minPresetCode = presetCode; 1106 | let minResultCode = resultCode; 1107 | 1108 | // Find min code at random 1109 | for (let i = 0; i < iterationCount; i++) { 1110 | const candidates = []; 1111 | const shuffle = []; 1112 | 1113 | for (const key in characterResults) { 1114 | if (characterResults[key].indexOf(`'`) !== -1) continue; 1115 | if (characterResults[key].indexOf(`"`) !== -1) continue; 1116 | if (characterResults[key].indexOf('`') !== -1) continue; 1117 | 1118 | candidates.push(characterResults[key]); 1119 | } 1120 | 1121 | while (candidates.length > 0) { 1122 | const chosen = candidates.splice(Math.floor(Math.random() * candidates.length), 1)[0]; 1123 | shuffle.push(chosen); 1124 | } 1125 | 1126 | shuffle.forEach((v) => { 1127 | makeShorter(v); 1128 | }); 1129 | 1130 | if (minResultCode.length > resultCode.length) { 1131 | minPresetCode = presetCode; 1132 | minResultCode = resultCode; 1133 | } 1134 | 1135 | presetCode = copyPresetCode; 1136 | resultCode = copyResultCode; 1137 | variableNames = [...copyvariableNames]; 1138 | } 1139 | 1140 | return minPresetCode + minResultCode; 1141 | }; 1142 | 1143 | const replaceAll = (targetString, searchString, replaceString) => { 1144 | return targetString.split(searchString).join(replaceString); 1145 | }; -------------------------------------------------------------------------------- /styles/common.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | 3 | /* Initialization */ 4 | * { 5 | font-family: 'Roboto', sans-serif; 6 | } 7 | a { 8 | color: #608CBA; 9 | } 10 | fieldset { 11 | box-sizing: border-box; 12 | margin: 0; 13 | } 14 | textarea { 15 | box-sizing: border-box; 16 | display: block; 17 | font-family: 'Consolas', monospace; 18 | font-size: 16px; 19 | padding: 10px; 20 | width: 100%; 21 | height: 200px; 22 | } 23 | 24 | /* Header */ 25 | .link-title { 26 | font-size: 30px; 27 | font-weight: bold; 28 | padding: 30px; 29 | text-align: center; 30 | } 31 | .link-title > a { 32 | color: black; 33 | text-decoration: none; 34 | } 35 | 36 | /* Main */ 37 | .main-contents { 38 | margin: 0 auto; 39 | width: 90%; 40 | max-width: 1000px; 41 | } 42 | .main-contents fieldset { 43 | margin-bottom: 30px; 44 | } 45 | .code-area { 46 | margin-bottom: 30px; 47 | overflow: hidden; 48 | } 49 | .code-area > .length { 50 | float: left; 51 | margin-top: 10px; 52 | } 53 | .code-area > .run-button { 54 | float: right; 55 | margin-top: 10px; 56 | } 57 | .code-area > .run-button > button { 58 | background: none; 59 | border: none; 60 | color: deeppink; 61 | cursor: pointer; 62 | font-size: 16px; 63 | outline: none; 64 | padding: 0; 65 | text-decoration: underline; 66 | } 67 | .button-area { 68 | margin-bottom: 30px; 69 | } 70 | .button-area > button { 71 | font-size: 16px; 72 | padding: 10px; 73 | width: 100%; 74 | } 75 | .fieldset-area { 76 | display: flex; 77 | flex-wrap: wrap; 78 | } 79 | .fieldset-area > section { 80 | overflow: hidden; 81 | padding: 15px; 82 | } 83 | .fieldset-area .title { 84 | font-weight: bold; 85 | margin-bottom: 5px; 86 | padding-left: 3px; 87 | } 88 | .fieldset-area .checkbox-area { 89 | float: left; 90 | margin-right: 10px; 91 | } 92 | .fieldset-area .input-text { 93 | margin-top: 15px; 94 | padding-left: 3px; 95 | } 96 | .fieldset-area .explain { 97 | margin-bottom: 6px; 98 | } 99 | .fieldset-area .explain > div { 100 | margin-bottom: 2px; 101 | } 102 | .fieldset-area .explain > p { 103 | font-size: 14px; 104 | color: #888888; 105 | margin: 0; 106 | } 107 | 108 | /* Footer */ 109 | footer { 110 | margin: 40px 0; 111 | padding: 10px; 112 | text-align: center; 113 | } 114 | .github-link { 115 | margin-bottom: 4px; 116 | } 117 | .copyright > a { 118 | color: black; 119 | text-decoration: none; 120 | } --------------------------------------------------------------------------------