keepitanonymous

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

  1. // ==UserScript==
  2. // @name keepitanonymous
  3. // @name:zh-CN 保持匿名
  4. // @description 隐藏页面上的账号信息,如:用户名,手机,邮箱
  5. // @namespace maoxuner.gitee.io
  6. // @author maoxuner
  7. // @version 0.3.0
  8. // @license GPLv3
  9. // @match *://*/*
  10. // @grant GM_addStyle
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @run-at document-start
  15. // @homepageURL https://gitee.com/maoxuner
  16. // ==/UserScript==
  17.  
  18. (function (window) {
  19. 'use strict';
  20.  
  21. /* no89757 切换输入框文字显隐 aptx4869 */
  22.  
  23. const className = 'password-dots-regular'
  24. const styleElement = GM_addStyle(`
  25. @font-face {
  26. font-family: "Password Dots Regular";
  27. src: url("https://db.onlinewebfonts.com/t/2767b18dd6a611e3ce83d0bfe4729cb4.eot");
  28. src: url("https://db.onlinewebfonts.com/t/2767b18dd6a611e3ce83d0bfe4729cb4.eot?#iefix")format("embedded-opentype"),
  29. url("https://db.onlinewebfonts.com/t/2767b18dd6a611e3ce83d0bfe4729cb4.woff2")format("woff2"),
  30. url("https://db.onlinewebfonts.com/t/2767b18dd6a611e3ce83d0bfe4729cb4.woff")format("woff"),
  31. url("https://db.onlinewebfonts.com/t/2767b18dd6a611e3ce83d0bfe4729cb4.ttf")format("truetype"),
  32. url("https://db.onlinewebfonts.com/t/2767b18dd6a611e3ce83d0bfe4729cb4.svg#Password Dots Regular")format("svg");
  33. }
  34. input.password-dots-regular {
  35. font-family: "Password Dots Regular";
  36. }
  37. input.password-dots-regular::placeholder {
  38. font-family: none;
  39. }
  40. `)
  41. window.document.querySelector('head').appendChild(styleElement)
  42.  
  43. // 切换输入框文字显隐
  44. const STATE_SHOW = 1
  45. const STATE_HIDE = 0
  46. function switchInputText(element, state = null) {
  47. if (element.classList.contains(className)) {
  48. if (STATE_HIDE !== state) { // 非强制隐藏,则显示
  49. // 显示输入框文字
  50. if (1 === element.classList.length) {
  51. element.removeAttribute('class')
  52. } else {
  53. element.classList.remove(className)
  54. }
  55.  
  56. return true
  57. }
  58. } else {
  59. if (STATE_SHOW !== state) { // 非强制显示,则隐藏
  60. // 隐藏输入框文字
  61. element.classList.add(className)
  62.  
  63. return true
  64. }
  65. }
  66.  
  67. return false
  68. }
  69.  
  70. /* laravel 自动隐藏输入框文字 hohai */
  71.  
  72. // 判断是否是隐私信息输入框
  73. function isPrivacyInput(element) {
  74. const identifier = ['username', 'user', 'name', 'email', 'mail', 'phone', 'telephone', 'tel', 'mobilephone', 'mobile', 'login', 'account']
  75.  
  76. return 'text' === element.type && (element.name && identifier.includes(element.name) || 'username' === element.autocomplete) || 'email' === element.type || 'tel' === element.type
  77. }
  78.  
  79. // 显示所有
  80. function showAllInputText() {
  81. let ret = 0
  82. window.document.querySelectorAll('input.' + className)
  83. .forEach(element => switchInputText(element, STATE_SHOW) && ret++)
  84. return ret
  85. }
  86.  
  87. // 隐藏所有
  88. function hideAllInputText() {
  89. let ret = 0
  90. window.document.querySelectorAll('input')
  91. .forEach(element => isPrivacyInput(element) && switchInputText(element, STATE_HIDE) && ret++)
  92. return ret
  93. }
  94.  
  95. // 注册(不可用)菜单
  96. const TITLE_MESSAGE = '无法作用于嵌套页面'
  97. GM_registerMenuCommand('显示所有', showAllInputText, { title: TITLE_MESSAGE })
  98. GM_registerMenuCommand('隐藏所有', hideAllInputText, { title: TITLE_MESSAGE })
  99.  
  100. // 切换自动隐藏
  101. const MODE_KEY = 'mode'
  102. const MODE_OFF = 0
  103. const MODE_ON1 = 1
  104. const MODE_ON2 = 2
  105. function switchAutoHideInputText() {
  106. const mode = (GM_getValue(MODE_KEY, MODE_OFF) + 1) % 3
  107.  
  108. GM_setValue(MODE_KEY, mode)
  109. registerAutoHideMenu(mode)
  110. }
  111.  
  112. // 注册(不可用)自动隐藏菜单
  113. function registerAutoHideMenu(mode) {
  114. const id = 'DDRaceNetwork'
  115. switch (mode) {
  116. case MODE_OFF:
  117. GM_registerMenuCommand('切换自动隐藏模式(当前:关闭)', switchAutoHideInputText, { id, title: '当前不会自动隐藏', autoClose: false })
  118. break
  119. case MODE_ON1:
  120. GM_registerMenuCommand('切换自动隐藏模式(当前:普通)', switchAutoHideInputText, { id, title: '页面加载完成后立即隐藏', autoClose: false })
  121. break
  122. case MODE_ON2:
  123. GM_registerMenuCommand('切换自动隐藏模式(当前:增强)', switchAutoHideInputText, { id, title: '页面加载完成后持续隐藏(适用于嵌套页面)', autoClose: false })
  124. break
  125. }
  126. }
  127.  
  128. // 初始化
  129. const mode = GM_getValue(MODE_KEY, MODE_OFF)
  130. registerAutoHideMenu(mode)
  131. switch (mode) {
  132. case MODE_ON1:
  133. hideAllInputText()
  134. break
  135. case MODE_ON2:
  136. let times = 0
  137. const id = setInterval(() => {
  138. times++
  139. (hideAllInputText() || times >= 50) && clearInterval(id)
  140. }, 100)
  141. break
  142. }
  143. })(window)

QingJ © 2025

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