BunPro Training Mode

Add a training mode to BunPro after a lesson and before a quizz

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         BunPro Training Mode
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add a training mode to BunPro after a lesson and before a quizz
// @author       Luc Pitipuis
// @match        https://bunpro.jp/*
// @match        http://bunpro.jp/*
// @match        https://www.bunpro.jp/*
// @match        http://www.bunpro.jp/*
// @grant        GM.openInTab
// @license      GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

(function() {
    'use strict';
    if(window.location.pathname == "/learn") {
        var exercices_button = $('<div class="study-popup-btn" id="training">Some training first</div>')
        exercices_button.insertAfter($("#start-quiz"))
        exercices_button.on("click", function() {
            window.localStorage.setItem('grammar-ids', JSON.stringify($(".temp_grammar_ids").data("grammar-ids")))
            GM.openInTab(window.location.origin + "/cram")
        })
    }
})();

(function() {
    'use strict';
    // if we are in cram mode and there are some points to train
    if(window.location.pathname == "/cram" && window.localStorage.getItem('grammar-ids')) {
        // select custom grammar
        var t = $(".add-selected-grammar--cram")
        t.click()
        // select each grammar point
        JSON.parse(window.localStorage.getItem('grammar-ids')).forEach(id => $("#grammar-point-id-"+ id).click())
        // cleanup
        window.localStorage.removeItem('grammar-ids')
        // start session
        $(".start-cram-session-btn").click()

        // in training mode, we show the grammar
        $('.setsumei-structure').insertBefore($('.study-question-japanese'))
    }

})();