Add From JSFuck operation

This commit is contained in:
RomaRoma? 2026-05-04 11:30:08 +02:00
parent ec4f1f5605
commit afd8717819
3 changed files with 55 additions and 1 deletions

View File

@ -501,7 +501,8 @@
"BSON deserialise", "BSON deserialise",
"To MessagePack", "To MessagePack",
"From MessagePack", "From MessagePack",
"Render Markdown" "Render Markdown",
"From JSFuck"
] ]
}, },
{ {

View File

@ -0,0 +1,53 @@
/**
* @author Roma476 [friciu.robert09@gmail.com]
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* From JSFuck operation
*/
class FromJSFuck extends Operation {
/**
* FromJSFuck constructor
*/
constructor() {
super();
this.name = "From JSFuck";
this.module = "Default";
this.description = "Decodes JSFuck encoded JavaScript. JSFuck uses only 6 characters: <code>[</code>, <code>]</code>, <code>(</code>, <code>)</code>, <code>!</code> and <code>+</code>.<br><br>e.g. <code>[][(![]+[])[+[]]+...]</code> becomes <code>alert(1)</code>";
this.infoURL = "https://wikipedia.org/wiki/JSFuck";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
// Input Validation
for (let i = 0; i < input.length; i++) {
const char = input[i];
if (!["[", "]", "(", ")", "!", "+"].includes(char)) {
throw new OperationError(`Invalid character at position ${i}: ${char}`);
}
}
try {
return String(Function('"use strict"; return (' + input + ')')());
} catch (err) {
throw new OperationError("Unable to decode JSFuck: " + err.message);
}
}
}
export default FromJSFuck;

View File