Telegram-Web Image Display Switch

none

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Telegram-Web Image Display Switch
// @namespace   [email protected]
// @description none
// @include     https://web.telegram.org/*
// @match       https://web.telegram.org/*
// @version     1.0.0
// @grant       none
// ==/UserScript==


const createStyleElement = (css) => {
  const styleElement = document.createElement('style');
  styleElement.type = 'text/css';
  
  if (styleElement.styleSheet) {
    styleElement.styleSheet.cssText = css;
  } else {
    styleElement.textContent = css;
  }

  return styleElement;
};

(() => {
  const container = document.querySelector('head');

  const css = `
div[ng-switch-when="sticker"],
a.im_message_photo_thumb,
a.im_message_video_thumb,
div.img_gif_image_wrap,
div.im_message_webpage_wrap {
  position: relative;
}
div[ng-switch-when="sticker"]::after {
  content: "【贴图已隐藏】";
}
a.im_message_photo_thumb::after {
  content: "【图片已隐藏】";
}
a.im_message_video_thumb::after {
  content: "【视频已隐藏】";
}
div.img_gif_image_wrap::after {
  content: "【GIF已隐藏】";
}
div.im_message_webpage_wrap::after {
  content: "【链接预览已隐藏】";
}
div[ng-switch-when="sticker"]::after,
a.im_message_photo_thumb::after,
a.im_message_video_thumb::after,
div.img_gif_image_wrap::after,
div.im_message_webpage_wrap::after {
  display: block;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  color: white;
  background-color: rgba(0, 0, 0, .9);
}
  `;
  
  const style = createStyleElement(css);

  container.appendChild(style);
  
  window.CoverImage = () => {
    container.appendChild(style);
  };
  window.DisplayImage = () => {
    container.removeChild(style);
  };
})();