Coursera EXT - Play/Pause with [space bar] or click

Coursera Extension -- Enables space bar to play/pause the video. Based on http://userscripts.org/scripts/show/139512 by loopkid

  1. // ==UserScript==
  2. // @name Coursera EXT - Play/Pause with [space bar] or click
  3. // @description Coursera Extension -- Enables space bar to play/pause the video. Based on http://userscripts.org/scripts/show/139512 by loopkid
  4. // @namespace http://sepczuk.com/
  5. // @version 0.03
  6. // @include https://*.coursera.org/*/lecture/view*
  7. // @include https://*.coursera.org/*/lecture/preview_view*
  8. // @match https://*.coursera.org/*/lecture/view*
  9. // @match https://*.coursera.org/*/lecture/preview_view*
  10. // @copyright 2012-2013, Damian Sepczuk, damian at sepczuk period delme com; loopkid
  11. // ==/UserScript==
  12.  
  13. function contentEval(source) {
  14. if ('function' == typeof source) {
  15. source = '(' + source + ')();';
  16. }
  17. var script = document.createElement('script');
  18. script.setAttribute("type", "application/javascript");
  19. script.textContent = source;
  20. document.body.appendChild(script);
  21. document.body.removeChild(script);
  22. }
  23.  
  24.  
  25. function fixVideoPlayerShortcuts() {
  26.  
  27. // Check every 300ms if video player has finished loading
  28. var qlchecker = window.setInterval(function () { checkForQL_player(); }, 300);
  29.  
  30. function checkForQL_player() {
  31. if (typeof QL_player == "undefined") return;
  32.  
  33. // Disable checking of video player load status
  34. window.clearInterval(qlchecker);
  35. var playOrPause = function(player, media) {
  36. if (media.paused || media.ended) {
  37. media.play();
  38. } else {
  39. media.pause();
  40. };
  41. };
  42. SPACEBAR_KEY = 32;
  43.  
  44. QL_player.mediaelement_handle.options.keyActions.push({keys: [SPACEBAR_KEY], action: playOrPause});
  45. QL_player.mediaelement_media.addEventListener('click', function(){playOrPause(undefined, QL_player.mediaelement_media)});
  46. }
  47. }
  48.  
  49. contentEval(fixVideoPlayerShortcuts);

QingJ © 2025

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