Replaces error message with a link to load the media in a new tab where hopefully a plugin will play it
当前为
// ==UserScript==
// @name Twitter HTML5 Video Error to Link
// @description Replaces error message with a link to load the media in a new tab where hopefully a plugin will play it
// @namespace JeffersonScher
// @include https://amp.twimg.com/*
// @version 1
// @grant none
// ==/UserScript==
var t_errcheck;
t_errcheck = window.setInterval(function (){errCheck()}, 500);
function errCheck(){
if (document.querySelector('div.error-msg').textContent.indexOf("does not support video playback") > -1){
window.clearInterval(t_errcheck);
gotoLink();
}
}
function gotoLink(){
var vsrc = document.querySelector('video source');
if (vsrc){
var t = vsrc.getAttribute("type");
if (t){
var mt = navigator.mimeTypes[t];
if (mt === undefined) var p = "the applicable plugin (NOT DETECTED)";
else {
var pn = mt.enabledPlugin.name;
if (pn.toLowerCase().indexOf("plugin") < 0 && pn.toLowerCase().indexOf("plug-in") < 0) pn += " plugin";
} var p = "the " + pn;
} else {
var p = "the applicable plugin (if any)";
}
var ih = 'Link to launch the media in a new tab where it should be handled by ' + p + ': <a href="' + vsrc.getAttribute("src") + '" target="_blank" style="text-decoration:underline">' + vsrc.getAttribute("src") + '</a>';
} else {
var ih = "SORRY! Cannot read video source tag.";
}
var pw = document.querySelector('div#playerContainer');
pw.innerHTML = '<p style="color:#00f;background:#ffc">' + ih + '</p>';
}