Imgur direct image/media page without HTML

Prevents Imgur from redirecting direct media URLs to their HTML page, keeping the correct file extension for images, GIFs and videos. Thanks to /u/american_spacey (https://www.reddit.com/r/firefox/comments/1exswyv/comment/lja7yc7/) for improvements.

  1. // ==UserScript==
  2. // @name Imgur direct image/media page without HTML
  3. // @icon https://www.google.com/s2/favicons?sz=64&domain=imgur.com
  4. // @description Prevents Imgur from redirecting direct media URLs to their HTML page, keeping the correct file extension for images, GIFs and videos. Thanks to /u/american_spacey (https://www.reddit.com/r/firefox/comments/1exswyv/comment/lja7yc7/) for improvements.
  5. // @include /^https?:\/\/imgur\.com\/[A-Za-z0-9]+$/
  6. // @include /^https?:\/\/i\.imgur\.com\/[A-Za-z0-9]+\.(jpeg|png|jpg|gif|mp4)$/
  7. // @exclude *imgur.com/vidgif
  8. // @exclude *imgur.com/jobs
  9. // @exclude *imgur.com/about
  10. // @exclude *imgur.com/apps
  11. // @exclude *imgur.com/tos
  12. // @exclude *imgur.com/privacy
  13. // @exclude *imgur.com/removalrequest
  14. // @exclude *imgur.com/advertise
  15. // @exclude *imgur.com/blog
  16. // @exclude *imgur.com/random
  17. // @exclude *imgur.com/search
  18. // @exclude *imgur.com/*.webm
  19. // @exclude *imgur.com/upload
  20. // @version 2.0
  21. // @license MIT
  22. // @grant none
  23. // @run-at document-start
  24. // @namespace https://gf.qytechs.cn/users/1355202
  25. // ==/UserScript==
  26.  
  27. const contentTypes = ["image/gif", "video/mp4", "image/jpeg", "image/png"];
  28.  
  29. const fix_page = async function () {
  30. const currentUrl = window.location.href;
  31. if (!/^https?:\/\/imgur\.com\/[A-Za-z0-9]+$/.test(currentUrl)) {return;}
  32. const imageId = currentUrl.match(/imgur\.com\/([A-Za-z0-9]+)/)[1];
  33. for (const contentType of contentTypes) {
  34. const extension = contentType.split("/")[1];
  35. const url = `https://i.imgur.com/${imageId}.${extension}`;
  36. const response = await fetch(url, {method: "HEAD"});
  37. if (response.ok && response.headers.get("content-type").split(",").includes(contentType)) {
  38. window.location.replace(url);
  39. break;
  40. }
  41. }
  42. };
  43.  
  44. fix_page();

QingJ © 2025

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