Last active
June 15, 2020 09:17
-
-
Save met4000/56c4987cbe3b2a6ea9dbc4643ca0ddda to your computer and use it in GitHub Desktop.
A bookmarklet to add extra speed options to the echo player (supports x0-16, up to a reasonable number of decimal places)
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
if (!window.__echoUtil__speed__) { | |
window.__echoUtil__speed__ = {}; | |
__echoUtil__speed__.createOptionEl = function (speed) { | |
var optionEl = document.createElement("option"); | |
optionEl.value = speed; | |
optionEl.text = optionEl.value; | |
return optionEl; | |
}; | |
__echoUtil__speed__.updateOptions = function () { | |
var l = document.querySelector("#speed-select"); | |
l.innerHTML = ""; | |
for (var i = 0; i < __echoUtil__speed__.insertedSpeeds.length; i++) l.appendChild(__echoUtil__speed__.insertedSpeeds[i]); | |
l.value = 0; | |
}; | |
__echoUtil__speed__.settingsWheelEl = document.getElementsByClassName("echoPlayer")[0].querySelector("div > div > div.controls > div.controlsBar > div.right > div.video-menu.settings-menu > a"); | |
__echoUtil__speed__.settingsWheelEl.click(); | |
__echoUtil__speed__.insertedSpeeds = Array(__echoUtil__speed__.createOptionEl(0), ...document.querySelector("#speed-select").children); | |
__echoUtil__speed__.settingsWheelEl.click(); | |
__echoUtil__speed__.isMenuOpen = function () { return !!document.querySelector("#speed-select"); }; | |
document.getElementsByClassName("echoPlayer")[0].querySelector("div > div > div.controls > div.controlsBar > div.right > div.video-menu.settings-menu > a").onclick = function () { setTimeout(() => { if (__echoUtil__speed__.isMenuOpen()) __echoUtil__speed__.updateOptions(); }, 10); }; | |
} | |
var isOpen = __echoUtil__speed__.isMenuOpen(); | |
var speed = parseFloat(prompt("New Speed Option Value")); | |
if (speed < 0) throw new Error("Negative speed breaks the lecture player (-_-)"); | |
if (speed > 16) throw new Error("Too fast for the lecture player (<= x16)"); | |
if (!(0 <= speed && speed <= 16)) throw new Error("Unprocessable type '" + speed + "' - please input a float between 0 and 16"); | |
if (isOpen) __echoUtil__speed__.settingsWheelEl.click(); | |
var optionEl = __echoUtil__speed__.createOptionEl(speed), f = __echoUtil__speed__.insertedSpeeds.findIndex(el => el.value >= speed); | |
if (f == -1) __echoUtil__speed__.insertedSpeeds.push(optionEl); | |
else if (__echoUtil__speed__.insertedSpeeds[f].value != speed) __echoUtil__speed__.insertedSpeeds.splice(f, 0, optionEl); | |
if (isOpen) __echoUtil__speed__.settingsWheelEl.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
javascript: window.__echoUtil__speed__||(window.__echoUtil__speed__={},__echoUtil__speed__.createOptionEl=function(e){var _=document.createElement("option");return _.value=e,_.text=_.value,_},__echoUtil__speed__.updateOptions=function(){var e=document.querySelector("#speed-select");e.innerHTML="";for(var _=0;_<__echoUtil__speed__.insertedSpeeds.length;_++)e.appendChild(__echoUtil__speed__.insertedSpeeds[_]);e.value=0},__echoUtil__speed__.settingsWheelEl=document.getElementsByClassName("echoPlayer")[0].querySelector("div > div > div.controls > div.controlsBar > div.right > div.video-menu.settings-menu > a"),__echoUtil__speed__.settingsWheelEl.click(),__echoUtil__speed__.insertedSpeeds=Array(__echoUtil__speed__.createOptionEl(0),...document.querySelector("#speed-select").children),__echoUtil__speed__.settingsWheelEl.click(),__echoUtil__speed__.isMenuOpen=function(){return!!document.querySelector("#speed-select")},document.getElementsByClassName("echoPlayer")[0].querySelector("div > div > div.controls > div.controlsBar > div.right > div.video-menu.settings-menu > a").onclick=function(){setTimeout(()=>{__echoUtil__speed__.isMenuOpen()&&__echoUtil__speed__.updateOptions()},10)});var isOpen=__echoUtil__speed__.isMenuOpen(),speed=parseFloat(prompt("New Speed Option Value"));if(speed<0)throw new Error("Negative speed breaks the lecture player (-_-)");if(speed>16)throw new Error("Too fast for the lecture player (<= x16)");if(!(0<=speed&&speed<=16))throw new Error("Unprocessable type '"+speed+"' - please input a float between 0 and 16");isOpen&&__echoUtil__speed__.settingsWheelEl.click();var optionEl=__echoUtil__speed__.createOptionEl(speed),f=__echoUtil__speed__.insertedSpeeds.findIndex(e=>e.value>=speed);-1==f?__echoUtil__speed__.insertedSpeeds.push(optionEl):__echoUtil__speed__.insertedSpeeds[f].value!=speed&&__echoUtil__speed__.insertedSpeeds.splice(f,0,optionEl),isOpen&&__echoUtil__speed__.settingsWheelEl.click(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment