fix: popup.js action->cmd; add disable_dialogs.js with toast; update manifest

This commit is contained in:
Jiaqing Liang
2026-04-07 12:17:18 +08:00
parent b525684378
commit 25fe3e42fd
4 changed files with 33 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
// Disable alert/confirm/prompt to prevent page JS from blocking extension
(function() {
const _log = console.log.bind(console);
function toast(type, msg) {
_log('[TMWD] ' + type + ' suppressed:', msg);
try {
const d = document.createElement('div');
d.textContent = '[' + type + '] ' + msg;
Object.assign(d.style, {
position:'fixed', top:'12px', right:'12px', zIndex:'2147483647',
background:'#222', color:'#fff', padding:'10px 18px', borderRadius:'8px',
fontSize:'14px', maxWidth:'420px', wordBreak:'break-all',
boxShadow:'0 4px 16px rgba(0,0,0,.3)', opacity:'1',
transition:'opacity .5s', pointerEvents:'none'
});
(document.body || document.documentElement).appendChild(d);
setTimeout(() => { d.style.opacity = '0'; }, 3000);
setTimeout(() => { d.remove(); }, 3600);
} catch(e) {}
}
window.alert = function(msg) { toast('alert', msg); };
window.confirm = function(msg) { toast('confirm', msg); return true; };
window.prompt = function(msg, def) { toast('prompt', msg); return def || null; };
})();

View File

@@ -17,6 +17,13 @@
"service_worker": "background.js" "service_worker": "background.js"
}, },
"content_scripts": [ "content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["disable_dialogs.js"],
"run_at": "document_start",
"all_frames": true,
"world": "MAIN"
},
{ {
"matches": ["<all_urls>"], "matches": ["<all_urls>"],
"js": ["config.js", "content.js"], "js": ["config.js", "content.js"],

View File

@@ -10,7 +10,7 @@ async function fetchCookies() {
try { try {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (!tab?.url) { out.textContent = 'No active tab'; return; } if (!tab?.url) { out.textContent = 'No active tab'; return; }
const resp = await chrome.runtime.sendMessage({ action: 'cookies', url: tab.url }); const resp = await chrome.runtime.sendMessage({ cmd: 'cookies', url: tab.url });
if (!resp?.ok) { out.textContent = 'Error: ' + (resp?.error || 'unknown'); return; } if (!resp?.ok) { out.textContent = 'Error: ' + (resp?.error || 'unknown'); return; }
if (!resp.data.length) { out.textContent = '(no cookies)'; return; } if (!resp.data.length) { out.textContent = '(no cookies)'; return; }
// 展示带标记 // 展示带标记

View File

@@ -52,7 +52,7 @@ fetch('PDF_URL').then(r=>r.blob()).then(b=>{
## CDP桥(tmwd_cdp_bridge扩展) ⭐首选 ## CDP桥(tmwd_cdp_bridge扩展) ⭐首选
扩展路径:`assets/tmwd_cdp_bridge/`(需安装含debugger权限) 扩展路径:`assets/tmwd_cdp_bridge/`(需安装含debugger权限)
⚠TID密钥首次运行自动生成到`assets/tmwd_cdp_bridge/config.js`(已gitignore)扩展通过manifest引用 ⚠TID约定标识(非密钥):首次运行自动生成到`assets/tmwd_cdp_bridge/config.js`(已gitignore)扩展通过manifest引用
调用:`web_execute_js` script直传JSON字符串工具层自动识别对象格式走WS→background.js cmd路由 调用:`web_execute_js` script直传JSON字符串工具层自动识别对象格式走WS→background.js cmd路由
```js ```js
// 直接传JSON字符串作为script参数无需DOM操作 // 直接传JSON字符串作为script参数无需DOM操作