如何修改Matter书签脚本,自动触发回车实现链接自动保存?
修改Matter书签脚本实现自动保存
原Matter书签脚本需要手动点击保存按钮,以下是修改后的单行脚本,添加1秒延迟确保弹窗加载完成后自动触发保存操作:
javascript:(()=>{async(o)=>{let e=window.document;await(async()=>new Promise((t)=>{if(e.readyState==="complete")return t(e.readyState);window.addEventListener("load",()=>t(e.readyState))})());const origin="https://web.getmatter.com";window.addEventListener("message",(e)=>{if(e.origin!==origin||e.data.type!=="ASK_PAGE_HTML")return;e.source.postMessage({type:"PAGE_HTML",payload:document.documentElement.outerHTML},origin)});const popup=window.open(`${origin}/bookmarklet/save?url=${encodeURIComponent(o.location.href)}`,"MATTER_SAVE","popup=1,width=500,height=250");setTimeout(()=>{try{const a=popup.document.querySelector('button[type="submit"],button:has-text("Save"),.save-button');a?a.click():popup.document.activeElement.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter",bubbles:true}))}catch(t){}},1000)}(window)})()
修改说明
- 保存弹窗实例:捕获
window.open返回的弹窗对象,用于后续操作 - 1秒延迟定时器:等待弹窗页面完全加载,避免元素未找到的问题
- 自动触发逻辑:
- 优先查找常见的保存按钮选择器(提交按钮、含"Save"文本的按钮、保存按钮类),找到后直接点击
- 如果按钮定位失败,自动对当前激活元素触发回车键,模拟手动提交
- 异常捕获:包裹
try/catch处理跨域访问可能出现的报错,避免脚本中断
内容的提问来源于stack exchange,提问作者Fede Gold
相关产品推荐
相关产品推荐

