Greasy Fork

Greasy Fork is available in English.

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.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Imgur direct image/media page without HTML
// @icon        https://www.google.com/s2/favicons?sz=64&domain=imgur.com
// @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.
// @include     /^https?:\/\/imgur\.com\/[A-Za-z0-9]+$/
// @include     /^https?:\/\/i\.imgur\.com\/[A-Za-z0-9]+\.(jpeg|png|jpg|gif|mp4)$/
// @exclude     *imgur.com/vidgif
// @exclude     *imgur.com/jobs
// @exclude     *imgur.com/about
// @exclude     *imgur.com/apps
// @exclude     *imgur.com/tos
// @exclude     *imgur.com/privacy
// @exclude     *imgur.com/removalrequest
// @exclude     *imgur.com/advertise
// @exclude     *imgur.com/blog
// @exclude     *imgur.com/random
// @exclude     *imgur.com/search
// @exclude     *imgur.com/*.webm
// @exclude     *imgur.com/upload
// @version     2.0
// @license     MIT
// @grant       none
// @run-at      document-start
// @namespace http://greasyfork.icu/users/1355202
// ==/UserScript==

const contentTypes = ["image/gif", "video/mp4", "image/jpeg", "image/png"];

const fix_page = async function () {
  const currentUrl = window.location.href;
  if (!/^https?:\/\/imgur\.com\/[A-Za-z0-9]+$/.test(currentUrl)) {return;}
  const imageId = currentUrl.match(/imgur\.com\/([A-Za-z0-9]+)/)[1];
  for (const contentType of contentTypes) {
    const extension = contentType.split("/")[1];
    const url = `https://i.imgur.com/${imageId}.${extension}`;
    const response = await fetch(url, {method: "HEAD"});
    if (response.ok && response.headers.get("content-type").split(",").includes(contentType)) {
      window.location.replace(url);
      break;
    }
  }
};

fix_page();