对于任何带有 HTML 标记的视频 (YouTube),我都有一个简单的播放速度设置器。
当我单击应该将速度更改为 2.25 的 2.25 按钮时,没有任何反应。我没有收到错误消息。
但是当我打开浏览器控制台并输入“document.querySelector('video').playbackRate = 2.25”时,视频会改变它的速度。
怎么了?
播放速度.js
browser.tabs.executeScript(
{ code: `document.getElementById('speed225').onclick = function () { document.querySelector('video').playbackRate = 2.25;
}` })
速度按钮.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="popup-content">
<div class="button" id="speed225">2.25</div>
</div>
<script src='playspeed.js'></script>
</body>
</html>
样式.css
html, body {
width: 100px;
}
.button {
margin: 3% auto;
padding: 4px;
text-align: center;
font-size: 1em;
cursor: pointer;
background-color: lightgray;
}
.button:hover {
background-color: rgb(196, 230, 196);
}
清单.json
{
"manifest_version": 2,
"name": "Video Playback Speed Controller (Menu Bar)",
"version": "1.0",
"description": "Adds buttons in the menu bar to change playback speed for HTML video tagged videos.",
"icons": {
"48": "icons/playback-icon-48.png"
},
"permissions": [
"activeTab"
],
"browser_action": {
"default_icon": "icons/playback-icon-32.png",
"default_title": "Change Video Speed",
"default_popup": "speed-buttons.html"
}
}