BetterDiscordApp-rauenzi/Plugins/mediaSupport.plugin.js

61 lines
1.8 KiB
JavaScript
Raw Normal View History

//META{"name":"mediaSupport"}*//
var mediaSupport = function () {};
mediaSupport.prototype.convert = function () {
$(".message a").each(function() {
var t = $(this);
var href = t.attr("href");
if(href == undefined) return true;
href = href.replace("http:", "https:");
if(!href.endsWith(".mp4") && !href.endsWith(".webm") && !href.endsWith(".ogg") && !href.endsWith(".mp3") && !href.endsWith(".wav")) return true;
var video = true;
var type = "webm";
if(href.endsWith(".mp4")) type = "mp4";
if(href.endsWith(".ogg")) type = "ogg";
if(href.endsWith(".mp3")) {
type = "mpeg";
video = false;
}
if(href.endsWith(".wav")) {
type = "wav";
video = false;
}
if(video) {
2016-08-11 16:30:27 +02:00
t.replaceWith('<video width="480" height="320" src="'+encodeURI(href)+'" type="video/'+type+'" controls></video>');
} else {
2016-08-11 16:30:27 +02:00
t.replaceWith('<audio src="'+encodeURI(href)+'" type="audio/'+type+'" controls></audio>');
}
});
};
mediaSupport.prototype.onMessage = function () {
setTimeout(this.convert(), 2000);
};
mediaSupport.prototype.onSwitch = function () {
this.convert();
};
mediaSupport.prototype.start = function () {
this.convert();
};
mediaSupport.prototype.load = function () {};
mediaSupport.prototype.unload = function () {};
mediaSupport.prototype.stop = function () {};
mediaSupport.prototype.getSettingsPanel = function () {
return "";
};
mediaSupport.prototype.getName = function () {
2016-03-30 03:44:38 +02:00
return "Media Support";
};
mediaSupport.prototype.getDescription = function () {
2016-03-30 03:44:38 +02:00
return "Add support for html5 media";
};
mediaSupport.prototype.getVersion = function () {
return "0.1.0";
};
mediaSupport.prototype.getAuthor = function () {
return "Jiiks";
};