Imgur - Page redirector

Redirects Imgur pages to images, videos or album download.

  1. // ==UserScript==
  2. // @name Imgur - Page redirector
  3. // @description Redirects Imgur pages to images, videos or album download.
  4. // @namespace var512
  5. // @author var512
  6. // @version 0.0.4
  7. // @supportURL https://gitlab.com/var512
  8. // @supportURL https://github.com/var512
  9. // @include /^https?:\/\/(i\.|www\.)?imgur\.com\/(.+)/
  10. // @exclude /^https?:\/\/(www\.)?imgur\.com\/(about|privacy|search|upload|t\/)(.*)/
  11. // @icon https://imgur.com/favicon.ico
  12. // @license MIT
  13. // @noframes
  14. // @grant none
  15. // @run-at document-end
  16. // ==/UserScript==
  17.  
  18. (() => {
  19. 'use strict';
  20.  
  21. const isDebugEnabled = false;
  22. const imgurUrl = new URL(document.URL);
  23. isDebugEnabled && console.log(`imgurUrl: ${imgurUrl}`);
  24.  
  25. if (typeof imgurUrl !== 'object') {
  26. return;
  27. }
  28.  
  29. const splitPath = imgurUrl.pathname.split('/');
  30. isDebugEnabled && console.log(`splitPath: ${splitPath} | length: ${splitPath.length}`);
  31.  
  32. if (splitPath.length < 2) {
  33. return;
  34. }
  35.  
  36. // response.status workaround
  37. const pageTitle = document.querySelector('title');
  38. const isResponseNotFound = pageTitle && pageTitle.innerText.includes('404 page');
  39. isDebugEnabled && console.log(`isResponseNotFound: ${isResponseNotFound}`);
  40.  
  41. if (isResponseNotFound) {
  42. return;
  43. }
  44.  
  45. const isDirectLink = imgurUrl.host.includes('i.imgur.com');
  46. isDebugEnabled && console.log(`isDirectLink: ${isDirectLink}`);
  47.  
  48. if (isDirectLink === true) {
  49. // .gifv URLs are redirects (not a video content-type)
  50. if (imgurUrl.href.endsWith('.gifv')) {
  51. isDebugEnabled && console.log('redirecting gifv to mp4...');
  52. window.location.replace(imgurUrl.href.replace(/.gifv$/i, '.mp4'));
  53. }
  54. return;
  55. }
  56.  
  57. window.stop();
  58.  
  59. const isGallery = ['a', 'gallery'].indexOf(splitPath[1]) >= 0 && ['zip'].indexOf(splitPath[2]) === -1;
  60. const isSingleImageGallery = document.querySelectorAll('.post-image-container').length === 1;
  61. isDebugEnabled && console.log(`isGallery: ${isGallery} | isSingleImageGallery: ${isSingleImageGallery}`);
  62.  
  63. if (isGallery && isSingleImageGallery === false) {
  64. isDebugEnabled && console.log('redirecting gallery to zip download...');
  65. window.location.replace(`https://imgur.com/a/${splitPath[2]}/zip`);
  66. return;
  67. }
  68.  
  69. const contentType = document.querySelectorAll('meta[property="og:video"]').length > 0 ? 'video' : 'image';
  70. const ogUrl = document.querySelector(`meta[property="og:${contentType}"]`).attributes.getNamedItem('content').value;
  71. const newUrl = ogUrl.split('?').shift();
  72. isDebugEnabled && console.log(`contentType: ${contentType}`);
  73. isDebugEnabled && console.log(`ogUrl: ${ogUrl}`);
  74. isDebugEnabled && console.log(`newUrl: ${newUrl}`);
  75. isDebugEnabled && console.log('redirecting...');
  76.  
  77. window.location.replace(newUrl);
  78. })();

QingJ © 2025

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