Duolingo flashcards speaker

Add speaker to duolingo feature "review flashcards"

  1. // ==UserScript==
  2. // @name Duolingo flashcards speaker
  3. // @description Add speaker to duolingo feature "review flashcards"
  4. // @namespace vokracko
  5. // @author Lukáš Vokráčko
  6. // @include https://www.duolingo.com/*
  7. // @version 1.0
  8. // @grant none
  9. // @encoding utf-8
  10. // ==/UserScript==
  11.  
  12. var target = document.querySelector('body');
  13. var config = { attributes: false, childList: true, characterData: false, subtree: true};
  14. var counter = 1;
  15.  
  16. var play = function(counter, lang, word) { // play word
  17. soundManager2015.createSound(
  18. {
  19. id: counter,
  20. url: 'https://d7mj4aqfscim2.cloudfront.net/tts/' + lang + '/token/' + word,
  21. autoPlay: true
  22. });
  23. }
  24. var observer = new MutationObserver(function(mutations) {
  25. mutations.forEach(function(mutation) {
  26.  
  27. if($(mutation.addedNodes).find(".flashcard-word")) // when flashcards are shown
  28. {
  29. var lang = $(".language-choice.active").data('value');
  30. var wordNode = $(mutation.addedNodes).find("#current-container").find(".flashcard-word");
  31.  
  32. if(wordNode.length)
  33. {
  34. var word = $(wordNode).first().text();
  35. setTimeout(function() {play(counter, lang, word);}, 80); // wait until word is visible
  36. counter++;
  37. }
  38. }
  39. });
  40. });
  41.  
  42. observer.observe(target, config);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址