Embed to HTML5

Replaces media embed tags with HTML5 equivalents

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

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

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          Embed to HTML5
// @namespace     DoomTay
// @description   Replaces media embed tags with HTML5 equivalents
// @include       *
// @version       1.1.2
// @exclude       *.svg
// @grant         none

// ==/UserScript==

var embeds = document.embeds;

var audioFiletypes = [".mp3",".wav",".ogg"];
var videoFiletypes = [".mp4"];

var bgsound = document.querySelector("bgsound");
if(bgsound && audioFiletypes.some(type => decodeURIComponent(bgsound.getAttribute("src")).includes(type)))
{
	var replacement = document.createElement("audio");
	replacement.src = decodeURIComponent(bgsound.getAttribute("src"));
	replacement.style.display = "none";
	replacement.loop = parseBool(bgsound.getAttribute("loop")) || bgsound.getAttribute("loop") == "-1" || bgsound.getAttribute("loop") == "infinite";
	replacement.autoplay = "true";
	bgsound.parentNode.replaceChild(replacement, bgsound);

	if(bgsound.getAttribute("loop") && bgsound.getAttribute("loop") != "infinite" && parseInt(bgsound.getAttribute("loop")) > 0)
	{
		var playCount = parseInt(bgsound.getAttribute("loop")) - 1;

		replacement.addEventListener('ended', function(){
			if(playCount > 0)
			{
				playCount--;
				replacement.play();
			}
		});
	}
}

if(embeds.length > 0)
{
	for(var e = embeds.length - 1; e >= 0; e--)
	{
		if(audioFiletypes.some(type => embeds[e].src.includes(type))) var replacement = document.createElement("audio");
		else if(videoFiletypes.some(type => embeds[e].src.includes(type))) var replacement = document.createElement("video");
		else continue;
		replacement.src = decodeURIComponent(embeds[e].src);
		replacement.width = embeds[e].width;
		replacement.height = embeds[e].height;
		if(embeds[e].hidden) replacement.style.display = "none";
		replacement.autoplay = parseBool(embeds[e].getAttribute("autostart") || embeds[e].getAttribute("autoplay")) || audioFiletypes.some(elem => window.location.href.includes(elem));
		replacement.controls = parseBool(embeds[e].getAttribute("controller"));
		replacement.loop = parseBool(embeds[e].getAttribute("loop"));
		var oldEmbed;
		if(embeds[e].parentNode.nodeName == "OBJECT")
		{
			oldEmbed = embeds[e].parentNode.parentNode.replaceChild(replacement, embeds[e].parentNode);
		}
		else
		{
			oldEmbed = embeds[e].parentNode.replaceChild(replacement, embeds[e]);
		}
		if(oldEmbed.name)
		{
			replacement.setAttribute("name", oldEmbed.name);
			document[replacement.getAttribute("name")] = replacement;
		}
	}
}

function getBitrate(media)
{
	console.log(media);
	return 44;
}

function parseBool(string)
{
	return string == "true";
}