Greasy Fork

Greasy Fork is available in English.

t.me fix

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

当前为 2025-02-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        t.me fix
// @description Make t.me image savable and prevent "open with..." dialog on load
// @namespace   http://github/hafeoz
// @match       https://t.me/*
// @match       https://telegram.me/joinchat/*
// @grant       none
// @run-at      document-start
//
// @version     1.0.1
// @author      hafeoz
// @icon        https://telegram.org/img/website_icon.svg
// @license     0BSD OR CC0-1.0 OR WTFPL
// @homepageURL https://gist.github.com/hafeoz/666c8cd11a3c7be20167a3aeb3e9df7b
// @supportURL  https://gist.github.com/hafeoz/666c8cd11a3c7be20167a3aeb3e9df7b
//
// @incompatible chrome unable to prevent "open with..." dialog
// @incompatible opera unable to prevent "open with..." dialog
// @incompatible safari unable to prevent "open with..." dialog
// @incompatible edge unable to prevent "open with..." dialog
// ==/UserScript==
for (const elem of document.getElementsByClassName("tgme_widget_message_photo_wrap")) {
    const src = /^url\("([^"]+)"\)$/.exec(elem.style.backgroundImage)[1];
    elem.style.backgroundImage = "";
    const imgelem = document.createElement("img");
    elem.appendChild(imgelem);
    const placeholder = elem.getElementsByClassName("tgme_widget_message_photo")[0];
    if (placeholder !== undefined) {
        imgelem.classList = placeholder.classList;
        placeholder.remove();
    }
    imgelem.style.width = "100%";
    imgelem.src = src;
}

// https://caniuse.com/mdn-api_element_beforescriptexecute_event
window.addEventListener("beforescriptexecute", (e) => {
    if (e.target.text.includes("protoUrl")) {
        //e.preventDefault();
        e.target.text = e.target.text.replace(/tg:\\\/\\\/resolve[^\"]+/, "");
    }
});