[Usercript] Typing Hint

Click on the plant icon to produce a hint.

// ==UserScript==
// @name         Memrise - Hint
// @namespace    http://tampermonkey.net/
// @match        https://www.memrise.com/course/*/garden/*
// @match        https://www.memrise.com/garden/review/*
// @match        https://app.memrise.com/garden/review/*// @grant        none
// ==/UserScript==

$(document).ready(function() {

    MEMRISE.garden._events.activate.push(() => {
        $('.ico-growth').on('click', function(e){
            hint();
        })
    })

    function hint(){
        console.log('HINT');
        var input = MEMRISE.garden.box.$input.input.val();
        var answer = MEMRISE.garden.box.testData.answer.value;

        //Produce hint
        var index = answer.equalUpTo(input);
        var hint = answer.substr(0, index + 1);
        MEMRISE.garden.box.$input.input.val(hint);
        //Events
        $('body').trigger('select'); //notify text changed for other scripts
        $('.typing-type-here').trigger('keydown'); //auto accept
    }

})


String.prototype.equalUpTo = function(str){
    for(var i = 0; i < Math.min(this.length, str.length); i++){
        if(this.charAt(i) !== str.charAt(i)) break;
    }
    return i;
}