Tabshot – 下载 🦊 Firefox 扩展(zh-CN)
最近一个用户找到我,想要这个浏览器扩展有一个快捷键截图功能。
我找了一下,发现火狐扩展的确支持快捷键
研究源码
about:support
配置文件夹,打开文件夹。
附件组件,查看 网页截图 对应的ID 是 easyscreenshot@mozillaonline.com
extensions 目录查找 easyscreenshot@mozillaonline.com.xpi
复制出来,解压缩。
发现 manifest.json 里面有没有见过的参数:
"commands": {"ess-select": {"suggested_key": {"default": "Ctrl+Shift+S"},"description": "__MSG_action_select__"},"ess-entire": {"description": "__MSG_action_entire__"},"ess-visible": {"description": "__MSG_action_visible__"}
}
background.js
function handleCommand(cmd) {if (!cmd.startsWith("ess-")) {return;}let action = cmd.slice("ess-".length);handleAction({action}, response => {if (response && response.error) {console.error(response.error);} else {console.log(response);}});
}chrome.commands.onCommand.addListener(handleCommand);
看了几遍,好像懂了,我的这样改
manifest.json
"commands": { "capture_video": {"suggested_key": {"default": "Ctrl+Shift+Y"},"description": "截图视频"}
}
background.js
chrome.commands.onCommand.addListener(function (command) {console.log(command);if (command === 'capture_video') {chrome.tabs.executeScript({ file: 'video.js' });}
});
静默保存(不显示保存对话框)