t.me fix

Make t.me image savable and prevent "open with..." dialog on load

目前为 2025-02-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name t.me fix
  3. // @description Make t.me image savable and prevent "open with..." dialog on load
  4. // @namespace http://github/hafeoz
  5. // @match https://t.me/*
  6. // @match https://telegram.me/joinchat/*
  7. // @grant none
  8. // @run-at document-start
  9. //
  10. // @version 1.0.2
  11. // @author hafeoz
  12. // @icon https://telegram.org/img/website_icon.svg
  13. // @license 0BSD OR CC0-1.0 OR WTFPL
  14. // @homepageURL https://gist.github.com/hafeoz/666c8cd11a3c7be20167a3aeb3e9df7b
  15. // @supportURL https://gist.github.com/hafeoz/666c8cd11a3c7be20167a3aeb3e9df7b
  16. // ==/UserScript==
  17. for (const elem of document.getElementsByClassName("tgme_widget_message_photo_wrap")) {
  18. const src = /^url\("([^"]+)"\)$/.exec(elem.style.backgroundImage)[1];
  19. elem.style.backgroundImage = "";
  20. const imgelem = document.createElement("img");
  21. elem.appendChild(imgelem);
  22. const placeholder = elem.getElementsByClassName("tgme_widget_message_photo")[0];
  23. if (placeholder !== undefined) {
  24. imgelem.classList = placeholder.classList;
  25. placeholder.remove();
  26. }
  27. imgelem.style.width = "100%";
  28. imgelem.src = src;
  29. }
  30.  
  31. // https://caniuse.com/mdn-api_element_beforescriptexecute_event
  32. window.addEventListener("beforescriptexecute", (e) => {
  33. if (e.target.text.includes("protoUrl")) {
  34. //e.preventDefault();
  35. e.target.text = e.target.text.replace(/tg:\\\/\\\/resolve[^\"]+/, "");
  36. }
  37. });