Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gorbiz
Last active February 23, 2024 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gorbiz/d84657c6ef57268b53cc to your computer and use it in GitHub Desktop.
Save gorbiz/d84657c6ef57268b53cc to your computer and use it in GitHub Desktop.
Coursera.org videos: Auto hide controls & toggle play on click
// ==UserScript==
// @name Coursera friendly video player
// @description Auto hide coursera.org's video controls & toggle play on click
// @match https://class.coursera.org/*/lecture/view?lecture_id=*
// @version 0.2
// ==/UserScript==
function autoHideControls() {
var controls, timeout;
function hideControls() {
timeout = setTimeout(function() {
controls = document.getElementsByClassName('mejs-controls')[0];
if (!controls) return;
controls.style.display = 'none';
}, 2000);
}
window.onmousemove = function() {
clearTimeout(timeout);
hideControls();
if (controls) controls.style.display = '';
}
hideControls();
}
function togglePlayOnClickVideo() {
var video = document.getElementsByTagName('video')[0];
if (!video) return;
video.onclick = function() {
this[this.paused ? 'play' : 'pause']();
}
}
window.addEventListener('load', autoHideControls, false);
window.addEventListener('load', togglePlayOnClickVideo, false);
@gorbiz
Copy link
Author

gorbiz commented Oct 21, 2014

The @match pattern seems to restrictive, not sure what's wrong but confirmed that "https://class.coursera.org/*" works.

@arseniy-panfilov
Copy link

the autoHideControls helped me today, thanks!
had to make a couple of adjustments though:

// #1
// @match          https://www.coursera.org/*

// #2
// function hideControls() 
       controls = document.getElementsByClassName('rc-ControlBar')[0];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment