From 29fc6921ab1d2964635ea8ab529ff68aaf70d07b Mon Sep 17 00:00:00 2001 From: Coding Zhang <2291200076@qq.com> Date: Sat, 12 Feb 2022 01:12:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=88=A4=E6=96=AD=E5=85=BC=E5=AE=B9edge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/shell-chrome/assets/js/popup.js | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/shell-chrome/assets/js/popup.js b/packages/shell-chrome/assets/js/popup.js index 14994ee..d266512 100644 --- a/packages/shell-chrome/assets/js/popup.js +++ b/packages/shell-chrome/assets/js/popup.js @@ -99,9 +99,7 @@ $(function() { */ document.getElementById("btnScreenshot").addEventListener("click", () => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { - if(isChromeSettingPage(tabs[0].url)) { - alert("抱歉,由于浏览器限制,“chrome://”开头的网页不支持截图"); - } else { + if(!isBrowserSettingPage({ url: tabs[0].url, action: "截图", showSorryInfo: true })) { chrome.extension.getBackgroundPage().takeScreenshot(tabs[0]); window.close(); } @@ -114,9 +112,7 @@ $(function() { */ document.getElementById("transform").onclick = function () { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { - if(isChromeSettingPage(tabs[0].url)) { - alert("抱歉,由于浏览器限制,“chrome://”开头的网页不支持翻译"); - } else { + if(!isBrowserSettingPage({ url: tabs[0].url, action: "翻译", showSorryInfo: true })) { chrome.extension.getBackgroundPage().showTranslationWindow() window.close(); } @@ -157,12 +153,24 @@ $(function() { // **************************************************************************************************************** /** - * 判断是否是 chrome:// 开头的链接 + * 判断是否是浏览器设置页面 + * 即是否是 chrome:// 或 edge:// 开头的链接 * @param {} url * @returns */ - function isChromeSettingPage(url) { - return /^chrome:\/\/.*$/.test(url); + function isBrowserSettingPage({url, action, showSorryInfo = true }) { + var protocol, isSettingPage = true; + if(/^chrome:\/\/.*$/.test(url)) { + protocol = "chrome://" + } else if(/^edge:\/\/.*$/.test(url)) { + protocol = "edge://" + } else { + isSettingPage = false; + } + if(showSorryInfo && isSettingPage) { + alert(`十分抱歉,由于浏览器限制,“${protocol}”开头的网站不支持${action}`); + } + return isSettingPage; } /**