Skip to content

Instantly share code, notes, and snippets.

@brospars
Created September 18, 2018 08:30
Show Gist options
  • Save brospars/0a6e076f1242d749257648815b98097d to your computer and use it in GitHub Desktop.
Save brospars/0a6e076f1242d749257648815b98097d to your computer and use it in GitHub Desktop.
Bookmarlet to generate table of content of a MOOC from edx studio
  1. Create a bookmarlet with the code below
  2. Go to the homepage of your MOOC in studio (in our case : studio.fun-mooc.fr/course/[MOOC_ID])
  3. Run the bookmarklet
javascript:(function(){
	var base_url = window.location.href.replace('studio.fun-mooc.fr/course','fun-mooc.fr/courses')+'/jump_to_id/';
	var sections = $('.outline-section');
	var sectionList = $('<ul/>');

	var expandables = $('.expand');

	expandables.click();

	sections.each(function(i, section) {
		var title = $(section).find('.section-title').text();
	  	var subsections = $(section).find('.outline-subsection');

	  	var sectionItem = $('<li></li>').append(
  			$('<a/>').attr('title', title).attr('href',base_url+$(section).data('locator').split('@').pop()).text(title)
		);
		var subsectionList = $('<ul/>');

	  	subsections.each(function(i, subsection) {
	  		var subtitle = $(subsection).find('.subsection-title').text();
	  		var units = $(subsection).find('.unit-title a');

	  		var subsectionItem = $('<li></li>').append(
	  			$('<a/>').attr('title', subtitle).attr('href',base_url+$(subsection).data('locator').split('@').pop()).text(subtitle)
  			);		

	  		var unitList = $('<ul/>');

	  		units.each(function(i, unit) {
	  			var $unit = $('<a/>').attr('title', $(unit).text()).attr('href',base_url+$(unit).attr('href').split('@').pop()).text($(unit).text());
	  			unitList.append($('<li></li>').append($unit));
			});

			subsectionItem.append(unitList);
	  		subsectionList.append(subsectionItem);
		});

		sectionItem.append(subsectionList);
		sectionList.append(sectionItem);
	});

	expandables.click();

	var output = $('<div>').append($('<xmp>').html(sectionList.prop('outerHTML')).css({float: 'right', width: '50%', height: '500px', 'white-space': 'normal'})).append(sectionList);

	window.open().document.write(output.html());
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment