Pixiv Origin Image

Pixiv原图显示

  1. // ==UserScript==
  2. // @name Pixiv Origin Image
  3. // @name:zh-cn Pixiv 原图显示
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.3
  6. // @description Pixiv原图显示
  7. // @author Faper
  8. // @license MIT
  9. // @match http*://www.pixiv.net/*
  10. // @connect i.pximg.net
  11. // @connect i-f.pximg.net
  12. // @connect i-cf.pximg.net
  13. // @icon http://www.pixiv.net/favicon.ico
  14. // @grant none
  15. // @run-at document-end
  16. // ==/UserScript==
  17.  
  18. "use strict";
  19. (function() {
  20. const throttle = (fn, delay = 500) => {
  21. let flag = true;
  22. return (...args) => {
  23. if (!flag) return;
  24. flag = false;
  25. setTimeout(() => {
  26. fn.apply(this, args);
  27. flag = true;
  28. }, delay);
  29. };
  30. };
  31. //替换原图
  32. const originCallback = () => {
  33. let imgTags = document.querySelectorAll("a img");
  34. for(let imgTag of imgTags) {
  35. const originImg = imgTag.parentElement.href;
  36. if(/https:\/\/i.pximg.net\/img-original\/img\/[\w|\/]+\.(?:jpg|png)/g.test(originImg)) {
  37. imgTag.setAttribute("src", originImg);
  38. }
  39. }
  40. }
  41. //描述图片尺寸
  42. let sizeFig = [];
  43. const sizeCallback = () => {
  44. let imgTags = document.querySelectorAll("figure a img");
  45. for(let imgTag of imgTags) {
  46. if(sizeFig.find(x => x == imgTag) != undefined) {
  47. continue;
  48. }
  49. const height = imgTag.attributes.height.value;
  50. const width = imgTag.attributes.width.value;
  51. const span = document.createElement("span");
  52. const textNode = document.createTextNode(`${width}\u00D7${height}`);
  53. span.appendChild(textNode);
  54. imgTag.parentNode.parentNode.insertBefore(span, imgTag.parentNode);
  55. sizeFig.push(imgTag);
  56. }
  57. }
  58. const targetNode = document.querySelector("body");
  59. const config = {
  60. childList: true,
  61. subtree: true,
  62. }
  63. const originObserver = new MutationObserver(throttle(originCallback));
  64. const sizeObserver = new MutationObserver(throttle(sizeCallback));
  65. originObserver.observe(targetNode, config);
  66. sizeObserver.observe(targetNode, config);
  67. })();