keepitanonymous

隐藏页面上的账号信息,如:用户名,手机,邮箱

目前為 2024-05-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        keepitanonymous
// @name:zh-CN  保持匿名
// @description 隐藏页面上的账号信息,如:用户名,手机,邮箱
// @namespace   maoxuner.gitee.io
// @author      maoxuner
// @version     0.2.0
// @license     GPLv3
// @match       *://*/*
// @grant       GM_registerMenuCommand
// @grant       GM_getValue
// @grant       GM_setValue
// @run-at      document-start
// @homepageURL https://gitee.com/maoxuner
// ==/UserScript==

(function (window) {
  'use strict';

  /* no89757        切换输入框文字显隐        aptx4869 */

  // 切换输入框文字显隐
  const STATE_SHOW = 1
  const STATE_HIDE = 0
  function switchInputText(element, state = null) {
    const identifier = 'ttplayer'

    if (element.hasAttribute(identifier)) {
      if (STATE_HIDE !== state) {  // 非强制隐藏,则显示
        // 显示输入框文字
        element.setAttribute('type', 'text')
        element.setAttribute('placeholder', element.getAttribute(identifier))
        element.removeAttribute(identifier)

        return true
      }
    } else {
      if (STATE_SHOW !== state) {  // 非强制显示,则隐藏
        // 隐藏输入框文字
        element.setAttribute(identifier, element.getAttribute('placeholder') || '')
        element.setAttribute('type', 'password')
        element.setAttribute('placeholder', 'Text Protected')

        return true
      }
    }

    return false
  }

  /* laravel        自动隐藏输入框文字        hohai */

  // 判断是否是隐私信息输入框
  function isPrivacyInput(element) {
    const identifier = ['username', 'user', 'name', 'email', 'mail', 'phone', 'login', 'account']

    return 'text' === element.type && (element.name && identifier.includes(element.name) || 'username' === element.autocomplete) || 'email' === element.type
  }

  // 显示所有
  function showAllInputText() {
    let ret = 0
    window.document.querySelectorAll('input[type=password]')
      .forEach(element => switchInputText(element, STATE_SHOW) && ret++)
    return ret
  }

  // 隐藏所有
  function hideAllInputText() {
    let ret = 0
    window.document.querySelectorAll('input')
      .forEach(element => isPrivacyInput(element) && switchInputText(element, STATE_HIDE) && ret++)
    return ret
  }

  // 注册菜单
  const TITLE_MESSAGE = '无法作用于嵌套页面'
  GM_registerMenuCommand('显示所有', showAllInputText, { title: TITLE_MESSAGE })
  GM_registerMenuCommand('隐藏所有', hideAllInputText, { title: TITLE_MESSAGE })

  // 切换自动隐藏
  const MODE_KEY = 'mode'
  const MODE_OFF = 0
  const MODE_ON1 = 1
  const MODE_ON2 = 2
  function switchAutoHideInputText() {
    const mode = (GM_getValue(MODE_KEY, MODE_OFF) + 1) % 3

    GM_setValue(MODE_KEY, mode)
    registerAutoHideMenu(mode)
  }

  // 注册自动隐藏菜单
  function registerAutoHideMenu(mode) {
    const id = 'DDRaceNetwork'
    switch (mode) {
      case MODE_OFF:
        GM_registerMenuCommand('切换自动隐藏模式(当前:关闭)', switchAutoHideInputText, { id, title: '当前不会自动隐藏', autoClose: false })
        break
      case MODE_ON1:
        GM_registerMenuCommand('切换自动隐藏模式(当前:普通)', switchAutoHideInputText, { id, title: '页面加载完成后立即隐藏', autoClose: false })
        break
      case MODE_ON2:
        GM_registerMenuCommand('切换自动隐藏模式(当前:增强)', switchAutoHideInputText, { id, title: '页面加载完成后持续隐藏(适用于嵌套页面)', autoClose: false })
        break
    }
  }

  // 初始化
  const mode = GM_getValue(MODE_KEY, MODE_OFF)
  registerAutoHideMenu(mode)
  switch (mode) {
    case MODE_ON1:
      hideAllInputText()
      break
    case MODE_ON2:
      let times = 0
      const id = setInterval(() => {
        times++
        (hideAllInputText() || times >= 50) && clearInterval(id)
      }, 100)
      break
  }
})(window)