Instagram 隐藏图片

调整 Instagram 图片的透明度。

  1. // ==UserScript==
  2. // @name Instagram: Hide Image
  3. // @name:zh-TW Instagram 隱藏圖片
  4. // @name:zh-CN Instagram 隐藏图片
  5. // @name:ja Instagram 画像を非表示
  6. // @name:ko Instagram 이미지 숨기기
  7. // @name:ru Instagram Скрыть изображение
  8. // @version 1.0.3
  9. // @description Make Instagram Images Opacity Lower.
  10. // @description:zh-TW 調整 Instagram 圖片的透明度。
  11. // @description:zh-CN 调整 Instagram 图片的透明度。
  12. // @description:ja Instagram 画像の不透明度を低くします。
  13. // @description:ko Instagram 이미지 불투명도를 낮추십시오.
  14. // @description:ru Уменьшите непрозрачность изображений в Instagram.
  15. // @author Hayao-Gai
  16. // @namespace https://github.com/HayaoGai
  17. // @icon https://i.imgur.com/obCmlr9.png
  18. // @match https://www.instagram.com/*
  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. const textStyle = `
  32. .switch-set {
  33. margin-left: 20px;
  34. }
  35. .hide-set {
  36. transition: opacity 0.3s;
  37. opacity: 0.1;
  38. }
  39. .show-set {
  40. opacity: 1 !important;
  41. }`;
  42. let currentUrl = document.location.href;
  43. let updating = false;
  44.  
  45. css();
  46.  
  47. init(10);
  48.  
  49. locationChange();
  50.  
  51. window.addEventListener("scroll", update);
  52.  
  53. function init(times) {
  54. for (let i = 0; i < times; i++) {
  55. setTimeout(addToggle, 500 * i);
  56. setTimeout(findImage1, 500 * i);
  57. setTimeout(findImage2, 500 * i);
  58. setTimeout(findVideo, 500 * i);
  59. setTimeout(showAll, 500 * i);
  60. }
  61. }
  62.  
  63. // toggle
  64. function addToggle() {
  65. // check exist
  66. const exist = document.querySelector(".switch-set");
  67. if (!!exist) {
  68. exist.innerHTML = getToggle() ? iconOn : iconOff;
  69. return;
  70. }
  71. // panel
  72. const panel = document.querySelector(".ctQZg");
  73. if (!panel) return;
  74. // switch
  75. const button = document.createElement("button");
  76. button.className = "dCJp8 afkep switch-set";
  77. button.innerHTML = getToggle() ? iconOn : iconOff;
  78. button.addEventListener("click", onClick);
  79. panel.appendChild(button);
  80. }
  81.  
  82. function onClick() {
  83. const afterClick = !getToggle();
  84. GM_setValue("switch", afterClick);
  85. this.innerHTML = afterClick ? iconOn : iconOff;
  86. init(3);
  87. }
  88.  
  89. function getToggle() {
  90. return GM_getValue("switch", true);
  91. }
  92.  
  93. // hide image
  94. function findImage1() {
  95. // check toggle
  96. if (!getToggle()) return;
  97. // image ( avatar )
  98. document.querySelectorAll("img._6q-tv:not(.hide-set)").forEach(image => {
  99. image.classList.add("hide-set");
  100. // event
  101. image.addEventListener("mouseenter", showImage);
  102. image.addEventListener("mouseleave", hideImage);
  103. });
  104. }
  105.  
  106. function findImage2() {
  107. // check toggle
  108. if (!getToggle()) return;
  109. // image ( post )
  110. document.querySelectorAll("img.FFVAD:not(.hide-set)").forEach(image => {
  111. image.classList.add("hide-set");
  112. // event
  113. const hover = image.closest(".eLAPa").lastElementChild;
  114. hover.addEventListener("mouseenter", showImage);
  115. hover.addEventListener("mouseleave", hideImage);
  116. });
  117. }
  118.  
  119. function showImage() {
  120. const tag = this.tagName;
  121. // avatar
  122. if (tag === "IMG") this.classList.add("show-set");
  123. // post
  124. else this.parentElement.querySelector("img").classList.add("show-set");
  125. }
  126.  
  127. function hideImage() {
  128. const tag = this.tagName;
  129. // avatar
  130. if (tag === "IMG") this.classList.remove("show-set");
  131. // post
  132. else this.parentElement.querySelector("img").classList.remove("show-set");
  133. }
  134.  
  135. // hide video
  136. function findVideo() {
  137. // check toggle
  138. if (!getToggle()) return;
  139. // video
  140. document.querySelectorAll("video:not(.hide-set)").forEach(video => {
  141. video.classList.add("hide-set");
  142. // thumbnail
  143. const thumbnail = video.parentElement.querySelector("img");
  144. thumbnail.classList.add("hide-set");
  145. // event
  146. const hover = video.closest(".kPFhm").lastElementChild;
  147. hover.addEventListener("mouseenter", showVideo);
  148. hover.addEventListener("mouseleave", hideVideo);
  149. });
  150. }
  151.  
  152. function showVideo() {
  153. const video = this.parentElement.querySelector("video");
  154. video.classList.add("show-set");
  155. }
  156.  
  157. function hideVideo() {
  158. const video = this.parentElement.querySelector("video");
  159. video.classList.remove("show-set");
  160. }
  161.  
  162. // show all
  163. function showAll() {
  164. // check toggle
  165. if (getToggle()) return;
  166. // show
  167. document.querySelectorAll(".hide-set").forEach(target => target.classList.remove("hide-set"));
  168. }
  169.  
  170. // other
  171. function css() {
  172. const style = document.createElement("style");
  173. style.type = "text/css";
  174. style.innerHTML = textStyle;
  175. document.head.appendChild(style);
  176. }
  177.  
  178. function update() {
  179. if (updating) return;
  180. updating = true;
  181. init(3);
  182. setTimeout(() => { updating = false }, 1000);
  183. }
  184.  
  185. function locationChange() {
  186. const observer = new MutationObserver(mutations => {
  187. mutations.forEach(() => {
  188. if (currentUrl !== document.location.href) {
  189. currentUrl = document.location.href;
  190. init(10);
  191. }
  192. });
  193. });
  194. const target = document.querySelector("body");
  195. const config = { childList: true, subtree: true };
  196. observer.observe(target, config);
  197. }
  198.  
  199. })();

QingJ © 2025

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