You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Window/LocalStorage跨页面添加持久化全局函数隐藏不可编辑页面图标

解决方案

方案一:LocalStorage + 用户脚本(最稳定可靠)

由于unEditPage无法直接修改代码,用户脚本是跨同域页面执行自定义逻辑的最优方案,结合LocalStorage传递触发信号:

1. 在可编辑页面添加标记代码

在任意可编辑页面中插入以下代码,它会在页面卸载(用户导航离开)时,向LocalStorage写入需要执行隐藏操作的标记:

window.addEventListener('unload', () => {
  localStorage.setItem('hideIconOnUnEditPage', 'true');
});

2. 编写用户脚本监听unEditPage

安装Tampermonkey或Violentmonkey等用户脚本管理器,创建新脚本并填入以下内容:

// ==UserScript==
// @name         Hide Icon on unEditPage
// @match        https://your-domain.com/path/to/unEditPage
// @grant        none
// ==/UserScript==

(() => {
    'use strict';
    const hideFlag = localStorage.getItem('hideIconOnUnEditPage');
    if (hideFlag === 'true') {
        document.getElementById('icon').style.display = 'none';
        localStorage.removeItem('hideIconOnUnEditPage'); // 清除标记,避免重复执行
    }
})();

记得把@match后的URL替换成unEditPage的实际访问地址。

方案二:Cookie + 代码注入(无需用户脚本,兼容性有限)

如果不想使用用户脚本,可以用Cookie存储触发标记,但需要你有能力将代码注入到unEditPage的执行环境中(比如通过浏览器扩展、代理工具等):

1. 在可编辑页面设置Cookie标记

在可编辑页面中添加这段代码,在页面卸载时设置短期Cookie:

window.addEventListener('unload', () => {
  // 设置有效期1分钟的Cookie,作用域覆盖全站
  document.cookie = "hideIcon=1; path=/; max-age=60; same-site=strict";
});

2. 注入代码到unEditPage

将以下代码注入到unEditPage的加载流程中,读取Cookie并执行隐藏逻辑:

window.addEventListener('DOMContentLoaded', () => {
  const cookie = document.cookie.split('; ').find(row => row.startsWith('hideIcon='));
  if (cookie?.split('=')[1] === '1') {
    document.getElementById('icon').style.display = 'none';
    // 立即清除Cookie
    document.cookie = "hideIcon=; path=/; max-age=0";
  }
});

注:此方案的局限性在于必须能将代码注入到目标页面,否则无法生效。

关键注意点

  • 确保LocalStorage/Cookie的作用域覆盖unEditPage(比如path=/)
  • 执行完隐藏操作后务必清除标记,避免后续进入unEditPage时重复执行

内容的提问来源于stack exchange,提问作者RooksStrife

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 19:10:16