Inline Media Player (HTML5)

Watch video/audio URLs right on the page instead of downloading them!

  1. // ==UserScript==
  2. // @name Inline Media Player (HTML5)
  3. // @namespace gfish
  4. // @author gfish
  5. // @version 1.0
  6. // @description Watch video/audio URLs right on the page instead of downloading them!
  7. // @license MIT
  8. // @match *://*/*
  9. // @grant none
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. const VIDEO_EXTENSIONS = ['mp4', 'm4v', 'mov', 'avi', 'mpeg', 'wmv', 'mov']
  15. const AUDIO_EXTENSIONS = ['mp3', 'wav', 'm4a', 'ogg', 'aac', 'flac']
  16. let inv = setInterval(() => {
  17. if (document.links.length > 0) {
  18. clearInterval(inv);
  19. Object.values(document.links).forEach(s => {
  20. let ext = s.href.split('.').pop().toLowerCase().split('?').shift();
  21. if (VIDEO_EXTENSIONS.includes(ext)) {
  22. let frame = document.createElement("span");
  23. frame.innerHTML = `<br><video controls="" loop preload="metadata" style="max-width: 100%; max-height: 100vh;" ><source src="${s.href}"></source></video>`;
  24. s.parentNode.insertBefore(frame, s.nextSibling);
  25. }
  26. else if (AUDIO_EXTENSIONS.includes(ext)) {
  27. let frame = document.createElement("span");
  28. frame.innerHTML = `<br><audio controls="" loop preload="metadata" style="width: 100%;" ><source src="${s.href}"></source></audio>`;
  29. s.parentNode.insertBefore(frame, s.nextSibling);
  30. }
  31. })
  32. }
  33. }, 100)
  34. })();