perf: 优化 chrome 插件

pull/10585/head
ibuler 2023-05-30 10:59:16 +08:00
parent 5edacf369b
commit 50d8389fff
2 changed files with 22 additions and 2 deletions

View File

@ -11,6 +11,13 @@ chrome.tabs.onCreated.addListener(function (tab) {
});
});
document.addEventListener("contextmenu", function (event) {
event.preventDefault();
// 监听窗口的创建事件
chrome.windows.onCreated.addListener(function (window) {
// 获取当前所有窗口
chrome.windows.getAll(function (windows) {
// 如果当前窗口数量大于1则关闭新创建的窗口
if (windows.length > 1) {
chrome.windows.remove(window.id);
}
});
});

View File

@ -8,16 +8,29 @@ for (let i = 0; i < links.length; i++) {
links[i].target = '_self'; // target 属性设置为 _self当前窗口打开
}
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
console.log(request.url);
$("iframe").attr("src", request.url);
sendResponse({farewell: "goodbye"});
}
)
document.addEventListener("contextmenu", function (event) {
console.log('On contextmenu event')
event.preventDefault();
});
var AllowedKeys = ['P', 'F', 'p', 'f']
window.addEventListener("keydown", function (e) {
if (e.key === "F12" || (e.ctrlKey && !AllowedKeys.includes(e.key))) {
e.preventDefault();
e.stopPropagation();
console.log('Press key: ', e.ctrlKey ? 'Ctrl' : '', e.shiftKey ? ' Shift' : '', e.key)
}
}, true);
chrome.runtime.sendMessage({greeting: "hello"}, function (response) {
});