Discord 隐藏图片

使图片较为透明。

当前为 2020-05-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Discord: Hide Image
  3. // @name:zh-TW Discord 隱藏圖片
  4. // @name:zh-CN Discord 隐藏图片
  5. // @name:ja Discord 画像を非表示
  6. // @name:ko Discord 이미지 숨기기
  7. // @name:ru Discord Скрыть изображение
  8. // @version 1.0.2
  9. // @description Make images opacity lower.
  10. // @description:zh-TW 使圖片較為透明。
  11. // @description:zh-CN 使图片较为透明。
  12. // @description:ja 画像の不透明度を低くします。
  13. // @description:ko 이미지의 불투명도를 낮추십시오.
  14. // @description:ru Уменьшите непрозрачность изображений.
  15. // @author Hayao-Gai
  16. // @namespace https://github.com/HayaoGai
  17. // @icon https://i.imgur.com/rE9N0R7.png
  18. // @match https://discord.com/channels/*
  19. // @grant GM_getValue
  20. // @grant GM_setValue
  21. // ==/UserScript==
  22.  
  23. /* jshint esversion: 6 */
  24.  
  25. (function() {
  26. 'use strict';
  27.  
  28. // icons made by https://www.flaticon.com/authors/pixel-perfect
  29. const iconOn = `<svg width="35" height="35" viewBox="0 -107 512 512"><path d="m362.667969 298.667969h-213.335938c-82.34375 0-149.332031-67.007813-149.332031-149.335938 0-82.324219 66.988281-149.332031 149.332031-149.332031h213.335938c82.34375 0 149.332031 67.007812 149.332031 149.332031 0 82.328125-66.988281 149.335938-149.332031 149.335938zm-213.335938-266.667969c-64.703125 0-117.332031 52.652344-117.332031 117.332031 0 64.683594 52.628906 117.335938 117.332031 117.335938h213.335938c64.703125 0 117.332031-52.652344 117.332031-117.335938 0-64.679687-52.628906-117.332031-117.332031-117.332031zm0 0"/><path d="m362.667969 234.667969c-47.0625 0-85.335938-38.273438-85.335938-85.335938 0-47.058593 38.273438-85.332031 85.335938-85.332031 47.058593 0 85.332031 38.273438 85.332031 85.332031 0 47.0625-38.273438 85.335938-85.332031 85.335938zm0-138.667969c-29.398438 0-53.335938 23.914062-53.335938 53.332031 0 29.421875 23.9375 53.335938 53.335938 53.335938 29.394531 0 53.332031-23.914063 53.332031-53.335938 0-29.417969-23.9375-53.332031-53.332031-53.332031zm0 0"/></svg>`;
  30. const iconOff = `<svg width="35" height="35" viewBox="0 -107 512 512"><path d="m362.667969 0h-213.335938c-82.324219 0-149.332031 66.988281-149.332031 149.332031 0 82.347657 67.007812 149.335938 149.332031 149.335938h213.335938c82.324219 0 149.332031-66.988281 149.332031-149.335938 0-82.34375-67.007812-149.332031-149.332031-149.332031zm-213.335938 234.667969c-47.058593 0-85.332031-38.273438-85.332031-85.335938 0-47.058593 38.273438-85.332031 85.332031-85.332031 47.0625 0 85.335938 38.273438 85.335938 85.332031 0 47.0625-38.273438 85.335938-85.335938 85.335938zm0 0"/></svg>`;
  31.  
  32. // css
  33. const textStyle = `
  34. .hide-set {
  35. transition: opacity 0.3s;
  36. opacity: 0.1 !important;
  37. }
  38. .switch-set {
  39. fill: white;
  40. text-align: center;
  41. bottom: 10px;
  42. cursor: pointer;
  43. pointer-events: all;
  44. }`;
  45.  
  46. // update
  47. let updating = false;
  48.  
  49. css();
  50.  
  51. init(10);
  52.  
  53. locationChange();
  54.  
  55. window.addEventListener("scroll", update, true);
  56.  
  57. function init(times) {
  58. console.log("init!");
  59. for (let i = 0; i < times; i++) {
  60. setTimeout(switchButton, 500 * i);
  61. setTimeout(() => getTarget("img:not(.hide-set)"), 500 * i); // all images.
  62. setTimeout(() => getTarget("video:not(.hide-set)"), 500 * i); // all videos ( gifs ).
  63. setTimeout(() => getTarget(".animatedContainer-1pJv5C:not(.hide-set)"), 500 * i); // the image on top of server channel lists.
  64. setTimeout(() => getTarget(".avatarContainer-2inGBK:not(.hide-set)"), 500 * i); // the avatar images in channels.
  65. }
  66. stopHide();
  67. }
  68.  
  69. function switchButton() {
  70. // check exist
  71. const isExist = document.querySelector(".switch-set");
  72. if (!!isExist) return;
  73. // left panel ( parent )
  74. const leftPanel = document.querySelector("nav.wrapper-1Rf91z");
  75. if (!leftPanel) return;
  76. // add switch button
  77. const button = document.createElement("div");
  78. button.className = "unreadMentionsIndicatorBottom-BXS58x switch-set";
  79. button.innerHTML = getToggle() ? iconOn : iconOff;
  80. button.addEventListener("click", onClick);
  81. leftPanel.appendChild(button);
  82. }
  83.  
  84. function getToggle() {
  85. return GM_getValue("switch", true);
  86. }
  87.  
  88. function onClick() {
  89. const afterClick = !getToggle();
  90. GM_setValue("switch", afterClick);
  91. this.innerHTML = afterClick ? iconOn : iconOff;
  92. init(3);
  93. }
  94.  
  95. function getTarget(target) {
  96. // check toggle
  97. if (!getToggle()) return;
  98. // hide target
  99. document.querySelectorAll(target).forEach(t => {
  100. t.classList.add("hide-set");
  101. t.addEventListener("mouseenter", showTarget);
  102. t.addEventListener("mouseleave", hideTarget);
  103. });
  104. }
  105.  
  106. function showTarget() {
  107. this.style.opacity = 1;
  108. }
  109.  
  110. function hideTarget() {
  111. this.style.opacity = 0.1;
  112. }
  113.  
  114. function stopHide() {
  115. // check toggle
  116. if (getToggle()) return;
  117. // show target
  118. document.querySelectorAll(".hide-set").forEach(hide => {
  119. hide.classList.remove("hide-set");
  120. hide.removeEventListener("mouseenter", showTarget);
  121. hide.removeEventListener("mouseleave", hideTarget);
  122. });
  123. }
  124.  
  125. function update() {
  126. if (updating) return;
  127. updating = true;
  128. init(3);
  129. setTimeout(() => { updating = false; }, 1000);
  130. }
  131.  
  132. function css() {
  133. const style = document.createElement("style");
  134. style.type = "text/css";
  135. style.innerHTML = textStyle;
  136. document.head.appendChild(style);
  137. }
  138.  
  139. function locationChange() {
  140. window.addEventListener('locationchange', () => init(3));
  141. // situation 1
  142. history.pushState = (f => function pushState(){
  143. var ret = f.apply(this, arguments);
  144. window.dispatchEvent(new Event('pushState'));
  145. window.dispatchEvent(new Event('locationchange'));
  146. return ret;
  147. })(history.pushState);
  148. // situation 2
  149. history.replaceState = (f => function replaceState(){
  150. var ret = f.apply(this, arguments);
  151. window.dispatchEvent(new Event('replaceState'));
  152. window.dispatchEvent(new Event('locationchange'));
  153. return ret;
  154. })(history.replaceState);
  155. // situation 3
  156. window.addEventListener('popstate', () => window.dispatchEvent(new Event('locationchange')));
  157. }
  158.  
  159. })();

QingJ © 2025

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