您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
2023/6/12 19:20:21
当前为
// ==UserScript== // @name 自动隐藏抖音header搜索 // @namespace 鼠标显示隐藏抖音header搜索 // @match https://www.douyin.com/* // @namespace 476321082 // @license MIT // @grant none // @version 0.4 // @author - // @description 2023/6/12 19:20:21 // ==/UserScript== (function () { 'use strict'; const style = document.createElement('style'); style.textContent = ` .MiecXVmm.gCMIwEM1 { height: 0; } .MiecXVmm .adfr96Gm.RNsmkkvd { top: -80px; } `; document.head.appendChild(style); let target = null; let height = 0; let hidden = false; let menu = null; let isFirst = true; let isObserving = false; let lastMouseMoveTime = 0; const THROTTLE_DELAY = 100; let isReady = false; let intervalId = null; function init() { if (target.style.display !== 'none') { target.style.display = 'none'; hidden = true; } document.addEventListener('mousemove', throttle(onMouseMove, THROTTLE_DELAY), { passive: true }); target.addEventListener('mouseover', onMouseOver); observe(); } function waitForHeader() { intervalId = setInterval(() => { target = document.getElementById('douyin-header'); if (target) { clearInterval(intervalId); height = target.offsetHeight; init(); } }, 1000); } document.addEventListener('readystatechange', () => { if (document.readyState === 'complete') { isReady = true; waitForHeader(); } }); function throttle(fn, delay) { let timer = null; return function (...args) { const currentTime = Date.now(); if (!timer || currentTime - timer >= delay) { fn.apply(this, args); timer = currentTime; } }; } function onMouseMove(e) { const y = e.clientY; if (y <= height / 2) { if (hidden) { target.style.display = 'block'; hidden = false; height = target.offsetHeight; } } else if (y > height && !menuContains(y)) { if (!hidden) { target.style.display = 'none'; hidden = true; menu = null; } } } function menuContains(y) { if (menu) { const menuHeight = menu.offsetHeight; const menuRect = menu.getBoundingClientRect(); const menuTop = menuRect.top; const menuBottom = menuRect.bottom; return y >= menuTop && y <= menuBottom; } return false; } function onMouseOver(e) { if (e.target.tagName === 'DIV' && target.contains(e.target)) { isFirst = true; } } function observe() { if (isObserving) { return; } const observer = new MutationObserver(throttle(handleMutation, THROTTLE_DELAY)); const options = { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] }; observer.observe(target, options); isObserving = true; } function handleMutation(mutations) { for (const mutation of mutations) { if (mutation.addedNodes.length > 0 && isFirst) { for (const node of mutation.addedNodes) { if (node.tagName === 'DIV' && target.contains(node)) { menu = node; isFirst = false; } } } if ( mutation.target.tagName === 'DIV' && mutation.attributeName === 'class' ) { menu = mutation.target; } } } if (isReady) { init(); } })();