// Author: DosX
// E-Mail: collab@kay-software.ru
// GitHub: https://github.com/DosX-dev
// Telegram: @DosX_dev

const detect = main;

function main() {
    if (Binary.isHeuristicScan()) {
        switch (Binary.getFileSuffix().toLowerCase()) {
            case "js":
            case "jse":
            case "jsc":
                var options = "";

                if (!Binary.isPlainText()) {
                    options = "bytecode";
                } else {
                    if (Binary.getSize() > 3000) {
                        var scriptContent = Binary.getString(0x00, Binary.getSize());

                        var unquotedContent = '',
                            inQuotes = false;

                        for (var i = 0; i < scriptContent.length; i++) {
                            if (scriptContent[i] === '"' || scriptContent[i] === "'" || scriptContent[i] === '`') {
                                inQuotes = !inQuotes;
                            } else if (!inQuotes) {
                                unquotedContent += scriptContent[i];
                            }
                        }

                        if (/\s{2}/.test(unquotedContent)) {
                            options = "minified/compiled";
                        }
                    }
                }

                _setResult("~language", "JavaScript", String(), Binary.isVerbose() ? options : String());

                break;
        }
    }
}