你正在訪問的內容是外部程式的映像位址,僅用於使用者加速訪問,本站無法保證其可靠性。當前的連結位址(單點即可複製)為 https://greasyfork.org.cn/zh-CN/scripts/30506-video-speed-buttons/discussions/236749,源站連結 點此以跳轉。
Add speed buttons to any HTML5 <video> element. Comes with a loader for YouTube and Vimeo
What I ended up doing was change the speed changing function to edit a data structure containing a reference to the video element and the current speed. An independent loop called the "enforcer" then uses this data structure to update the video speed on an interval (currently 500ms).
It's not perfect. Sometimes on youtube, the loop will just break (I suspect youtube is replacing the video element with a new one). However, this only happens after the page has been open for a long time. A lot of things on youtube break over this (it's a shockingly unstable UI), and the solution is to simply refresh the page.
This script is over-engineered anyway. I could have accomplished the buttons using a simple array instead of a linked list, for example. I'm considering doing a more extensive update in the future, but I don't have the time for it now. For now, it works and is not annoying to use.
I encountered some sites where the player would reset the speed automatically about one second after setting a new speed using this script:
while it doesn't perfectly, i added this code to ensure persistence, in the ev_keyboard function, just before the return part.:
---- start of existing code
setPlaybackRate(video_el, DEFAULT_SPEED);
anchor.insertBefore(container, anchor.firstChild);
document.body.addEventListener("keydown", ev_keyboard);
---- end of existing code
---- new code
setInterval(() => {
if(video_el && video_el.playbackRate !== buttons.selected.speed) {
video_el.playbackRate = buttons.selected.speed;
}
}, 250);
---- end of new code
(return code below)
Dunno if anyone can improve on that, but probably you can. thanks