您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
Makes every YouTube video run in the highest definition
当前为
// ==UserScript== // @name YouTube HD Override // @namespace http://www.youtube.com/ // @version 2.3 // @description Makes every YouTube video run in the highest definition // @include http://*.youtube.com/* // @include https://*.youtube.com/* // @exclude http://apiblog.youtube.com/* // @exclude https://apiblog.youtube.com/* // @run-at document-end // @copyright Prehistoricman Inc. 2015 // ==/UserScript== console.log("YouTube HD Override loaded") var CurrentVersion = 2.3 HDOSettings = {} if (localStorage.HDOLastUpdate == undefined | (localStorage.HDOLastUpdate < CurrentVersion)) { //Old stats, reset all HDOSettings.HD = true HDOSettings.VideoAutoPlay = false HDOSettings.ChannelAutoPlay = false HDOSettings.DASHPlayback = false HDOSettings.PauseInvisible = true localStorage.HDOverride = JSON.stringify(HDOSettings) localStorage.HDOLastUpdate = CurrentVersion } else { HDOSettings = JSON.parse(localStorage.HDOverride) } function SaveHDOSettings() { localStorage.HDOverride = JSON.stringify(HDOSettings) } var LastUrl = "" var LastHREF = "" var Debugging = false if (Debugging) { console.trace() } function Print(output) { //It would be immoral to spam others' consoles. if (Debugging) { console.log(output) } } function DetectPageType() { if (location.href.substring(0, 31) == "https://www.youtube.com/channel" | location.href.substring(0, 31) == "http://www.youtube.com/channel/" | location.href.substring(0, 28) == "https://www.youtube.com/user" | location.href.substring(0, 28) == "http://www.youtube.com/user/") { return "channel" } else if (location.href.substring(0, 29) == "https://www.youtube.com/watch" | location.href.substring(0, 29) == "http://www.youtube.com/watch?") { return "video" } else { return "else" } } function GetVideoElement() { if (DetectPageType() == "video") { return document.getElementById("movie_player") } else if (DetectPageType() == "channel") { return document.getElementById("c4-player") } else { return "nope" } } function PauseChannelVideo() { var PauseInterval = setInterval(function () { var ChannelPlayer = document.getElementById("c4-player") if (document.getElementById("c4-player")) { ChannelPlayer.pauseVideo() Print("Paused channel video") if (document.getElementById("c4-player").getPlayerState() == 2) { clearInterval(PauseInterval) Print("Pause interval stopped") } } else { Print("Channel player not found yet") } }, 30) } function SetHD() { var HDInterval = setInterval(function () { var OverridePlayer = document.getElementById("movie_player") if (OverridePlayer) { if (OverridePlayer.setPlaybackQuality) { OverridePlayer.setPlaybackQuality(OverridePlayer.getAvailableQualityLevels()[0]) Print("HD'd video") Print(document.visibilityState) if (HDOSettings.PauseInvisible && document.visibilityState && document.visibilityState != "visible") { //A non-prefixed property on document? Is this the future?????? OverridePlayer.pauseVideo() Print("Paused inactive tab") } if (!HDOSettings.DASHPlayback && ytplayer && ytplayer.config && ytplayer.config.args) { ytplayer.config.args.dash = "0" ytplayer.config.args.dashmpd = "" Print("Set DASH") } else if (!HDOSettings.DASHPlayback) { //if we can't find ytplayer Print("DASH set failed") } Print("Set quality") } if (OverridePlayer.getPlaybackQuality() == OverridePlayer.getAvailableQualityLevels()[0]) { clearInterval(HDInterval) Print("Quality interval stopped") } else { Print("check fail") Print(OverridePlayer.getPlaybackQuality()) Print(OverridePlayer.getAvailableQualityLevels()[0]) } } else { Print("Player not found yet") } }, 30) } function ApplyFixes() { Print("ApplyFixes at " + location.href) if (DetectPageType() == "channel") { if (!HDOSettings.ChannelAutoPlay) { //Everybody hates this shit PauseChannelVideo() //Pause video on channel pages } } else if (HDOSettings.HD & DetectPageType() == "video") { SetHD() //Set HD on video pages } else { Print("Who knows???") Print(location.href) Print(HDOSettings) } } if (GetVideoElement() && GetVideoElement() != "nope" && GetVideoElement().getVideoUrl() != LastUrl) { ApplyFixes() } setInterval(function () { if (location.href != LastHREF) { //href has changed LastHREF = location.href Print("Href change") var count = 0 var ApplyInterval = setInterval(function () { //Waits for a new player to load count++ Print("Apply interval for " + ApplyInterval) var getvid = GetVideoElement() if (getvid && getvid != "nope" && getvid.getVideoUrl() != LastUrl) { Print("applyinterval check pass for " + ApplyInterval) LastUrl = getvid.getVideoUrl() LastHREF = location.href ApplyFixes() clearInterval(ApplyInterval) } else if (getvid == "nope") { Print(getvid) LastUrl = "" Print("stopped on main page") clearInterval(ApplyInterval) } if (count > 70) { clearInterval(ApplyInterval) //No freaking excuses LastUrl = "" Print("stopped on timeout") } }, 30) } }, 200) setInterval(function () { var mov = document.getElementById("movie_player") if (!HDOSettings.VideoAutoPlay && mov && mov.setAutonavState) { mov.setAutonavState(1) //Disable auto-nav } }, 1000)