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

目前为 2016-03-01 提交的版本。查看 最新版本

// ==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/*
// @include     https://twitter.com/*
// @version     1.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>';
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址