Imgur Direct

See Imgur images & videos directly.

目前为 2020-12-04 提交的版本。查看 最新版本

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

QingJ © 2025

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