From 50d8389ffffe788966ab5a10bdb122daceffe36e Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 30 May 2023 10:59:16 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20chrome=20=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../disable_new_tab_window_menu/background.js | 11 +++++++++-- .../disable_new_tab_window_menu/content_script.js | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/terminal/applets/chrome/extensions/disable_new_tab_window_menu/background.js b/apps/terminal/applets/chrome/extensions/disable_new_tab_window_menu/background.js index 5a9a13b6b..57b0cca1a 100644 --- a/apps/terminal/applets/chrome/extensions/disable_new_tab_window_menu/background.js +++ b/apps/terminal/applets/chrome/extensions/disable_new_tab_window_menu/background.js @@ -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); + } + }); }); diff --git a/apps/terminal/applets/chrome/extensions/disable_new_tab_window_menu/content_script.js b/apps/terminal/applets/chrome/extensions/disable_new_tab_window_menu/content_script.js index f51c40254..d1a6bf8ea 100644 --- a/apps/terminal/applets/chrome/extensions/disable_new_tab_window_menu/content_script.js +++ b/apps/terminal/applets/chrome/extensions/disable_new_tab_window_menu/content_script.js @@ -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) { });