<commit_before>/*jshint globalstrict:true, es5:true, sub:true, evil:true*/
/*globals XSS, SelectMenu, SelectStage, ScreenStage, InputStage, GameStage, Shape, Util*/

'use strict';

XSS.stages = {

    /**
     * @return {SelectStage}
     */
    main: function() {
        var menu;

        menu = new SelectMenu('main');
        menu.addOption(null, XSS.stages.inputName,
            'MULTIPLAYER',
            'Play with a friend or (un)friendly stranger.');
        menu.addOption(null, XSS.stages.startGame,
            'SINGLE PLAYER',
            'Play with yourself, get some practise.');
        menu.addOption(null, XSS.stages.themesScreen,
            'THEEEMES',
            'Change the color scheme YAY!');
        menu.addOption(null, XSS.stages.helpScreen,
            'HEEELP?!!',
            'How do I use this computer electronic device?');
        menu.addOption(null, XSS.stages.creditsScreen,
            'CREDITS',
            'Who spent all this blood & tears?');

        return new SelectStage(menu);
    },

    /**
     * @return {SelectStage}
     */
    askIsPublic: function() {
        var menu;

        menu = new SelectMenu('public');
        menu.addOption(true, XSS.stages.askIsFriendly,
            'QUICK MATCH',
            'Join or create a game using matchmaking.');
        menu.addOption(false, XSS.stages.askIsFriendly,
            'PRIVATE GAME',
            'Create a private game for friends.');

        return new SelectStage(menu);
    },

    /**
     * @return {SelectStage}
     */
    askIsFriendly: function() {
        var menu;

        menu = new SelectMenu('friendly');
        menu.addOption(true, XSS.stages.startGame,
            'FRIENDLY MODE', 'May slightly dent your ego ' + XSS.UNICODE_HEART);
        menu.addOption(false, XSS.stages.captcha,
            'XSS MODE',
            'The winner of a game is allowed to execute JavaScript in the ' +
            'browsers of every loser… ' +
            'while(true){alert(\'' + XSS.UNICODE_SKULL + '\');}');

        return new SelectStage(menu);
    },

    /**
     * @return {InputStage}
     */
    captcha: function() {
        var challenges, challenge, intro, stage, str, digit,
            nextstage = XSS.stages.startGame;

        str = Util.randomStr().substr(0, 3);
        digit = String(Util.randomBetween(0, 5));

        challenges = [
            'Array(document.scripts[0].tagName.length).join(\'\/\');',
            'location.protocol.split(\'\').reverse().join()[0];',
            '\'cakeshake!\'.charAt(Math.ceil(Math.random())*%d));',
            'Array(%d).join(encodeURI(\' \'));',
            'String(parseInt(\'FF\', 16));',
            'JSON.stringify({foo:\'%s\'});',
            'String([1,2,3][3]).charAt(%d);',
            'String(typeof []).charAt(%d);',
            'String(typeof (5%2)).charAt(%d);',
            'String(/%s/.test(\'%s\'));',
            '\'1234512345kip\'.lastIndexOf(\'%d\');'
        ];

        challenge = String(Util.randomItem(challenges));
        challenge = challenge.replace(/%s/g, str);
        challenge = challenge.replace(/%d/g, digit);

        intro = 'XSS mode allows the winner of a game to execute\n' +
                'JavaScript in the browsers of every loser. This may\n' +
                'damage you and/or your computer. If you accept\n' +
                'this risk, please enter the result of this statement:\n\n> ' +
                challenge + '\n> ';

        stage = new InputStage(null, nextstage, intro);
        stage.inputSubmit = function(error, value) {
            var top = XSS.font.height(intro);
            XSS.stages._captchaSubmit.call(stage, value, challenge, top);
        };

        return stage;
    },

    /**
     * @param {string} value
     * @param {string} challenge
     * @param {number} top
     * @private
     */
    _captchaSubmit: function(value, challenge, top) {
        var shape, text = '> ACCESS DENIED!!';

        if (value === String(eval(challenge))) { // 666
            text = '> bleep!';
            setTimeout(function() {
                XSS.stageflow.switchStage(this.nextStage);
            }.bind(this), 1000);
        }

        shape = XSS.font.shape(text, XSS.MENU_LEFT, XSS.MENU_TOP + top);
        shape.lifetime(0, 1000);
        XSS.shapes.message = shape;
    },

    themesScreen: function() {
        var setTheme, menu = new SelectMenu('theme');

        setTheme = function(index) {
            XSS.canvas.setTheme(XSS.themes[index]);
            Util.storage('theme', index);
        };

        for (var i = 0, m = XSS.themes.length; i < m; i++) {
            var title = XSS.themes[i].title,
                desc = XSS.themes[i].desc;
            menu.addOption(true, null, title, desc, setTheme);<commit_msg>Select theme in theme menu after reloading page<commit_after>/*jshint globalstrict:true, es5:true, sub:true, evil:true*/
/*globals XSS, SelectMenu, SelectStage, ScreenStage, InputStage, GameStage, Shape, Util*/

'use strict';

XSS.stages = {

    /**
     * @return {SelectStage}
     */
    main: function() {
        var menu;

        menu = new SelectMenu('main');
        menu.addOption(null, XSS.stages.inputName,
            'MULTIPLAYER',
            'Play with a friend or (un)friendly stranger.');
        menu.addOption(null, XSS.stages.startGame,
            'SINGLE PLAYER',
            'Play with yourself, get some practise.');
        menu.addOption(null, XSS.stages.themesScreen,
            'THEEEMES',
            'Change the color scheme YAY!');
        menu.addOption(null, XSS.stages.helpScreen,
            'HEEELP?!!',
            'How do I use this computer electronic device?');
        menu.addOption(null, XSS.stages.creditsScreen,
            'CREDITS',
            'Who spent all this blood & tears?');

        return new SelectStage(menu);
    },

    /**
     * @return {SelectStage}
     */
    askIsPublic: function() {
        var menu;

        menu = new SelectMenu('public');
        menu.addOption(true, XSS.stages.askIsFriendly,
            'QUICK MATCH',
            'Join or create a game using matchmaking.');
        menu.addOption(false, XSS.stages.askIsFriendly,
            'PRIVATE GAME',
            'Create a private game for friends.');

        return new SelectStage(menu);
    },

    /**
     * @return {SelectStage}
     */
    askIsFriendly: function() {
        var menu;

        menu = new SelectMenu('friendly');
        menu.addOption(true, XSS.stages.startGame,
            'FRIENDLY MODE', 'May slightly dent your ego ' + XSS.UNICODE_HEART);
        menu.addOption(false, XSS.stages.captcha,
            'XSS MODE',
            'The winner of a game is allowed to execute JavaScript in the ' +
            'browsers of every loser… ' +
            'while(true){alert(\'' + XSS.UNICODE_SKULL + '\');}');

        return new SelectStage(menu);
    },

    /**
     * @return {InputStage}
     */
    captcha: function() {
        var challenges, challenge, intro, stage, str, digit,
            nextstage = XSS.stages.startGame;

        str = Util.randomStr().substr(0, 3);
        digit = String(Util.randomBetween(0, 5));

        challenges = [
            'Array(document.scripts[0].tagName.length).join(\'\/\');',
            'location.protocol.split(\'\').reverse().join()[0];',
            '\'cakeshake!\'.charAt(Math.ceil(Math.random())*%d));',
            'Array(%d).join(encodeURI(\' \'));',
            'String(parseInt(\'FF\', 16));',
            'JSON.stringify({foo:\'%s\'});',
            'String([1,2,3][3]).charAt(%d);',
            'String(typeof []).charAt(%d);',
            'String(typeof (5%2)).charAt(%d);',
            'String(/%s/.test(\'%s\'));',
            '\'1234512345kip\'.lastIndexOf(\'%d\');'
        ];

        challenge = String(Util.randomItem(challenges));
        challenge = challenge.replace(/%s/g, str);
        challenge = challenge.replace(/%d/g, digit);

        intro = 'XSS mode allows the winner of a game to execute\n' +
                'JavaScript in the browsers of every loser. This may\n' +
                'damage you and/or your computer. If you accept\n' +
                'this risk, please enter the result of this statement:\n\n> ' +
                challenge + '\n> ';

        stage = new InputStage(null, nextstage, intro);
        stage.inputSubmit = function(error, value) {
            var top = XSS.font.height(intro);
            XSS.stages._captchaSubmit.call(stage, value, challenge, top);
        };

        return stage;
    },

    /**
     * @param {string} value
     * @param {string} challenge
     * @param {number} top
     * @private
     */
    _captchaSubmit: function(value, challenge, top) {
        var shape, text = '> ACCESS DENIED!!';

        if (value === String(eval(challenge))) { // 666
            text = '> bleep!';
            setTimeout(function() {
                XSS.stageflow.switchStage(this.nextStage);
            }.bind(this), 1000);
        }

        shape = XSS.font.shape(text, XSS.MENU_LEFT, XSS.MENU_TOP + top);
        shape.lifetime(0, 1000);
        XSS.shapes.message = shape;
    },

    themesScreen: function() {
        var setTheme, menu = new SelectMenu('theme');

        menu.selected = parseInt(Util.storage('theme'), 10) || 0;

        setTheme = function(index) {
            XSS.canvas.setTheme(XSS.themes[index]);
            Util.storage('theme', index);
        };

        for (var i = 0, m = XSS.themes.length; i < m; i++) {
            var title = XSS.themes[i].title,
                desc = XSS.themes[i].desc;
            menu.addOption(true, null, title, desc, setTheme);
{'fraction_non_alphanumeric': 0.15216263873042216, 'fraction_numerical': 0.00819417072917747, 'mean_word_length': 1.9768447051559124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5730953', 'n_tokens_mistral': 3052, 'n_tokens_neox': 2912, 'n_words': 652}