Greasy Fork

Greasy Fork is available in English.

视频相关

进入视频后,自动开始,自动静音,移除自动暂停,倍速播放

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         视频相关
// @include      *://*
// @version      1.1.2
// @description  进入视频后,自动开始,自动静音,移除自动暂停,倍速播放
// @author       sndcyp
// @match        *://*
// @grant        none
// @namespace    
// ==/UserScript==
$(document).ready(function () {
    // (function () {
    // 'use strict';
    window.onfocus = function () { console.log('原始事件已被替换') };
    window.onblur = function () { console.log('原始事件已被替换') };
    var tmp = setInterval(function () {
        if (player) {
            player.addListener('loadedmetadata', function () {
                player.videoPlay();
                player.videoMute();
                clearInterval(tmp);
            });
        }
    }, 500);
});
(function () {
  'use strict';
  let rate = 1
  let selectors = []
  if (/bilibili/.test(location.hostname)) {
    selectors = [
      'div.bilibili-player-video-top-title',
      'span.tit'
    ]
  } else if (/netflix/.test(location.hostname)) {
    selectors = ['.ellipsize-text h4']
  } else if (/youtube/.test(location.hostname)) {
    selectors = [
      '.ytp-title-link.yt-uix-sessionlink.ytp-title-fullerscreen-link',
      'h1 > yt-formatted-string.style-scope.ytd-video-primary-info-renderer'
    ]
  }
 
  window.addEventListener('keydown', (e) => {
    if (e.key === '`') {
      rate = 0.5
    } else {
      if ((/youtube/.test(location.hostname))) {
        if (e.key === ']' && rate < 16) {
          rate += 0.5
        } else if (e.key === '[' && rate > 0.25) {
          rate -= 0.5
        } else {
          return
        }
      } else {
        if (e.key === ']' && rate < 16) {
          rate += 0.25
        } else if (e.key === '[' && rate > 0.25) {
          rate -= 0.25
        } else if (e.key === '=' && rate < 16) {
          rate += 0.5
        } else if (e.key === '-' && rate > 0.5) {
          rate -= 0.5
        } else if (e.key === '1') {
          rate = 1
        } else if (e.key === '2') {
          rate = 2
        } else if (e.key === '3') {
          rate = 3
        } else if (e.key === '4') {
          rate = 4
        } else {
          return
        }
      }
    }
    setVideoRate()
    setVideoTitle()
  })
 
  function getTitle() {
    return selectors
             .map(selector => document.querySelector(selector))
             .filter(el => el && el.innerText)
             .map(el => el.innerText)[0]
  }
 
  function setVideoRate() {
    console.debug(`rate: ${rate}x`)
    document.querySelector('video').playbackRate = rate
  }
 
  function setVideoTitle() {
    const title = (getTitle() || '').replace(/^\[.*\] /, '')
    for (const selector of selectors) {
      const el = document.querySelector(selector)
      if (el) {
        el.innerHTML = `[${rate}x] ${title}`
      }
    }
  }
})();