Forvo Audio in the Memrise Level Editor

Adds a column to the Memrise level editor with buttons to check for Forvo audio

当前为 2014-11-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Forvo Audio in the Memrise Level Editor
  3. // @namespace https://greasyfork.org/users/5238-carpiediem
  4. // @version 0.4
  5. // @description Adds a column to the Memrise level editor with buttons to check for Forvo audio
  6. // @author carpiediem
  7. // @match http://www.memrise.com/course/*/*/edit/*
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  9. // @grant GM_xmlhttpRequest
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. // This script will not work until you enter your own Forvo.com API key
  14. // To get an API key follow these steps:
  15. // 1. If you don't have a Forvo account already, browse to http://www.forvo.com/signup/ and sign up.
  16. // 2. Check your email & click the link to verify your account.
  17. // 3. Browse to http://api.forvo.com/login/ and log in.
  18. // 4. Click on the "Plans & Pricing" tab and click the button for the Free Plan. <http://api.forvo.com/plans-and-pricing/>.
  19. // 5. Check the box to accept the license terms and click on the "Choose plan for free" button.
  20. // 6. Click on the "Your account" tab. <http://api.forvo.com/account/>
  21. // 7. Copy the API key (a string of letters and numbers) on the right side of the screen.
  22. // 8. Paste the key in the line of code below. Replace the Xs, but keep the quotes.
  23. forvoApiKey = '656e4ccd61af3166507836caa55e777b';
  24.  
  25.  
  26.  
  27. //======DO NOT EDIT BELOW THIS LINE======
  28.  
  29. $('.container-main').css('width','1100px');
  30. $('#levels').after('<div class="pull-left"><a href="http://www.forvo.com/" title="Pronunciations by Forvo"><img src="http://api.forvo.com/byforvo.gif" width="120" height="40" alt="Pronunciations by Forvo" style="border:0"></a></div>');
  31.  
  32. if (forvoApiKey == 'XXXXXXXXXXXXXXXXXXXXXXXXX') console.log('You need to enter your own API key from Forvo.com');
  33. else
  34. document.addEventListener("DOMNodeInserted", function(e) { // NO EVENT TRIGGERED ON THE DATABASE PAGE
  35. if (e.relatedNode.className != "level-things table") return false;
  36. $(e.relatedNode).find('th').eq(4).after('<th class="column"><span class="txt">Other Audio</span></th>');
  37. $(e.relatedNode).find('tr').each(function(){
  38. var word = $(this).find('td').eq(1).find('.text').text();
  39. $(this).find('td').eq(4).after('<td><div class="btn-group forvo-check" data-word="' + word + '"><button class="btn btn-mini dropdown-toggle" data-toggle="dropdown" style="overflow:hidden;">Check Forvo<i class="ico ico-s ico-arr-down"></i></button><div class="dropdown-menu audios"><img src="https://d107cgb5lgj7br.cloudfront.net/img/icons/loader@2x.gif" style="width:30px;" /></div></div></td>');
  40. });
  41. $('.forvo-check .dropdown-menu').css({'min-width':'30px', padding:'5px'});
  42. $('.forvo-check').click(function(){
  43. var languageCode = forvoCodes[ $('.add-level .dropdown-menu a:first').text().trim() ];
  44. var word = encodeURI( $(this).attr("data-word") );
  45. GM_xmlhttpRequest({
  46. method: "GET",
  47. url: "http://apifree.forvo.com/action/word-pronunciations/format/json/word/" + word + "/language/" + languageCode + "/order/rate-desc/limit/4/key/" + forvoApiKey + "/",
  48. onload: function(response) {
  49. var data = $.parseJSON(response.responseText);
  50. popupHTML = '';
  51. for (i in data.items) popupHTML += '<p><a class="audio-player audio-player-hover" href="' + decodeURI(data.items[i].pathmp3) + '" style="margin:0px" title="Right-click is broken in Firefox. You\'ll need to middle click to save the MP3 file."></a></p>';
  52. if (popupHTML=='') popupHTML = '<a href="http://www.forvo.com/word/' + encodeURI( $('.forvo-check.open').attr("data-word") ) + '/" target="_blank">nothing</a>';
  53. $('.forvo-check.open .dropdown-menu').html(popupHTML);
  54. }
  55. });
  56. });
  57. }, true); //end of addEventListener
  58.  
  59. var forvoCodes = {
  60. 'Afrikaans':'af',
  61. 'Ainu':false,
  62. 'Akan-Twi':'ak',
  63. 'Albanian':'sq',
  64. 'Algonquian languages':false,
  65. 'Amharic':'am',
  66. 'Ancient Greek':'grc',
  67. 'Anglo-Saxon':false,
  68. 'Arabic':'ar',
  69. 'Arabic Alphabet':'ar',
  70. 'Aramaic':false,
  71. 'Azerbaijani':'az',
  72. 'Basque':'eu',
  73. 'Belarusian':'be',
  74. 'Bengali':'bn',
  75. 'Bosnian':'bs',
  76. 'Breton':'br',
  77. 'Bulgarian':'bg',
  78. 'Burmese':'my',
  79. 'Cantonese':'yue',
  80. 'Cantonese Jyutping':'yue',
  81. 'Catalan':'ca',
  82. 'Cherokee':'chr',
  83. 'Chinese':'zh',
  84. 'Citizen Potawatomi':false,
  85. 'Classical Quranic Arabic':'ar',
  86. 'Coptic':false,
  87. 'Cornish':'kw',
  88. 'Creek':'mus',
  89. 'Croatian':'hr',
  90. 'Czech':'cs',
  91. 'Danish':'da',
  92. 'Dovahzul':false,
  93. 'Dutch':'nl',
  94. 'Eastern Armenian':'hy',
  95. 'Egyptian (Ancient)':false,
  96. 'Egyptian Arabic':'ar',
  97. 'English':'en',
  98. 'Esperanto':'eo',
  99. 'Estonian':'et',
  100. 'Faroese':'fo',
  101. 'Farsi':'fa',
  102. 'Finnish':'fi',
  103. 'Flemish':'vls',
  104. 'French':'fr',
  105. 'Georgian':'ka',
  106. 'German':'de',
  107. 'Greek':'el',
  108. 'Greenlandic':false,
  109. 'Guarani':'gn',
  110. 'Gujarati':'gu',
  111. 'Gulf Khaliji Arabic':'ar',
  112. 'Hakka':'hak',
  113. 'Hausa':'ha',
  114. 'Hawaiian':'haw',
  115. 'Hebrew':'he',
  116. 'Hindi':'hi',
  117. 'Hungarian':'hu',
  118. 'Icelandic':'is',
  119. 'Indonesian':'ind',
  120. 'Inuktitut':'iu',
  121. 'Iraqi Arabic':'ar',
  122. 'Irish':'ga',
  123. 'Italian':'it',
  124. 'Japanese':'ja',
  125. 'Kanji':'ja',
  126. 'Kaonde':false,
  127. 'Khmer':'km',
  128. 'Kinyarwanda':'rw',
  129. 'Klingon':'tlh',
  130. 'Korean':'ko',
  131. 'Kurdish':'ku',
  132. 'Kyrgyz':'ky',
  133. 'Ladin':false,
  134. 'Lakota':'lkt',
  135. 'Latin':'la',
  136. 'Latvian':'lv',
  137. 'Laz':'lzz',
  138. 'Levantine Arabic':'ar',
  139. 'Lingala':'ln',
  140. 'Lithuanian':'lt',
  141. 'Lojban':'lmo',
  142. 'Lu Mien':'hmn',
  143. 'Luganda':'lg',
  144. 'Lule Sami':'fi',
  145. 'Luxembourgish':'lb',
  146. 'Macedonian':'mk',
  147. 'Malay':'ms',
  148. 'Mandarin':'zh',
  149. 'Mandarin Spoken Only':'zh',
  150. 'Mandarin Traditional':'zh',
  151. 'Mandinka':false,
  152. 'Maori':'mi',
  153. 'Marathi':'mr',
  154. 'Marshallese':'mh',
  155. 'Modern Standard Arabic - roman alph':false,
  156. 'Mongolian':'mn',
  157. 'Nahuatl languages':'nah',
  158. "Na'vi":false,
  159. 'Nepali':'ne',
  160. 'Ningbo Dialect':'wuu',
  161. 'North African Maghrebi Arabic':'ar',
  162. 'Northern Sami':'se',
  163. 'Norwegian':'no',
  164. 'Nyanja':false,
  165. 'Occitan':'oc',
  166. 'Ossetic':'os',
  167. 'Pali':'pi',
  168. 'Pashto':'ps',
  169. 'Persian':'fa',
  170. 'Polish':'pl',
  171. 'Portuguese (Brazil)':'pt',
  172. 'Portuguese (European)':'pt',
  173. 'Punjabi':'pa',
  174. 'Quechua':'qu',
  175. 'Romaji':'ja',
  176. 'Romanian':'ro',
  177. 'Russian':'ru',
  178. 'Sanskrit':'sa',
  179. 'Scots':'sco',
  180. 'Scottish Gaelic':'gd',
  181. 'Serbian':'sr',
  182. 'Sinhala':'si',
  183. 'Slovak':'sk',
  184. 'Slovenian':'sl',
  185. 'Small German Dialects':'nds',
  186. 'Somali':'so',
  187. 'Soninke':false,
  188. 'Southern Sami':'fi',
  189. 'Spanish':'es',
  190. 'Swahili':'sw',
  191. 'Swedish':'sv',
  192. 'Swiss German':'gsw',
  193. 'Tagalog':'tl',
  194. 'Taishanese':'yue',
  195. 'Tamang':'ne',
  196. 'Tamil':'ta',
  197. 'Telugu':'te',
  198. 'Thai':'th',
  199. 'Tibetan':'bo',
  200. 'Toki Pona':'x-tp',
  201. 'Turkish':'tr',
  202. 'Ukrainian':'uk',
  203. 'Ume Sami':'fi',
  204. 'Urdu':'ur',
  205. 'Vietnamese':'vi',
  206. 'Welsh':'cy',
  207. 'Western Armenian':'hy',
  208. 'Wolof':'wo',
  209. 'Xhosa':'xh',
  210. 'Yiddish':'yi',
  211. 'Zulu':'zu'
  212. };