Greasy Fork

Greasy Fork is available in English.

Anime News Network HTML5 Video

Replaces built-in Flash player with HTML5

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Anime News Network HTML5 Video
// @namespace   DoomTay
// @description Replaces built-in Flash player with HTML5
// @include     https://www.animenewsnetwork.com/video/*
// @version     0.5.1
// @grant       none
// @run-at      document-start
// ==/UserScript==

var observer = new MutationObserver(function(mutations) {
	mutations.forEach(function(mutation) {
		mutation.addedNodes.forEach(findVideoScript);
	});
});

var config = { childList: true, subtree: true };
observer.observe(document, config);

for(var i = 0; i < document.scripts.length; i++)
{
	findVideoScript(document.scripts[i]);
}

function findVideoScript(start)
{
	if(start.nodeName == "SCRIPT" && start.src.includes("assets/bd277df0dd3412fa7734d08320ecbe1cd9089168.js"))
	{
		observer.disconnect();

		start.on("load",function()
		{
			var oldInit = window.Video.init_player;

			window.Video.init_player = function(vid)
			{
				if(vid.flashvars["GetVideo"])
				{
					this.init_player = null;
					this.initialized = true;

					$("flash-required-message").hide();

					jQuery.get(vid.flashvars["GetVideo"],function(data)
					{
						var newVideo = document.createElement("video");
						newVideo.width = 480;
						newVideo.height = 360;
						newVideo.controls = true;
						newVideo.src = data.querySelector("flv bitrate").textContent;
						newVideo.autoplay = document.location.hash == "#play-1";
						newVideo.poster = data.querySelector("Still").textContent;

						$("video-player-area").append(newVideo);
					})
				}
				else if(vid.flash.movie && (vid.flash.movie.includes("youtube") || vid.flash.movie.includes("hulu")))
				{
					//A proper replacement of Hulu's embed might not be possible, as their HTML5 embed URL is too different from the Flash one
					vid.flash.movie = vid.flash.movie.replace("http:","https:");

					window.UFO.pluginType = "npapi";

					window.UFO.hasFlashVersion = function(major, release) {
						if(major == 9 && release == 115) return true;
						else return (UFO.fv[0] > major || (UFO.fv[0] == major && UFO.fv[1] >= release));
					}

					oldInit.apply(this, arguments);
				}
				else oldInit.apply(this, arguments);
			}
		});
	}
}