问答 查看内容
返回列表

“更多”工具栏可以隐藏吗?

17 1
发表于 昨天 15:40 | 查看全部 阅读模式
“更多”工具栏可以隐藏吗?

截图202604131540142790.png

评论1

观小豪楼主Lv.1 发表于 昨天 15:41 | 查看全部
关于这个问题,可以通过插件管理功能实现。

插件代码:


  1. <div>
  2. <div>(() => {
  3.   const PLUGIN_NAME = '隐藏-顶部更多入口-UAT';

  4.   const hideNode = (node) => {
  5.     if (!node || node.nodeType !== 1) return;
  6.     node.style.setProperty('display', 'none', 'important');
  7.     node.style.setProperty('pointer-events', 'none', 'important');
  8.     node.setAttribute('data-hidden-by-plugin', PLUGIN_NAME);
  9.   };

  10.   const findClickableWrapper = (node, stopNode) => {
  11.     let cur = node;
  12.     let best = node;

  13.     while (cur && cur !== stopNode && cur.nodeType === 1) {
  14.       const rect = cur.getBoundingClientRect();
  15.       const role = cur.getAttribute('role') || '';
  16.       const cls = String(cur.className?.baseVal || cur.className || '');

  17.       if (
  18.         cur.tagName === 'BUTTON' ||
  19.         role === 'button' ||
  20.         cls.includes('tooltip') ||
  21.         cls.includes('popover') ||
  22.         typeof cur.onclick === 'function' ||
  23.         rect.width <= 80
  24.       ) {
  25.         best = cur;
  26.       }

  27.       if (rect.width > 100 || rect.height > 80) break;
  28.       cur = cur.parentElement;
  29.     }

  30.     return best;
  31.   };

  32.   const hideToolbarMore = () => {
  33.     const toolbar = document.querySelector('[data-open="toolbar"]');
  34.     if (!toolbar) return;

  35.     const candidates = Array.from(toolbar.querySelectorAll('*')).filter((el) => {
  36.       const text = (el.textContent || '').trim();
  37.       const title = el.getAttribute('title') || '';
  38.       const aria = el.getAttribute('aria-label') || '';
  39.       const cls = String(el.className?.baseVal || el.className || '');
  40.       const href = el.getAttribute('href') || el.getAttribute('xlink:href') || '';
  41.       const name = el.getAttribute('name') || '';

  42.       return (
  43.         text === '更多' ||
  44.         title === '更多' ||
  45.         aria === '更多' ||
  46.         name === 'tool' ||
  47.         cls.includes('tool') ||
  48.         href.includes('tool')
  49.       );
  50.     });

  51.     candidates.forEach((el) => hideNode(findClickableWrapper(el, toolbar)));
  52.   };

  53.   const hideByOpenedApprovalPopup = () => {
  54.     const approvalNode = Array.from(document.querySelectorAll('body *')).find((el) => {
  55.       const text = (el.textContent || '').trim();
  56.       return text === '审批中心';
  57.     });

  58.     if (!approvalNode) return;

  59.     const toolbar = document.querySelector('[data-open="toolbar"]');
  60.     if (!toolbar) return;

  61.     const toolbarRect = toolbar.getBoundingClientRect();
  62.     const toolbarItems = Array.from(toolbar.children)
  63.       .filter((el) => {
  64.         const rect = el.getBoundingClientRect();
  65.         return rect.width > 0 && rect.height > 0 && rect.left >= toolbarRect.left;
  66.       })
  67.       .sort((a, b) => b.getBoundingClientRect().left - a.getBoundingClientRect().left);

  68.     const likelyMore = toolbarItems.find((el) => {
  69.       const text = el.textContent || '';
  70.       const cls = String(el.className?.baseVal || el.className || '');
  71.       return !text.includes('管理中心') && !cls.includes('user');
  72.     });

  73.     hideNode(likelyMore);
  74.   };

  75.   const apply = () => {
  76.     hideToolbarMore();
  77.     hideByOpenedApprovalPopup();
  78.     console.log(`[${PLUGIN_NAME}] applied`);
  79.   };

  80.   const schedule = () => {
  81.     apply();
  82.     setTimeout(apply, 100);
  83.     setTimeout(apply, 500);
  84.     setTimeout(apply, 1500);
  85.     setTimeout(apply, 3000);
  86.   };

  87.   if (document.readyState === 'loading') {
  88.     document.addEventListener('DOMContentLoaded', schedule, { once: true });
  89.   } else {
  90.     schedule();
  91.   }

  92.   window.addEventListener('load', schedule);
  93.   window.addEventListener('hashchange', schedule);
  94.   window.addEventListener('popstate', schedule);
  95.   document.addEventListener('mouseover', schedule, true);
  96.   document.addEventListener('click', schedule, true);

  97.   new MutationObserver(schedule).observe(document.documentElement, {
  98.     childList: true,
  99.     subtree: true,
  100.   });
  101. })();</div>
  102. </div>
复制代码



插件管理介绍:https://docs.guandata.com/product/bi/575594549863251968

回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

微信服务号
联系我们
电话:400-880-0750
邮箱:hello@guandata.com
Copyright © 2001-2026 观远社区 版权所有 All Rights Reserved. 浙 ICP 备15006424号-3
去回复 去发帖 返回顶部
快速回复 返回顶部 返回列表