t.me fix

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

  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.1.0
  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. window.onload = function() {
  18. for (const elem of document.getElementsByClassName("tgme_widget_message_photo_wrap")) {
  19. const src = /^url\("([^"]+)"\)$/.exec(elem.style.backgroundImage)[1];
  20. elem.style.backgroundImage = "";
  21. const imgelem = document.createElement("img");
  22. elem.appendChild(imgelem);
  23. const placeholder = elem.getElementsByClassName("tgme_widget_message_photo")[0];
  24. if (placeholder !== undefined) {
  25. imgelem.classList = placeholder.classList;
  26. placeholder.remove();
  27. }
  28. imgelem.style.width = "100%";
  29. imgelem.src = src;
  30. }
  31. }
  32.  
  33. // https://caniuse.com/mdn-api_element_beforescriptexecute_event
  34. window.addEventListener("beforescriptexecute", (e) => {
  35. if (e.target.text.includes("protoUrl")) {
  36. //e.preventDefault();
  37. e.target.text = e.target.text.replace(/tg:\\\/\\\/resolve[^\"]+/, "");
  38. }
  39. });