Imgur Direct

See Imgur images & videos directly.

  1. // ==UserScript==
  2. //
  3. // @name Imgur Direct
  4. // @version 1.3
  5. // @namespace https://gf.qytechs.cn/en/users/667743-catspinner
  6. // @description See Imgur images & videos directly.
  7. // @icon https://imgur.com/favicon.ico
  8. // @license MIT
  9. //
  10. //
  11. // @include /^https://imgur\.com/[a-zA-Z0-9]{5,8}$/
  12. // @exclude https://imgur.com/gallery
  13. // @exclude https://imgur.com/upload
  14. //
  15. // @run-at document-start
  16. //
  17. // ==/UserScript==
  18. //
  19. /*========================= Version History ==================================
  20.  
  21. 1.00 - First public release.
  22.  
  23. 1.1 - Fixed Imgur's jpg/jpeg shenanigans.
  24. Shows images faster.
  25. Strict @include rule to define where script can run.
  26.  
  27. 1.2 - Fixed a typo in @include regex.
  28.  
  29. 1.3 - Just some meta changes.
  30.  
  31. ==============================================================================*/
  32.  
  33.  
  34. function runImgurDirect() {
  35. const imgname = location.href.replace('https://imgur.com/', 'https://i.imgur.com/'),
  36. imgname_jpeg = imgname + '.jpeg',
  37. imgname_jpg = imgname + '.jpg',
  38. imgname_png = imgname + '.png',
  39. imgname_gif = imgname + '.gif',
  40. imgname_mp4 = imgname + '.mp4',
  41. imgname_gifv = imgname + '.gifv';
  42.  
  43. const url = location.href;
  44. const xhr = new XMLHttpRequest();
  45. xhr.open('GET', url);
  46. xhr.responseType = 'text';
  47. xhr.send();
  48. xhr.onload = function() {
  49. const page = xhr.response;
  50. var video = true;
  51. var trueimage = location.href;
  52.  
  53. if (page.indexOf("og:video") == -1) {
  54. video = false;
  55. } if (page.indexOf(imgname_png) > -1) {
  56. trueimage = imgname_png;
  57. } else if (page.indexOf(imgname_jpeg) > -1) {
  58. trueimage = imgname_jpeg;
  59. } else if (page.indexOf(imgname_jpg) > -1) {
  60. trueimage = imgname_jpg;
  61. }
  62.  
  63. if (video) {
  64. if (countOccurrence(page, imgname_gif) > 2) {
  65. trueimage = imgname_gif;
  66. } else if (countOccurrence(page, imgname_mp4) > 2) {
  67. trueimage = imgname_mp4;
  68. } else if (countOccurrence(page, imgname_gifv) > 2) {
  69. trueimage = imgname_gifv;
  70. }
  71. }
  72.  
  73. if (url !== trueimage) {
  74. window.location.replace(trueimage);
  75. } else {
  76. return;
  77. }
  78. }
  79. }
  80.  
  81. function countOccurrence(string, subString) {
  82. var n = 0,
  83. pos = 0,
  84. step = subString.length;
  85.  
  86. while (true) {
  87. pos = string.indexOf(subString, pos);
  88. if (pos >= 0) {
  89. ++n;
  90. pos += step;
  91. } else break;
  92. }
  93. return n;
  94. }
  95.  
  96. runImgurDirect();

QingJ © 2025

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