Last active
March 29, 2025 10:40
-
-
Save yukulele/805c382f371852e8f25efd7b2ec5876a to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name twitter native video player | |
// @match https://twitter.com/* | |
// @grant none | |
// @version 1.0 | |
// @author yukulele | |
// @description replace not user-friendly twitter player with native browser player. This allow to: seek with left/right keyboard keys change volume with up/down keyboard keys, fullscreen with double-click, change playback rate (via context menu), share playback rate between videos. | |
// @inject-into auto | |
// ==/UserScript== | |
function nativePlayer(video) { | |
video.playbackRate = window.localStorage.playbackRate || 1 | |
video.addEventListener('ratechange', () => window.localStorage.playbackRate = video.playbackRate) | |
video.addEventListener('mouseenter', () => video.controls = true) | |
video.addEventListener('mouseleave', () => video.controls = false) | |
video.style.zIndex = 1 | |
} | |
const mutationObserver = new MutationObserver(mutationsList => { | |
for (var mutation of mutationsList) { | |
if (mutation.type !== 'childList') return | |
for (const node of mutation.addedNodes) { | |
if (!(node instanceof HTMLElement)) continue | |
for (const video of node.querySelectorAll('video')) nativePlayer(video) | |
} | |
} | |
}) | |
mutationObserver.observe(document.documentElement, { | |
childList: true, | |
subtree: true, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment