I’m a javascript newbie. Could someone please help me. I was able to make it work with AjaxStop() and 2 sec time delay. but then I had to wait 2 sec, or if audio is longer script does not work. I need it for script which is scanning webpage and add TAG to every kanji so i can style it in other way.
What i have so far:
$(document).ajaxStop(function () {
setTimeout(function(){
'use strict';
$("#boxes > div > ol > li").each(function( index ) {
var $index = index + 1;
var $quote = $("#boxes > div > ol > li:nth-child("+ $index +") > span.val");
var $questionTrimed = $.trim($quote.text());
var $numWords = $questionTrimed.split(" ").length;
var $questionCharNum = $questionTrimed.length;
var qsize = (3.2 - Math.sqrt($questionCharNum) * 0.4) * (1.1 - $numWords * 0.1);
console.log("idx: " + index + " qtrimmed: " + $questionTrimed + " qtrimmedLENGTH: " + $questionCharNum + " numWords: " + $numWords + " ftsize: " + qsize);
if (($numWords <= 4) && ($questionCharNum < 28)) {
$("#boxes > div > ol > li:nth-child(" + $index + ") > span.val").css({
fontSize: qsize +"rem",
'line-height': qsize +"rem"
});
} else {
$("#boxes > div > ol > li").css({
'float': 'left',
'width': '570px'
});
}
});
}, 2000);
});
take a look at the code for this script: https://github.com/cooljingle/memrise-render-html
The code does an html replacement every time a ‘box’ loads; you could probably just swap that part out.
WOW I was reading your scripts all night yesterday. But without any javascript experience, I was not able to understand much.
Thanks to your advice I was able to fix my problem but I have another one or at least I think i did it in wrong way.
I have javascript which I’m loading from the webserver is it possible to load them somehow from Greasemonkey ?
Here is what I have for now. I would like to be more user friendly but _kanjax_with_koohii.js is a 3 MB file.
Can I contact you somehow on any chat service?
// ==UserScript==
// @name MEMRISE KANJAX v3
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.memrise.com/course/*
// @grant none
// ==/UserScript==
$(document).ready(function() {
MEMRISE.garden.boxes.load = (function() {
var cached_function = MEMRISE.garden.boxes.load;
return function() {
MEMRISE.garden.boxes.activate_box = (function() {
var cached_function = MEMRISE.garden.boxes.activate_box;
return function() {
var result = cached_function.apply(this, arguments);
var scriptElementBpop = document.createElement( "script" );
scriptElementBpop.type = "text/javascript";
scriptElementBpop.src = "http://127.0.0.1:8887/_jquery.bpopup.min.js";
document.body.appendChild( scriptElementBpop );
var scriptElement = document.createElement( "script" );
scriptElement.type = "text/javascript";
scriptElement.src = "http://127.0.0.1:8887/_kanjax_with_koohii.js";
document.body.appendChild( scriptElement );
return result;
};
}());
return cached_function.apply(this, arguments);
};
}());
});
If you’re loading an external file you’ll want to do it once at the top of the script rather than once per box load.
You could put the content somewhere publicly accessible and then set about loading it from your script but I think it would probably be easier to minify your 3mb js file and put it directly in with the rest of this script.
You can send me a private message if you want to ask more specific questions.
Hey! I was trying the same thing (do something after a window is loaded), but
MEMRISE.garden.boxes is now undefined. I looked through all the events and this one might work:
MEMRISE.garden._events.activate.push(() => {
console.debug(‘activate’);
keyboard(true); //do something special with typing exercises
})
function keyboard(shuffle = false){
if(MEMRISE.garden.box.template === ‘typing’){
var input = MEMRISE.garden.box.$input.input.val();
var answer = MEMRISE.garden.box.testData.answer.value;
var rest = answer.rest(input);
if(shuffle){
shuffled_answer = answer.shuffle();
}
display(shuffled_answer.keep(rest));
}
}