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

  1. // ==UserScript==
  2. // @name Twitter HTML5 Video Error to Link
  3. // @description Replaces error message with a link to load the media in a new tab where hopefully a plugin will play it
  4. // @namespace JeffersonScher
  5. // @include https://amp.twimg.com/*
  6. // @include https://video.twimg.com/*
  7. // @include https://twitter.com/*
  8. // @include https://mobile.twitter.com/*
  9. // @version 1.3
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. var t_errcheck;
  14. t_errcheck = window.setInterval(function (){errCheck()}, 500);
  15. function errCheck(){
  16. var errdiv = document.querySelector('div.error-msg');
  17. if (errdiv){
  18. if (errdiv.textContent.indexOf("does not support video playback") > -1){
  19. window.clearInterval(t_errcheck);
  20. gotoLink();
  21. }
  22. }
  23. }
  24. var t_mp4check;
  25. t_mp4check = window.setInterval(function (){mp4Check()}, 500);
  26. function mp4Check(){
  27. var mp4v = document.querySelector('video[src*=".mp4"]');
  28. if (mp4v){
  29. window.clearInterval(t_mp4check);
  30. gotoLink();
  31. }
  32. }
  33. function gotoLink(){
  34. var vsrc = document.querySelector('video source');
  35. if (!vsrc) vsrc = document.querySelector('video[src]');
  36. if (vsrc){
  37. var t = vsrc.getAttribute("type");
  38. if (t){
  39. var mt = navigator.mimeTypes[t];
  40. if (mt === undefined || mt.enabledPlugin === null) var p = "the applicable plugin (NOT DETECTED)";
  41. else {
  42. var pn = mt.enabledPlugin.name;
  43. if (pn.toLowerCase().indexOf("plugin") < 0 && pn.toLowerCase().indexOf("plug-in") < 0) pn += " plugin";
  44. var p = "the " + pn;
  45. }
  46. } else {
  47. var p = "the applicable plugin (if any)";
  48. }
  49. 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>';
  50. } else {
  51. var ih = "SORRY! Cannot read video source.";
  52. }
  53. var pw = document.querySelector('div#playerContainer');
  54. if (!pw) pw = document.querySelector('div.MediaDetail-itemWrapper');
  55. pw.innerHTML = '<p style="color:#00f;background:#ffc">' + ih + '</p>';
  56. /* This is fail
  57. if (vsrc.getAttribute("src").indexOf('.m3u8') > -1){
  58. pw.querySelector('a').addEventListener('click', makeVLC, false);
  59. }
  60. */
  61. }
  62. /*
  63. function makeVLC(evt){
  64. // Derive target element
  65. var m3uLink = evt.target;
  66. // Create object
  67. var obj = document.createElement('object');
  68. obj.setAttribute('type', "application/x-vlc-plugin"); // not working with M3U8 content type
  69. obj.setAttribute('data', m3uLink.href);
  70. obj.setAttribute('autoplay', 'true');
  71. obj.setAttribute('style', 'width:100%; height:100%; display:block; margin-left:auto; margin-right:auto;');
  72. // Replace container
  73. document.body.innerHTML = "";
  74. document.body.appendChild(obj);
  75. // Cancel link navigation
  76. evt.preventDefault();
  77. evt.stopPropagation();
  78. return false;
  79. }
  80. */

QingJ © 2025

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