Imgur Mirror

Switches all imgur links to the mirror site http://kageurufu.net/imgur

  1. // ==UserScript==
  2. // @name Imgur Mirror
  3. // @namespace https://github.com/jhxxs
  4. // @version 0.0.1
  5. // @description Switches all imgur links to the mirror site http://kageurufu.net/imgur
  6. // @author Kyle
  7. // @include http*
  8. // @require https://cdn.jsdelivr.net/gh/fuzetsu/userscripts@ec863aa92cea78a20431f92e80ac0e93262136df/wait-for-elements/wait-for-elements.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (() => {
  13. 'use strict';
  14.  
  15.  
  16. let is_add = false;
  17. const regex =
  18. /imgur\.com\/(?!a\/|gallery\/)(?:r\/[a-z0-9_]+\/)?([a-z0-9]+)(\.+[a-z0-9]+)?/iu;
  19. const extensions = [
  20. '.jpg',
  21. '.jpeg',
  22. '.png',
  23. '.gif',
  24. '.gifv',
  25. '.webm',
  26. '.mp4'
  27. ];
  28.  
  29. const getNewLink = function (imgurLink, useGif) {
  30. const match = imgurLink.match(regex);
  31. if (match) {
  32. const file = match[1];
  33. let extension = match[2].toLowerCase();
  34. if (!extension || !extensions.includes(extension)) {
  35. extension = '.png';
  36. } else if (
  37. extension === '.gifv' ||
  38. extension === '.gif' ||
  39. extension === '.webm'
  40. ) {
  41. extension = '.mp4';
  42. }
  43. if (useGif && extension === '.mp4') {
  44. extension = '.gif';
  45. }
  46. return `http://kageurufu.net/imgur/?${file + extension}`;
  47. } else {
  48. return null;
  49. }
  50. };
  51.  
  52. waitForElems({
  53. sel: 'img,a',
  54. onmatch(node) {
  55. const isImg = node.nodeName === 'IMG';
  56. const prop = isImg ? 'src' : 'href';
  57. const newLink = getNewLink(node[prop], isImg);
  58. if (newLink) {
  59. if(!is_add){
  60. const meta = document.createElement('meta');
  61. meta.setAttribute('name', 'referrer');
  62. meta.setAttribute('content', 'no-referrer');
  63. document.getElementsByTagName('head')[0].appendChild(meta);
  64. is_add = true;
  65. }
  66. node[prop] = newLink;
  67. if (node.dataset.hrefUrl) {
  68. node.dataset.hrefUrl = newLink;
  69. }
  70. if (node.dataset.outboundUrl) {
  71. node.dataset.outboundUrl = newLink;
  72. }
  73. }
  74. }
  75. });
  76. })();

QingJ © 2025

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