Embed to HTML5

Replaces media embed tags with HTML5 equivalents

اعتبارا من 24-01-2016. شاهد أحدث إصدار.

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

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 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.

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

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name          Embed to HTML5
// @namespace     DoomTay
// @description   Replaces media embed tags with HTML5 equivalents
// @version       1.0.1
// @grant         none

// ==/UserScript==

var embeds = document.embeds;

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

for(var e = embeds.length - 1; e >= 0; e--)
{
	if(audioFiletypes.some(elem => embeds[e].src.indexOf(elem) > -1)) var replacement = document.createElement("audio");
	else if(videoFiletypes.some(elem => embeds[e].src.indexOf(elem) > -1)) var replacement = document.createElement("video");
	else continue;
	replacement.src = 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.indexOf(elem) > -1);
	replacement.controls = true;
	replacement.loop = parseBool(embeds[e].getAttribute("loop"));
	if(embeds[e].parentNode.nodeName == "OBJECT")
	{
		embeds[e].parentNode.parentNode.insertBefore(replacement,embeds[e].parentNode);
		embeds[e].parentNode.parentNode.removeChild(embeds[e].parentNode);
	}
	else
	{
		embeds[e].parentNode.insertBefore(replacement,embeds[e]);
		embeds[e].parentNode.removeChild(embeds[e]);
	}
}

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