mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-01-10 21:58:14 +08:00
主面板翻译和截图使用前先判断是不是chrome://开头网页;翻译的后台代码独立成单独文件;Google广告屏蔽前如果是chrome://开头网页则跳过
This commit is contained in:
parent
afb773faa3
commit
fdfce0b77c
@ -48,13 +48,3 @@ chrome.contextMenus.create({
|
||||
showNotification()
|
||||
}
|
||||
})
|
||||
|
||||
function tranBit(){
|
||||
console.log("开始插入翻译页面")
|
||||
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
console.log(tabs)
|
||||
chrome.tabs.executeScript(tabs[0].id, { file:'./assets/js/translate/tran.js', runAt: 'document_start' })
|
||||
chrome.tabs.insertCSS(tabs[0].id, { file:'./assets/css/tran.css', runAt: 'document_start' })
|
||||
})
|
||||
}
|
@ -83,9 +83,13 @@ $(function() {
|
||||
// 截图
|
||||
document.getElementById("btnScreenshot").addEventListener("click", () => {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
if(isChromeSettingPage(tabs[0].url)) {
|
||||
alert("抱歉,由于浏览器限制,“chrome://”开头的网页不支持截图");
|
||||
} else {
|
||||
chrome.extension.getBackgroundPage().takeScreenshot(tabs[0]);
|
||||
})
|
||||
window.close();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// 番茄钟
|
||||
@ -102,4 +106,25 @@ $(function() {
|
||||
$('#back').css("display", "none");
|
||||
chrome.storage.sync.set({ "clockState": "none" });
|
||||
})
|
||||
|
||||
//翻译
|
||||
document.getElementById("transform").onclick = function () {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
if(isChromeSettingPage(tabs[0].url)) {
|
||||
alert("抱歉,由于浏览器限制,“chrome://”开头的网页不支持翻译");
|
||||
} else {
|
||||
chrome.extension.getBackgroundPage().showTranslationWindow()
|
||||
window.close();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是 chrome:// 开头的链接
|
||||
* @param {} url
|
||||
* @returns
|
||||
*/
|
||||
function isChromeSettingPage(url) {
|
||||
return /^chrome:\/\/.*$/.test(url);
|
||||
}
|
||||
})
|
||||
|
@ -89,12 +89,3 @@ document.getElementById("weatherSite").onclick = function() {
|
||||
}
|
||||
|
||||
//天气end
|
||||
|
||||
//翻译
|
||||
//默认参数
|
||||
document.getElementById("transform").onclick = function () {
|
||||
console.log(chrome.extension.getBackgroundPage())
|
||||
chrome.extension.getBackgroundPage().tranBit()
|
||||
window.close();
|
||||
}
|
||||
//翻译end
|
||||
|
@ -1,6 +1,8 @@
|
||||
// refer: https://www.it1352.com/1996113.html
|
||||
chrome.webRequest.onBeforeRequest.addListener(
|
||||
function (details) {
|
||||
if (!details || !details.initiator || !details.url)
|
||||
return { cancel: false }; // 如果没有请求信息,则可能是chrome://开头的页面,不处理
|
||||
let isBlock = false
|
||||
|| details.initiator === "https://googleads.g.doubleclick.net"
|
||||
|| details.initiator.indexOf("googleads.g.doubleclick.net") != -1
|
||||
|
7
packages/shell-chrome/assets/js/translate/background.js
Normal file
7
packages/shell-chrome/assets/js/translate/background.js
Normal file
@ -0,0 +1,7 @@
|
||||
// 翻译功能
|
||||
function showTranslationWindow() {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
chrome.tabs.executeScript(tabs[0].id, { file: './assets/js/translate/tran.js', runAt: 'document_start' })
|
||||
chrome.tabs.insertCSS(tabs[0].id, { file: './assets/css/tran.css', runAt: 'document_start' })
|
||||
})
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
"scripts": [
|
||||
"assets/js/lib/jquery.min.js",
|
||||
"assets/js/background.js",
|
||||
"assets/js/translate/background.js",
|
||||
"assets/js/remove-google-ads/background_preventAdsScript.js",
|
||||
"assets/html/pomodoro/background.js",
|
||||
"assets/js/advanced-search/background.js",
|
||||
|
Loading…
Reference in New Issue
Block a user