gpt4 book ai didi

javascript - 达到 3 分钟后从 chrome 控制台暂停 YouTube 视频

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:56:59 24 4
gpt4 key购买 nike

我可以暂停视频globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0].pause()

我可以使用 globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0].currentTime 获取视频的当前时间

如何在视频到达 currentTime > 180 时自动触发暂停?

最佳答案

一种简单的方法是轮询。

const player = globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0]
setTimeout(function polling() {
if (player.currentTime < 180)
setTimeout(polling, 1000)
else
player.pause()
}, 1000)

另一种方式:

const player = globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0]
const timer = setInterval(() => { // no need of named function as no 'async recursion' is needed
if (player.currentTime >= 180) {
player.pause()
clearInterval(timer)
}
}, 1000)

关于javascript - 达到 3 分钟后从 chrome 控制台暂停 YouTube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53933106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com