您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Add a 4x speed option to YouTube player.
当前为
- // ==UserScript==
- // @name YouTube 4x Speed
- // @namespace https://www.youtube.com/
- // @version 1.0
- // @description Add a 4x speed option to YouTube player.
- // @author YourName
- // @match https://www.youtube.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- function addSpeedOption() {
- const player = document.querySelector('video');
- const speedMenu = document.querySelector('.ytp-settings-menu');
- if (player && speedMenu) {
- const existingSpeeds = player.playbackRate;
- // Add the 4x speed option to the playback rate menu if it doesn't already exist
- if (!Array.from(document.querySelectorAll('.ytp-menuitem')).some(el => el.innerText.includes('4'))) {
- const speedOption = document.createElement('div');
- speedOption.className = 'ytp-menuitem';
- speedOption.setAttribute('role', 'menuitem');
- speedOption.setAttribute('aria-checked', 'false');
- speedOption.setAttribute('tabindex', '0');
- const speedLabel = document.createElement('div');
- speedLabel.className = 'ytp-menuitem-label';
- speedLabel.innerText = '4x';
- speedOption.appendChild(speedLabel);
- speedOption.addEventListener('click', function() {
- player.playbackRate = 4.0;
- closeSpeedMenu();
- });
- speedMenu.appendChild(speedOption);
- }
- }
- }
- function closeSpeedMenu() {
- // Close the YouTube settings menu
- const settingsButton = document.querySelector('.ytp-settings-button');
- settingsButton.click();
- }
- function observerCallback() {
- addSpeedOption();
- }
- // Mutation observer to ensure the script runs even after navigating to a different video
- const observer = new MutationObserver(observerCallback);
- observer.observe(document, { childList: true, subtree: true });
- })();