Memrise Full Markdown (multimedia level)

Enables full Markdown support for multimedia levels on Memrise.com

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name           Memrise Full Markdown (multimedia level)
// @description    Enables full Markdown support for multimedia levels on Memrise.com
// @match          http://*.memrise.com/*
// @match          https://*.memrise.com/*
// @run-at         document-end
// @version        1.1.1
// @grant          none
// @namespace      https://greasyfork.org/users/213706
// ==/UserScript==

if(typeof unsafeWindow == "undefined") {
  unsafeWindow = window;
}

if(typeof unsafeWindow.level_multimedia != "undefined") {
  main();
} else if(unsafeWindow.MEMRISE.renderer) {
  unsafeWindow.MEMRISE.renderer.allowed_tags = "*";
}

function main() {
  
  // Disable Memrise's native markdown 
  var data = unsafeWindow.level_multimedia;

  unsafeWindow.MEMRISE.renderer.allowed_tags = "*";
  unsafeWindow.level_multimedia = "";
  
  // When renderer is loaded, enable all HTML tags and render Markdown
  window.addEventListener('load', function() {
    setTimeout(renderMultimedia, 100);
  }, false);

  function renderMultimedia() {
    unsafeWindow.MEMRISE.renderer.allowed_tags = "*";

    var e = unsafeWindow.MEMRISE.renderer.rich_format(data);
    unsafeWindow.$(".multimedia-wrapper").html(e);
    unsafeWindow.MEMRISE.renderer.do_embeds(unsafeWindow.$(".multimedia-wrapper"));
  }
}