Faster Media

Set Youtube & Overcast & Youku PlaybackRate to 1.75 by default

Tính đến 20-04-2025. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Faster Media
// @namespace    http://tampermonkey.net/
// @version      0.3.0-beta.7
// @description  Set Youtube & Overcast & Youku PlaybackRate to 1.75 by default
// @author       Decradish
// @match        *www.youtube.com/watch?v=*
// @match        *overcast.fm/+*
// @grant        none
// ==/UserScript==

(function() {
	'use strict';

	// 核心方法
	var coreFn = () => {
		var iPlaybackRate = 1.75, //rate
		tmVideo = document.getElementsByTagName("video")[0],
		tmMedia = false,
		OcRange = document.getElementById('speedcontrol') //Overcast

		if(!!tmVideo){
			tmMedia = tmVideo;

			var youTubePlayBtn = document.getElementsByClassName('ytp-play-button')

			if(youTubePlayBtn.length > 0){
				document.getElementsByClassName('ytp-play-button')[0].focus()
			}
		}

		if(!!OcRange){
			OcRange.stepUp(5)
			document.getElementById('speedlabel0').style.color = '#000'
			document.getElementById('speedlabel1500').style.color = '#fff'
		}

		if(!tmMedia){
			return false;
		}

		tmMedia.playbackRate = iPlaybackRate;

		tmMedia.onplay = function(){
			tmMedia.playbackRate = iPlaybackRate;
		};

		tmMedia.oncanplay = function(){
			tmMedia.playbackRate = iPlaybackRate;
		};
	}

	// 观察器的执行函数
	var obsCb = (mutationsList, mutationObserver) => {
		// 遍历出所有的MutationRecord对象
		mutationsList.forEach(function (mutation) {
			// 找一下目标元素
			const hasTargetElem = mutation.addedNodes.some((item => 
				item.tagName === 'VIDEO' ||
				item.id === 'speedcontrol'
			));

			if(hasTargetElem){
				// 已产生目标元素,停止观察
				observer.disconnect()

				// 执行核心方法
				coreFn();
			}
		});
	}

	// 设置一个观察器
	var observer = new MutationObserver(obsCb);

	// 观察目标元素是否出现
	observer.observe(document.body, {
		childList: true,
		subtree: true
	});
})();