转换微信公众号图片到兼容格式

将WEBP格式图片转换到JPEG、PNG等兼容性较好的格式

  1. // ==UserScript==
  2. // @name 转换微信公众号图片到兼容格式
  3. // @description 将WEBP格式图片转换到JPEG、PNG等兼容性较好的格式
  4. // @namespace https://gf.qytechs.cn/users/197529
  5. // @version 0.6.4
  6. // @author kkocdko
  7. // @license Unlicense
  8. // @match *://mp.weixin.qq.com/*
  9. // ==/UserScript==
  10. "use strict";
  11.  
  12. const { addFloatButton } = {
  13. addFloatButton(text, onclick) /* 20220324-0950 */ {
  14. if (!document.addFloatButton) {
  15. const host = document.body.appendChild(document.createElement("div"));
  16. const root = host.attachShadow({ mode: "open" });
  17. root.innerHTML = `<style>:host{position:fixed;top:4px;left:4px;z-index:2147483647;height:0}#i{display:none}*{float:left;padding:1em;margin:4px;line-height:0;color:#fff;user-select:none;background:#28e;border:1px solid #fffa;border-radius:8px;transition:.3s}[for]~:active{background:#4af;transition:0s}:checked~*{opacity:.3;transform:translateY(-3em)}:checked+*{transform:translateY(3em)}</style><input id=i type=checkbox><label for=i>`;
  18. document.addFloatButton = (text, onclick) => {
  19. const el = document.createElement("label");
  20. el.textContent = text;
  21. el.addEventListener("click", onclick);
  22. return root.appendChild(el);
  23. };
  24. }
  25. return document.addFloatButton(text, onclick);
  26. },
  27. };
  28.  
  29. addFloatButton("转换全部图片到兼容格式", function () {
  30. document.querySelectorAll("img").forEach((el) => {
  31. const imgUrlStr = el.dataset.src || el.src;
  32. if (!imgUrlStr) return;
  33. const imgUrl = new URL(imgUrlStr);
  34. imgUrl.searchParams.set("tp", "png");
  35. const newImg = el.cloneNode();
  36. newImg.src = imgUrl.href;
  37. el.replaceWith(newImg);
  38. });
  39. this.style.background = "#4caf50";
  40. this.textContent = "全部图片都已转换完成!";
  41. });

QingJ © 2025

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