// ==UserScript==
// @name Forvo Audio in the Memrise Level Editor
// @namespace https://greasyfork.org/users/5238-carpiediem
// @version 0.7
// @description Adds a column to the Memrise level/database editor with buttons to check for Forvo audio
// @author carpiediem
// @match http://www.memrise.com/course/*/*/edit/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant GM_xmlhttpRequest
// @run-at document-end
// @downloadURL https://update.greasyfork.icu/scripts/6305/Forvo%20Audio%20in%20the%20Memrise%20Level%20Editor.user.js
// @updateURL https://update.greasyfork.icu/scripts/6305/Forvo%20Audio%20in%20the%20Memrise%20Level%20Editor.meta.js
// ==/UserScript==
// This script will not work until you enter your own Forvo.com API key
// To get an API key follow these steps:
// 1. If you don't have a Forvo account already, browse to http://www.forvo.com/signup/ and sign up.
// 2. Check your email & click the link to verify your account.
// 3. Browse to http://api.forvo.com/login/ and log in.
// 4. Click on the "Plans & Pricing" tab and click the button for the Free Plan. .
// 5. Check the box to accept the license terms and click on the "Choose plan for free" button.
// 6. Click on the "Your account" tab.
// 7. Copy the API key (a string of letters and numbers) on the right side of the screen.
// 8. Paste the key in the line of code below. Replace the Xs, but keep the quotes.
forvoApiKey = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
//======DO NOT EDIT BELOW THIS LINE======
$('.container-main').css('width','1200px');
$('#levels').after('
');
var firefoxTooltip = (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) ? ' Right-click is broken in Firefox. You\'ll need to middle click to save the MP3 file."' : '';
function addColumn(tableElement) {
$(tableElement).find('th').eq(4).after('
Other Audio
');
$(tableElement).find('tr').each(function(){
var word = $(this).find('td').eq(1).find('.text').text();
$(this).find('td').eq(4).after('
');
});
$('.forvo-check .dropdown-menu').css({'min-width':'30px', padding:'5px'});
$('.forvo-check').click(function(){
if ( $('.pool-name').size() )
var languageCode = forvoCodes[ $('.pool-name').text().trim() ];
else
var languageCode = forvoCodes[ $('.add-level .dropdown-menu a:first').text().trim() ];
if (languageCode=="haw")
var word = encodeURI( $(this).attr("data-word").replace("he ","").replace(/[ʻ']/,"%60") );
else
var word = encodeURI( $(this).attr("data-word") );
//console.log("API request to: http://apifree.forvo.com/action/word-pronunciations/format/json/word/" + word + "/language/" + languageCode + "/order/rate-desc/limit/4/key/" + forvoApiKey + "/");
GM_xmlhttpRequest({
method: "GET",
url: "http://apifree.forvo.com/action/word-pronunciations/format/json/word/" + word + "/language/" + languageCode + "/order/rate-desc/limit/4/key/" + forvoApiKey + "/",
onload: function(response) {
var data = $.parseJSON(response.responseText);
popupHTML = '';
for (i in data.items) popupHTML += '