Last active
February 23, 2024 12:25
-
-
Save gorbiz/d84657c6ef57268b53cc to your computer and use it in GitHub Desktop.
Coursera.org videos: Auto hide controls & toggle play on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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); |
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
The @match pattern seems to restrictive, not sure what's wrong but confirmed that "https://class.coursera.org/*" works.