VanderCat / RESH.EDU.VZLOM

// ==UserScript==
// @name         RESH.EDU.VZLOM
// @namespace    http://dauncorp.cc/
// @version      0.2.1.1
// @description  "хакает" проверку правильных ответов, лол
// @author       VanderCat
// @match        https://resh.edu.ru/subject/lesson/*/train/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    const resultButton = $('.js-result');
    function makeAnswerWrong(){
        document.oncontextmenu = function() {
            return false;
        };
        $(".test__task-num--active")
            .addClass('test__task-num--with-error')
            .removeClass('test__task-num--passed');
        resultButton
        .text('Пройдено ' + (getDataID().length - getWrongCount()) +' из ' + (getDataID().length))
    };
    function getWrongCount() {
        return $('.test__task-num--with-error').length;
    }
    function getDataID() {
        const idcount = $(".test-meta").length;
        var ids = [];
        $.each($(".test-meta"), function(i) { ids.push($(this).attr("data-test-id").text); });
        return ids
    };
    function makeData(ids) {
        const header = '{ "success": true, "data": {'
        const footer = '  }}'
        var text = header
        ids.forEach(function(item, i, arr) {
            if ( ids.length === i+1 ) {text += '"'+item+'": {"result": true}'}
            else {text += '"'+item+'": {"result": true},'};
        });
        text += footer;        return text;
    };
    function tryHack() {
        const data = makeData(getDataID());

        const showAnswerButton = $('.js-show-answer');
        const sendButton = $('.js-finish');
        const nextTest = $('.js-go-to-next-test-btn');


        console.log("hack by VanderCat 2020");
        showAnswerButton.show();
        Swal.fire({
            title: "Вы успешно прошли урок!",
            text: "Tip: Чтобы пометить ответ как неправильный нажмите правой кнопкой мыши по кнопки помощи" });

        nextTest.hide();
        sendButton.hide();
        resultButton
        .text('Пройдено ' + (getDataID().length) +' из ' + (getDataID().length))
        .show();
    };
    function HackHideBtnColorAlert() {
        Swal.fire({
            title: "Спрятать кнопку взлом?",
            html:  '<div><i>Для того что бы появились эти кнопки необходимо обновить страницу</i></div>',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Да',
            cancelButtonText: 'Нет'
        }).then((result) => {
            if (result.value) {
                $("#hackbutton").css( "display", "none" );
                tryHack();
            } else {tryHack();}
        });
        $.each($(".test__task-num"), function(i) {
            $(this).removeClass('test__task-num--with-error').addClass('test__task-num--passed'); });
    };
    $(".test__buttons-line").append(
        '<a href="javascript:void(0)" id="hackbutton" class="lk-form-submit js-clear" data-intro="Этот текст вообще вроде не работает лол">Взлом</a>'
    );
    $("#hackbutton").on("click", function(){HackHideBtnColorAlert()});
    $("._help").bind("contextmenu", function(e){makeAnswerWrong(); return false});
})();