Created
April 22, 2025 01:32
-
-
Save jwt625/7e44b6b20049682ebc63e9de9d4d9001 to your computer and use it in GitHub Desktop.
Tampermonkey script for speeding up web media
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 force‑1.25×‑every‑media | |
// @match *://*/* | |
// @run-at document-start | |
// ==/UserScript== | |
(() => { | |
const RATE = 1.5; | |
/* ---------- HTMLMediaElement ---------- */ | |
const desc = Object.getOwnPropertyDescriptor( | |
HTMLMediaElement.prototype, 'playbackRate'); | |
// hard‑override the setter so any “set to 1.0” gets ignored | |
Object.defineProperty(HTMLMediaElement.prototype, 'playbackRate', { | |
get() { return desc.get.call(this); }, | |
set(_) { return desc.set.call(this, RATE); } // always RATE | |
}); | |
// make sure play() kicks in with the right rate even on blob rewrites | |
const origPlay = HTMLMediaElement.prototype.play; | |
HTMLMediaElement.prototype.play = function (...args) { | |
if (this.playbackRate !== RATE) desc.set.call(this, RATE); | |
return origPlay.apply(this, args); | |
}; | |
/* ---------- Web‑Audio (AudioBufferSourceNode) ---------- */ | |
if (window.AudioBufferSourceNode) { | |
const origStart = AudioBufferSourceNode.prototype.start; | |
AudioBufferSourceNode.prototype.start = function (...args) { | |
try { | |
// multiply any preset rate by 1.25; if none, just set it | |
const p = this.playbackRate; | |
const ctxTime = this.context.currentTime; | |
const nowVal = p.value || 1.0; | |
p.setValueAtTime(nowVal * RATE, ctxTime); | |
} catch (_) { /* some nodes are read‑only; ignore */ } | |
return origStart.apply(this, args); | |
}; | |
} | |
/* ---------- fix elements already in the DOM ---------- */ | |
document.addEventListener('DOMContentLoaded', () => { | |
document.querySelectorAll('video,audio') | |
.forEach(m => { if (m.playbackRate !== RATE) desc.set.call(m, RATE); }); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment