我想设置一个键盘快捷键,以便使用 tampermonkey 用户脚本轻松获取 pdf 的 url(并对其进行一些格式化)。我可以为普通的 html 页面执行此操作,但不适用于在内置 pdf 查看器(在 Edge Chromium 上)中打开的 pdf:好像 tampermonkey 无法将 addEventListener 添加到 PDF 查看器,因为脚本在我复制粘贴时有效pdf打开后控制台。
这是我的脚本:
document.addEventListener("keydown", dispatchkeyboardPDF);
function dispatchkeyboardPDF(key) {
if (key.keyCode == 66 && key.altKey) { ///66 = b https://keycode.info/
alert(document.location);
}
}
我还注意到,alert(document.location)
如果我在页面加载时和控制台中直接在 Tampermonkey 中运行它,则会返回不同的结果:这是为什么呢?