-
-
Save naveedn/bc71e68debac2ff143f6b2928f74b220 to your computer and use it in GitHub Desktop.
Add speed controls to SAP Litmos
This file contains hidden or 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 Litmos speed controls | |
// @namespace rodrigo.deodoro@carta.com | |
// @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', '10'].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