Imgur - Page redirector

Redirects Imgur pages to images, videos or album download.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

作者のサイトでサポートを受ける。または、このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Imgur - Page redirector
// @description  Redirects Imgur pages to images, videos or album download.
// @namespace    var512
// @author       var512
// @version      0.0.4
// @supportURL   https://gitlab.com/var512
// @supportURL   https://github.com/var512
// @include      /^https?:\/\/(i\.|www\.)?imgur\.com\/(.+)/
// @exclude      /^https?:\/\/(www\.)?imgur\.com\/(about|privacy|search|upload|t\/)(.*)/
// @icon         https://imgur.com/favicon.ico
// @license      MIT
// @noframes
// @grant        none
// @run-at       document-end
// ==/UserScript==

(() => {
  'use strict';

  const isDebugEnabled = false;
  const imgurUrl = new URL(document.URL);
  isDebugEnabled && console.log(`imgurUrl: ${imgurUrl}`);

  if (typeof imgurUrl !== 'object') {
    return;
  }

  const splitPath = imgurUrl.pathname.split('/');
  isDebugEnabled && console.log(`splitPath: ${splitPath} | length: ${splitPath.length}`);

  if (splitPath.length < 2) {
    return;
  }

  // response.status workaround
  const pageTitle = document.querySelector('title');
  const isResponseNotFound = pageTitle && pageTitle.innerText.includes('404 page');
  isDebugEnabled && console.log(`isResponseNotFound: ${isResponseNotFound}`);

  if (isResponseNotFound) {
    return;
  }

  const isDirectLink = imgurUrl.host.includes('i.imgur.com');
  isDebugEnabled && console.log(`isDirectLink: ${isDirectLink}`);

  if (isDirectLink === true) {
    // .gifv URLs are redirects (not a video content-type)
    if (imgurUrl.href.endsWith('.gifv')) {
      isDebugEnabled && console.log('redirecting gifv to mp4...');
      window.location.replace(imgurUrl.href.replace(/.gifv$/i, '.mp4'));
    }
    return;
  }

  window.stop();

  const isGallery = ['a', 'gallery'].indexOf(splitPath[1]) >= 0 && ['zip'].indexOf(splitPath[2]) === -1;
  const isSingleImageGallery = document.querySelectorAll('.post-image-container').length === 1;
  isDebugEnabled && console.log(`isGallery: ${isGallery} | isSingleImageGallery: ${isSingleImageGallery}`);

  if (isGallery && isSingleImageGallery === false) {
    isDebugEnabled && console.log('redirecting gallery to zip download...');
    window.location.replace(`https://imgur.com/a/${splitPath[2]}/zip`);
    return;
  }

  const contentType = document.querySelectorAll('meta[property="og:video"]').length > 0 ? 'video' : 'image';
  const ogUrl = document.querySelector(`meta[property="og:${contentType}"]`).attributes.getNamedItem('content').value;
  const newUrl = ogUrl.split('?').shift();
  isDebugEnabled && console.log(`contentType: ${contentType}`);
  isDebugEnabled && console.log(`ogUrl: ${ogUrl}`);
  isDebugEnabled && console.log(`newUrl: ${newUrl}`);
  isDebugEnabled && console.log('redirecting...');

  window.location.replace(newUrl);
})();