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

Από την 14/09/2015. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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>';
}