YouTube Speed Booster х2 on/off

Добавляет кнопку для включения/выключения изменения скорости воспроизведения на YouTube

当前为 2024-10-31 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        YouTube Speed Booster х2 on/off
// @namespace   Violentmonkey Scripts
// @match       *://www.youtube.com/*
// @grant       none
// @version     1.3
// @author      -
// @description Добавляет кнопку для включения/выключения изменения скорости воспроизведения на YouTube
// @license
// @license MIT
// ==/UserScript==

let speedEnabled = localStorage.getItem('speedEnabled') === 'true';
const speedButton = document.createElement('button');

function setPlaybackSpeed() {
  const video = document.querySelector('video');
  if (video && speedEnabled) {
    video.playbackRate = 2.0; // Устанавливаем желаемую скорость воспроизведения
  }
}

function toggleSpeed() {
  speedEnabled = !speedEnabled;
  localStorage.setItem('speedEnabled', speedEnabled);
  speedButton.textContent = speedEnabled ? 'Скорость x2 ВКЛ' : 'Скорость x2 ВЫКЛ';

  if (speedEnabled) {
    setPlaybackSpeed(); // Устанавливаем скорость воспроизведения, если включено
  }
}

// Создаем кнопку
speedButton.textContent = speedEnabled ? 'Скорость х2 ВКЛ' : 'Скорость х2 ВЫКЛ';
speedButton.title = 'Расширение запускается при загрузке видео. Обновите страницу для получения результата.';
speedButton.style.position = 'fixed';
speedButton.style.top = '12px'; // Настройте позицию по необходимости
speedButton.style.right = '240px'; // Настройте позицию по необходимости
speedButton.style.zIndex = '9999';
speedButton.style.padding = '10px 10px';
speedButton.style.backgroundColor = '#ff0000';
speedButton.style.color = '#ffffff';
speedButton.style.border = 'none';
speedButton.style.borderRadius = '5px';
speedButton.style.cursor = 'pointer';

// Добавляем кнопку в YouTube
document.body.appendChild(speedButton);
speedButton.addEventListener('click', toggleSpeed);

window.addEventListener('load', () => {
  if (speedEnabled) {
    setPlaybackSpeed();
  }
});

document.addEventListener('fullscreenchange', () => {
  if (document.fullscreenElement) {
    speedButton.style.display = 'none'; // Скрываем кнопку в полноэкранном режиме
  } else {
    speedButton.style.display = 'block'; // Показываем кнопку при выходе из полноэкранного режима
  }
});

const observer = new MutationObserver(setPlaybackSpeed);
observer.observe(document.body, { childList: true, subtree: true });