Twitter HTML5 Video Error to Link

Replaces error message with a link to load the media in a new tab where hopefully a plugin will play it

Fra 14.09.2015. Se den seneste versjonen.

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

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install 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>';
}