Faster Media

Set Youtube & Overcast PlaybackRate to 1.75 by default

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Faster Media
// @namespace    http://tampermonkey.net/
// @version      0.3.0
// @description  Set Youtube & Overcast 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){
			obsFn()
			return false;
		}

		tmMedia.playbackRate = iPlaybackRate;

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

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

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

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

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

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

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

	// 触发核心逻辑
	coreFn();
})();