Skip to content

Instantly share code, notes, and snippets.

@churchofthought
Created April 29, 2021 12:12
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 churchofthought/8ada3999d2a258dc4446cef7f93f7bc2 to your computer and use it in GitHub Desktop.
Save churchofthought/8ada3999d2a258dc4446cef7f93f7bc2 to your computer and use it in GitHub Desktop.
JS Hook (Coursera Playback Speed)
//webpack:///./static/bundles/video-experimental/constants.js
//webpack:///./static/bundles/video-experimental/components/settingsMenu/VideoSettingsMenu.jsx
const speeds = [];
const playbackDelta = 0.250001;
for (let i = 0.75; i <= 10; i += playbackDelta)
speeds.push(i);
let hooked = false;
const old = Array.prototype.findIndex;
function findIndex() {
if (!hooked) {
const error = new Error();
if (/VideoSettingsMenu/.test(error.stack) && this.length == 6 && this[0] == 0.75 &&
this[1] == 1 &&
this[2] == 1.25 &&
this[3] == 1.5 &&
this[4] == 1.75 &&
this[5] == 2) {
Array.prototype.splice.apply(this, [0, this.length].concat(speeds));
//undo hook
hooked = true;
Array.prototype.findIndex = old;
}
}
return old.apply(this, arguments);
}
Array.prototype.findIndex = findIndex;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment