Imgur auto resize

Automatically resizes imgur videos to fit the screen height

  1. // ==UserScript==
  2. // @name Imgur auto resize
  3. // @namespace https://greatest.deepsurf.us/en/scripts/434744-imgur-auto-resize
  4. // @version 1.3
  5. // @description Automatically resizes imgur videos to fit the screen height
  6. // @icon https://imgur.com/favicon.ico
  7. // @author NotJ3st3r
  8. // @license MIT
  9. // @match https://i.imgur.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. addGlobalStyle('body { overflow: hidden !important; }');
  16. try {
  17. var video = document.getElementsByTagName('video');
  18. video[0].style.height = "100vh";
  19. video[0].style.width = "auto";
  20. video[0].muted = false;
  21. setInterval(function(){
  22. if(video[0]){
  23. video[0].setAttribute("controls", "controls");
  24. }
  25. }, 100);
  26. }
  27. catch{}
  28. try {
  29. var image = document.getElementsByTagName("img");
  30. image[0].style.height = "100vh";
  31. image[0].style.width = "auto";
  32. }
  33. catch{}
  34. })();
  35.  
  36. function addGlobalStyle(css) {
  37. var head, style;
  38. head = document.getElementsByTagName('head')[0];
  39. if (!head) { return; }
  40. style = document.createElement('style');
  41. style.type = 'text/css';
  42. style.innerHTML = css;
  43. head.appendChild(style);
  44. }