去除绑定账号弹框

Remove modal-mask and bind-phone-number-form elements, and rewrite scroll listener

  1. // ==UserScript==
  2. // @name 去除绑定账号弹框
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @license MIT
  6. // @description Remove modal-mask and bind-phone-number-form elements, and rewrite scroll listener
  7. // @author AnmSleepalone
  8. // @match *://juejin.cn/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 函数:移除指定的元素
  16. function removeElements() {
  17. // 移除 modal-mask 元素
  18. const modalMasks = document.getElementsByClassName('modal-mask');
  19. while (modalMasks.length > 0) {
  20. modalMasks[0].remove();
  21. }
  22.  
  23. // 移除 bind-phone-number-form 元素
  24. const phoneforms = document.getElementsByClassName('bind-phone-number-form');
  25. while (phoneforms.length > 0) {
  26. phoneforms[0].remove();
  27. }
  28.  
  29. // 恢复页面滚动
  30. document.body.style.overflow = 'auto';
  31. }
  32.  
  33. // 函数:重写滚动监听
  34. function setupScrollListener() {
  35. // 移除可能存在的所有滚动事件监听器
  36. window.onscroll = null;
  37.  
  38. // 添加新的滚动监听器
  39. let lastScrollPosition = window.pageYOffset;
  40. let ticking = false;
  41.  
  42. window.addEventListener('scroll', function() {
  43. lastScrollPosition = window.pageYOffset;
  44.  
  45. if (!ticking) {
  46. window.requestAnimationFrame(function() {
  47. // 在这里处理滚动事件
  48. console.log('Scroll position:', lastScrollPosition);
  49. // 可以在这里添加你的自定义滚动逻辑
  50.  
  51. ticking = false;
  52. });
  53.  
  54. ticking = true;
  55. }
  56. }, { passive: true });
  57. }
  58.  
  59. // 主函数:等待DOM加载完成后执行
  60. function init() {
  61. // 立即执行一次移除
  62. removeElements();
  63.  
  64. // 设置新的滚动监听
  65. setupScrollListener();
  66.  
  67. // 创建 MutationObserver 来监视 DOM 变化
  68. const observer = new MutationObserver(function(mutations) {
  69. mutations.forEach(function(mutation) {
  70. if (mutation.addedNodes.length) {
  71. removeElements();
  72. }
  73. });
  74. });
  75.  
  76. // 配置 observer
  77. observer.observe(document.body, {
  78. childList: true,
  79. subtree: true
  80. });
  81. }
  82.  
  83. // 当页面加载完成后执行初始化
  84. if (document.readyState === 'loading') {
  85. document.addEventListener('DOMContentLoaded', init);
  86. } else {
  87. init();
  88. }
  89. })();

QingJ © 2025

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