Greasy Fork

Greasy Fork is available in English.

HideImg

隐藏图片

当前为 2023-10-07 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        HideImg
// @namespace   ojer
// @match       *://*/*
// @version     1.2
// @author      ojer
// @description 隐藏图片
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_addStyle
// @grant       GM_registerMenuCommand
// @grant       GM_unregisterMenuCommand
// @grant       GM_addValueChangeListener
// @require     https://unpkg.com/@violentmonkey/[email protected]/dist/index.js
// ==/UserScript==

const { register } = VM.shortcut

const HI_STATUS = 'HI_STATUS'

const captionHideKey = 'HideImg (Ctrl+Shift+I)'
const captionShowKey = 'ShowImg (Ctrl+Shift+I)'
const styleBkImgHIde = `
* { background-image: url("data:,") !important; }
img,video{ visibility: hidden !important; }
`

const hide = () => {
  regMenu(true)
  GM_addStyle(styleBkImgHIde)
}

const show = () => {
  regMenu(false)
  Array.from(document.querySelectorAll('style'))
    .filter((e) => e.id.startsWith('VMst0.'))
    .forEach((e) => e.remove())
}

GM_addValueChangeListener(HI_STATUS, (name, oldValue, newValue, remote) => {
  if (oldValue && !newValue) {
    show()
  } else if (!oldValue && newValue) {
    hide()
  }
})
const regMenu = (isShow) => {
  GM_unregisterMenuCommand(isShow ? captionHideKey : captionShowKey)
  GM_registerMenuCommand(isShow ? captionShowKey : captionHideKey, () => {
    GM_setValue(HI_STATUS, !isShow)
  })
}

register('c-s-i', () => {
  GM_setValue(HI_STATUS, !GM_getValue(HI_STATUS))
})

const main = () => {
  if (GM_getValue(HI_STATUS, undefined) === undefined) {
    GM_setValue(HI_STATUS, false)
  }
  if (GM_getValue(HI_STATUS)) {
    hide()
  } else {
    show()
  }
}
main()