mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/StarCitizenBoxBrowserEx.git
synced 2025-07-19 12:54:45 +08:00
feat: add context menu for translating pages
This commit is contained in:
@ -151,3 +151,16 @@ function setLocalData(key, data) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chrome.contextMenus.create({
|
||||||
|
id: "translate",
|
||||||
|
title: "翻译本页面",
|
||||||
|
contexts: ["page"]
|
||||||
|
});
|
||||||
|
|
||||||
|
chrome.contextMenus.onClicked.addListener((info, tab) => {
|
||||||
|
console.log("contextMenus", info, tab);
|
||||||
|
_initLocalization("manual").then(data => {
|
||||||
|
chrome.tabs.sendMessage(tab.id, {action: "_initTranslation", data});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -193,6 +193,13 @@ function _loadLocalizationData() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
|
if (request.action === "_initTranslation") {
|
||||||
|
SCLocalizationEnableSplitMode = true;
|
||||||
|
WebLocalizationUpdateReplaceWords(request.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 注入脚本到网页上下文
|
// 注入脚本到网页上下文
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.src = chrome.runtime.getURL('injected.js');
|
script.src = chrome.runtime.getURL('injected.js');
|
||||||
|
@ -5,13 +5,16 @@
|
|||||||
"description": "为星际公民网站及工具站提供汉化",
|
"description": "为星际公民网站及工具站提供汉化",
|
||||||
"author": "xkeyC",
|
"author": "xkeyC",
|
||||||
"icons": {
|
"icons": {
|
||||||
|
"16": "icon.png",
|
||||||
|
"48": "icon.png",
|
||||||
"192": "icon.png"
|
"192": "icon.png"
|
||||||
},
|
},
|
||||||
"host_permissions": [
|
"host_permissions": [
|
||||||
"https://git.scbox.xkeyc.cn/*"
|
"https://git.scbox.xkeyc.cn/*"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage"
|
"storage",
|
||||||
|
"contextMenus"
|
||||||
],
|
],
|
||||||
"action": {
|
"action": {
|
||||||
"default_popup": "popup.html"
|
"default_popup": "popup.html"
|
||||||
@ -22,10 +25,6 @@
|
|||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": [
|
"matches": [
|
||||||
"https://robertsspaceindustries.com/*",
|
|
||||||
"https://*.robertsspaceindustries.com/*",
|
|
||||||
"https://www.erkul.games/*",
|
|
||||||
"https://uexcorp.space/*",
|
|
||||||
"*://*/*"
|
"*://*/*"
|
||||||
],
|
],
|
||||||
"exclude_matches": [
|
"exclude_matches": [
|
||||||
|
Reference in New Issue
Block a user