mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-01-10 21:58:14 +08:00
浏览器设置页面判断兼容edge
This commit is contained in:
parent
729d095745
commit
29fc6921ab
@ -99,9 +99,7 @@ $(function() {
|
|||||||
*/
|
*/
|
||||||
document.getElementById("btnScreenshot").addEventListener("click", () => {
|
document.getElementById("btnScreenshot").addEventListener("click", () => {
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||||
if(isChromeSettingPage(tabs[0].url)) {
|
if(!isBrowserSettingPage({ url: tabs[0].url, action: "截图", showSorryInfo: true })) {
|
||||||
alert("抱歉,由于浏览器限制,“chrome://”开头的网页不支持截图");
|
|
||||||
} else {
|
|
||||||
chrome.extension.getBackgroundPage().takeScreenshot(tabs[0]);
|
chrome.extension.getBackgroundPage().takeScreenshot(tabs[0]);
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
@ -114,9 +112,7 @@ $(function() {
|
|||||||
*/
|
*/
|
||||||
document.getElementById("transform").onclick = function () {
|
document.getElementById("transform").onclick = function () {
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||||
if(isChromeSettingPage(tabs[0].url)) {
|
if(!isBrowserSettingPage({ url: tabs[0].url, action: "翻译", showSorryInfo: true })) {
|
||||||
alert("抱歉,由于浏览器限制,“chrome://”开头的网页不支持翻译");
|
|
||||||
} else {
|
|
||||||
chrome.extension.getBackgroundPage().showTranslationWindow()
|
chrome.extension.getBackgroundPage().showTranslationWindow()
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
@ -157,12 +153,24 @@ $(function() {
|
|||||||
// ****************************************************************************************************************
|
// ****************************************************************************************************************
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否是 chrome:// 开头的链接
|
* 判断是否是浏览器设置页面
|
||||||
|
* 即是否是 chrome:// 或 edge:// 开头的链接
|
||||||
* @param {} url
|
* @param {} url
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function isChromeSettingPage(url) {
|
function isBrowserSettingPage({url, action, showSorryInfo = true }) {
|
||||||
return /^chrome:\/\/.*$/.test(url);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user