Skip to content

Instantly share code, notes, and snippets.

@roddds
Last active October 6, 2020 16:56
Show Gist options
  • Save roddds/ff9e386deed150f85dc820886c74739c to your computer and use it in GitHub Desktop.
Save roddds/ff9e386deed150f85dc820886c74739c to your computer and use it in GitHub Desktop.
Add speed controls to SAP Litmos
// ==UserScript==
// @name Litmos speed controls
// @namespace [email protected]
// @version 0.2
// @description Add speed controls to SAP Litmos videos
// @author Rodrigo Deodoro
// @match https://*.litmos.com/course/*
// ==/UserScript==
(function () {
'use strict';
console.log('Initializing script');
let done = false;
const addSpeedControls = () => {
if (done) {
return;
}
['1', '1.25', '1.5', '1.75', '2'].forEach((rate) => {
const iframeContent = document.querySelector('iframe').contentDocument.querySelector('#main-window');
const toolbar = iframeContent.querySelector('.controls');
const captionControls = toolbar.querySelector('.caption-controls');
const btn = document.createElement('button');
btn.className = 'btn cs-button';
btn.appendChild(document.createTextNode(`${rate}x`));
btn.onclick = () => {iframeContent.querySelector('video').playbackRate = rate};
captionControls.appendChild(btn);
});
console.log('Added speed controls');
done = true;
};
const waitForIframe = () => {
if (done) return;
console.log('Waiting for insert point...');
try {
if (
!document
.querySelector('iframe')
.contentDocument.querySelector('#main-window')
.querySelector('.caption-controls')
) {
throw Error();
}
} catch (e) {
setTimeout(waitForIframe, 500);
return;
}
addSpeedControls();
};
waitForIframe();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment