Created
October 30, 2025 16:48
-
-
Save yashkumaratri/cc22644294c9a88f99d134bcc3560661 to your computer and use it in GitHub Desktop.
Speed up videos on the stupid igotkarmayogi.gov.in platform
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
| (() => { | |
| const RATE = 2; // set 1.25, 1.5, 1.75, 2.0 | |
| const setRate = m => { | |
| try { | |
| m.defaultPlaybackRate = RATE; | |
| m.playbackRate = RATE; | |
| if ('preservesPitch' in m) m.preservesPitch = false; | |
| if ('webkitPreservesPitch' in m) m.webkitPreservesPitch = false; | |
| } catch (_) {} | |
| }; | |
| // Patch playbackRate and play so speed is applied even if we cannot query the element | |
| try { | |
| const proto = HTMLMediaElement.prototype; | |
| if (!proto.__patchedPlaybackRate) { | |
| const desc = Object.getOwnPropertyDescriptor(proto, 'playbackRate'); | |
| Object.defineProperty(proto, 'playbackRate', { | |
| get() { try { return RATE; } catch (e) { return desc.get.call(this); } }, | |
| set(v) { try { desc.set.call(this, RATE); setRate(this); } catch (e) {} } | |
| }); | |
| proto.__patchedPlaybackRate = true; | |
| } | |
| if (!proto.__patchedPlay) { | |
| const origPlay = proto.play; | |
| proto.play = function(...args) { | |
| setRate(this); | |
| const p = origPlay.apply(this, args); | |
| if (p && typeof p.then === 'function') { | |
| return p.then(x => { setRate(this); return x; }) | |
| .catch(e => { setRate(this); throw e; }); | |
| } | |
| return p; | |
| }; | |
| proto.__patchedPlay = true; | |
| } | |
| } catch (_) {} | |
| // Deep scan: DOM, shadow DOM, and same-origin iframes | |
| const wire = root => { | |
| try { | |
| root.querySelectorAll('video,audio').forEach(m => { | |
| setRate(m); | |
| ['play','loadedmetadata','canplay','ratechange','seeking','durationchange'] | |
| .forEach(ev => m.addEventListener(ev, () => setRate(m), true)); | |
| }); | |
| root.querySelectorAll('*').forEach(el => { if (el.shadowRoot) wire(el.shadowRoot); }); | |
| root.querySelectorAll('iframe').forEach(fr => { | |
| try { if (fr.contentDocument) wire(fr.contentDocument); } catch (_) {} | |
| }); | |
| } catch (_) {} | |
| }; | |
| wire(document); | |
| new MutationObserver(() => wire(document)).observe(document.documentElement, { childList: true, subtree: true }); | |
| setInterval(() => wire(document), 1000); | |
| // Try to inject into same-origin subframes by executing this function in their context | |
| const injectInto = win => { | |
| try { win.Function(`(${arguments.callee.caller.toString()})()` )(); } catch (_) {} | |
| }; | |
| (function injectAll(win) { | |
| Array.from(win.frames).forEach(fw => { | |
| try { if (fw.document) injectAll(fw); injectInto(fw); } catch (_) {} | |
| }); | |
| })(window); | |
| window.__checkRates = () => ([...document.querySelectorAll('video')].map(v => v.playbackRate)); | |
| console.log('Forced playbackRate =', RATE, 'for all reachable media in this page.'); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment