mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/StarCitizenBoxBrowserEx.git
synced 2025-05-09 21:51:25 +08:00
feat: add toggle translation functionality
This commit is contained in:
parent
d1f743ac22
commit
7c06708906
@ -155,7 +155,7 @@ function setLocalData(key, data) {
|
||||
chrome.runtime.onInstalled.addListener(function () {
|
||||
chrome.contextMenus.create({
|
||||
id: "translate",
|
||||
title: "翻译本页面",
|
||||
title: "切换翻译",
|
||||
contexts: ["page"]
|
||||
});
|
||||
});
|
||||
@ -163,6 +163,6 @@ chrome.runtime.onInstalled.addListener(function () {
|
||||
chrome.contextMenus.onClicked.addListener((info, tab) => {
|
||||
console.log("contextMenus", info, tab);
|
||||
_initLocalization("manual").then(data => {
|
||||
chrome.tabs.sendMessage(tab.id, {action: "_initTranslation", data});
|
||||
chrome.tabs.sendMessage(tab.id, {action: "_toggleTranslation", data});
|
||||
});
|
||||
});
|
||||
|
84
core.js
84
core.js
@ -1,5 +1,6 @@
|
||||
let SCLocalizationReplaceLocalesMap = {};
|
||||
let SCLocalizationEnableSplitMode = false;
|
||||
let SCLocalizationTranslating = false;
|
||||
|
||||
function InitWebLocalization() {
|
||||
// init script
|
||||
@ -25,7 +26,6 @@ function LocalizationWatchUpdate() {
|
||||
});
|
||||
|
||||
if (window.location.href.includes("robertsspaceindustries.com")) {
|
||||
console.log("SCLocalizationEnableSplitMode = true");
|
||||
SCLocalizationEnableSplitMode = true;
|
||||
}
|
||||
|
||||
@ -51,16 +51,25 @@ function WebLocalizationUpdateReplaceWords(w) {
|
||||
}
|
||||
allTranslate().then(_ => {
|
||||
});
|
||||
// console.log("WebLocalizationUpdateReplaceWords ==" + w)
|
||||
}
|
||||
|
||||
async function allTranslate() {
|
||||
async function replaceTextNode(node1) {
|
||||
if (node1.nodeType === Node.TEXT_NODE) {
|
||||
node1.nodeValue = GetSCLocalizationTranslateString(node1.nodeValue);
|
||||
SCLocalizationTranslating = true;
|
||||
|
||||
async function replaceTextNode(node, parentNode) {
|
||||
if (node.nodeType === Node.TEXT_NODE) {
|
||||
// 保存原始文本内容
|
||||
const originalText = node.nodeValue;
|
||||
const translatedText = GetSCLocalizationTranslateString(originalText);
|
||||
|
||||
// 只有当文本发生变化时才保存原始文本
|
||||
if (originalText !== translatedText) {
|
||||
parentNode.setAttribute('data-original-value', originalText);
|
||||
node.nodeValue = translatedText;
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < node1.childNodes.length; i++) {
|
||||
await replaceTextNode(node1.childNodes[i]);
|
||||
for (let i = 0; i < node.childNodes.length; i++) {
|
||||
await replaceTextNode(node.childNodes[i], node);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,7 +77,36 @@ async function allTranslate() {
|
||||
await replaceTextNode(document.body);
|
||||
}
|
||||
|
||||
async function undoTranslate() {
|
||||
SCLocalizationTranslating = false;
|
||||
|
||||
document.querySelectorAll('*[data-original-value]').forEach(element => {
|
||||
element.innerText = element.getAttribute('data-original-value');
|
||||
element.removeAttribute('data-original-value');
|
||||
});
|
||||
|
||||
// 处理输入元素
|
||||
const inputElements = document.querySelectorAll('input[type="button"], input[type="submit"], input[type="text"], input[type="password"]');
|
||||
inputElements.forEach(el => {
|
||||
// 尝试从 data-original-value 属性恢复原始值
|
||||
if (el.hasAttribute('data-original-value')) {
|
||||
if (el.type === 'button' || el.type === 'submit') {
|
||||
el.value = el.getAttribute('data-original-value');
|
||||
} else {
|
||||
el.placeholder = el.getAttribute('data-original-value');
|
||||
}
|
||||
el.removeAttribute('data-original-value');
|
||||
}
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
function traverseElement(el) {
|
||||
if (!SCLocalizationTranslating) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldTranslateEl(el)) {
|
||||
return
|
||||
}
|
||||
@ -80,12 +118,12 @@ function traverseElement(el) {
|
||||
}
|
||||
|
||||
if (child.nodeType === Node.TEXT_NODE) {
|
||||
translateElement(child);
|
||||
translateElement(child, el);
|
||||
} else if (child.nodeType === Node.ELEMENT_NODE) {
|
||||
if (child.tagName === "INPUT") {
|
||||
translateElement(child);
|
||||
translateElement(child, el);
|
||||
} else {
|
||||
traverseElement(child);
|
||||
traverseElement(child, el);
|
||||
}
|
||||
} else {
|
||||
// pass
|
||||
@ -93,7 +131,7 @@ function traverseElement(el) {
|
||||
}
|
||||
}
|
||||
|
||||
function translateElement(el) {
|
||||
function translateElement(el, parentNode) {
|
||||
// Get the text field name
|
||||
let k;
|
||||
if (el.tagName === "INPUT") {
|
||||
@ -102,8 +140,11 @@ function translateElement(el) {
|
||||
} else {
|
||||
k = 'placeholder';
|
||||
}
|
||||
|
||||
el.setAttribute('data-original-value', el[k]);
|
||||
} else {
|
||||
k = 'data';
|
||||
parentNode.setAttribute('data-original-value', el[k]);
|
||||
}
|
||||
el[k] = GetSCLocalizationTranslateString(el[k]);
|
||||
}
|
||||
@ -189,23 +230,26 @@ InitWebLocalization();
|
||||
|
||||
function _loadLocalizationData() {
|
||||
chrome.runtime.sendMessage({ action: "_loadLocalizationData", url: window.location.href }, function (response) {
|
||||
console.log("response ==" + JSON.stringify(response));
|
||||
WebLocalizationUpdateReplaceWords(response.result);
|
||||
});
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.action === "_initTranslation") {
|
||||
if (request.action === "_toggleTranslation") {
|
||||
if (SCLocalizationTranslating) {
|
||||
SCLocalizationTranslating = false;
|
||||
undoTranslate();
|
||||
return;
|
||||
}
|
||||
SCLocalizationEnableSplitMode = true;
|
||||
WebLocalizationUpdateReplaceWords(request.data);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('message', async (event) => {
|
||||
console.log(event)
|
||||
if (event.source !== window || !event.data || event.data.type !== 'SC_TRANSLATE_REQUEST') return;
|
||||
|
||||
const { action, payload } = event.data;
|
||||
const { action } = event.data;
|
||||
|
||||
let response = { success: false };
|
||||
|
||||
@ -215,17 +259,13 @@ window.addEventListener('message', async (event) => {
|
||||
chrome.runtime.sendMessage({ action: "_loadLocalizationData", url: "manual" }, function (response) {
|
||||
WebLocalizationUpdateReplaceWords(response.result);
|
||||
});
|
||||
response = { success: true };
|
||||
} catch (error) {
|
||||
response = { success: false, error: error.message };
|
||||
}
|
||||
} else if (action === 'updateReplaceWords') {
|
||||
} else if (action === 'undoTranslate') {
|
||||
try {
|
||||
if (payload && payload.words && Array.isArray(payload.words)) {
|
||||
WebLocalizationUpdateReplaceWords(payload.words);
|
||||
response = { success: true };
|
||||
} else {
|
||||
response = { success: false, error: 'Invalid words format' };
|
||||
}
|
||||
response = await undoTranslate();
|
||||
} catch (error) {
|
||||
response = { success: false, error: error.message };
|
||||
}
|
||||
|
2
dist/chrome/background/service_worker.js
vendored
2
dist/chrome/background/service_worker.js
vendored
@ -1 +1 @@
|
||||
(()=>{var e={},t={};function s(r){var n=t[r];if(void 0!==n)return n.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,s),o.exports}s.rv=()=>"1.3.8",s.ruid="bundler=rspack@1.3.8";let r=null;async function n(){r=await a("versions.json"),console.log("Localization Version ==="),console.log(r)}async function o(e){if(console.log("url ==="+e),null==r)return await n(),o(e);let t=r,s={};e.includes("robertsspaceindustries.com")||e.includes("manual")?(s["zh-CN"]=await a("zh-CN-rsi.json",{cacheKey:"zh-CN",version:t.rsi}),s.concierge=await a("concierge.json",{cacheKey:"concierge",version:t.concierge}),s.orgs=await a("orgs.json",t.orgs),s.address=await a("addresses.json",{cacheKey:"orgs",version:t.addresses}),s.hangar=await a("hangar.json",{cacheKey:"hangar",version:t.hangar})):e.includes("uexcorp.space")?s.UEX=await a("zh-CN-uex.json",{cacheKey:"uex",version:t.uex}):e.includes("erkul.games")&&(s.DPS=await a("zh-CN-dps.json",{cacheKey:"dps",version:t.dps}));let c=[];function i(e){c.push(...function(e,t){let s=[],r=e[t];if("object"==typeof r)for(let[e,t]of Object.entries(r)){let r=e.toString().trim().toLowerCase().replace(/\xa0/g," ").replace(/\s{2,}/g," ");s.push({word:r,replacement:t.toString()})}return s}(s,e))}if(e.includes("robertsspaceindustries.com")||e.includes("manual")){if(e.startsWith("https://robertsspaceindustries.com/spectrum/community/"))return;i("zh-CN"),(e.startsWith("https://robertsspaceindustries.com/orgs")||e.startsWith("https://robertsspaceindustries.com/citizens")||e.startsWith("https://robertsspaceindustries.com/account/organization"))&&(c.push({word:"members",replacement:"名成员"}),i("orgs")),e.startsWith("https://robertsspaceindustries.com/account/addresses")&&i("address"),e.startsWith("https://robertsspaceindustries.com/account/referral-program")&&c.push({word:"Total recruits: ",replacement:"总邀请数:"},{word:"Prospects ",replacement:"未完成的邀请"},{word:"Recruits",replacement:"已完成的邀请"}),e.startsWith("https://robertsspaceindustries.com/account/concierge")&&(c=[],i("concierge")),e.startsWith("https://robertsspaceindustries.com/account/pledges")&&i("hangar")}else e.includes("uexcorp.space")?i("UEX"):e.includes("erkul.games")&&i("DPS");return c}async function a(e,{cacheKey:t="",version:s=null}={}){if(url="https://git.scbox.xkeyc.cn/SCToolBox/ScWeb_Chinese_Translate/raw/branch/main/json/locales/"+e,t&&""!==t){let e=await c(`${t}_version`),r=await c(t);if(r&&"object"==typeof r&&Object.keys(r).length>0&&e===s)return r}let r=new Date,n=await fetch(url,{method:"GET",mode:"cors"}),o=new Date,u=await n.json();return t&&""!==t&&(console.log(`update ${t} v == ${s} time == ${(o-r)/1e3}s`),await i(t,u),await i(`${t}_version`,s)),u}function c(e){return new Promise(t=>{chrome.storage.local.get([e],s=>{t(s[e]||null)})})}function i(e,t){return new Promise(s=>{let r={};r[e]=t,chrome.storage.local.set(r,()=>{s()})})}chrome.runtime.onInstalled.addListener(function(){n().then(e=>{}),console.log("SWTT init")}),chrome.runtime.onMessage.addListener(function(e,t,s){if("_loadLocalizationData"===e.action)return o(e.url).then(e=>{s({result:e})}),!0}),chrome.runtime.onInstalled.addListener(function(){chrome.contextMenus.create({id:"translate",title:"翻译本页面",contexts:["page"]})}),chrome.contextMenus.onClicked.addListener((e,t)=>{console.log("contextMenus",e,t),o("manual").then(e=>{chrome.tabs.sendMessage(t.id,{action:"_initTranslation",data:e})})})})();
|
||||
(()=>{var e={},t={};function s(r){var n=t[r];if(void 0!==n)return n.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,s),o.exports}s.rv=()=>"1.3.8",s.ruid="bundler=rspack@1.3.8";let r=null;async function n(){r=await a("versions.json"),console.log("Localization Version ==="),console.log(r)}async function o(e){if(console.log("url ==="+e),null==r)return await n(),o(e);let t=r,s={};e.includes("robertsspaceindustries.com")||e.includes("manual")?(s["zh-CN"]=await a("zh-CN-rsi.json",{cacheKey:"zh-CN",version:t.rsi}),s.concierge=await a("concierge.json",{cacheKey:"concierge",version:t.concierge}),s.orgs=await a("orgs.json",t.orgs),s.address=await a("addresses.json",{cacheKey:"orgs",version:t.addresses}),s.hangar=await a("hangar.json",{cacheKey:"hangar",version:t.hangar})):e.includes("uexcorp.space")?s.UEX=await a("zh-CN-uex.json",{cacheKey:"uex",version:t.uex}):e.includes("erkul.games")&&(s.DPS=await a("zh-CN-dps.json",{cacheKey:"dps",version:t.dps}));let c=[];function i(e){c.push(...function(e,t){let s=[],r=e[t];if("object"==typeof r)for(let[e,t]of Object.entries(r)){let r=e.toString().trim().toLowerCase().replace(/\xa0/g," ").replace(/\s{2,}/g," ");s.push({word:r,replacement:t.toString()})}return s}(s,e))}if(e.includes("robertsspaceindustries.com")||e.includes("manual")){if(e.startsWith("https://robertsspaceindustries.com/spectrum/community/"))return;i("zh-CN"),(e.startsWith("https://robertsspaceindustries.com/orgs")||e.startsWith("https://robertsspaceindustries.com/citizens")||e.startsWith("https://robertsspaceindustries.com/account/organization"))&&(c.push({word:"members",replacement:"名成员"}),i("orgs")),e.startsWith("https://robertsspaceindustries.com/account/addresses")&&i("address"),e.startsWith("https://robertsspaceindustries.com/account/referral-program")&&c.push({word:"Total recruits: ",replacement:"总邀请数:"},{word:"Prospects ",replacement:"未完成的邀请"},{word:"Recruits",replacement:"已完成的邀请"}),e.startsWith("https://robertsspaceindustries.com/account/concierge")&&(c=[],i("concierge")),e.startsWith("https://robertsspaceindustries.com/account/pledges")&&i("hangar")}else e.includes("uexcorp.space")?i("UEX"):e.includes("erkul.games")&&i("DPS");return c}async function a(e,{cacheKey:t="",version:s=null}={}){if(url="https://git.scbox.xkeyc.cn/SCToolBox/ScWeb_Chinese_Translate/raw/branch/main/json/locales/"+e,t&&""!==t){let e=await c(`${t}_version`),r=await c(t);if(r&&"object"==typeof r&&Object.keys(r).length>0&&e===s)return r}let r=new Date,n=await fetch(url,{method:"GET",mode:"cors"}),o=new Date,u=await n.json();return t&&""!==t&&(console.log(`update ${t} v == ${s} time == ${(o-r)/1e3}s`),await i(t,u),await i(`${t}_version`,s)),u}function c(e){return new Promise(t=>{chrome.storage.local.get([e],s=>{t(s[e]||null)})})}function i(e,t){return new Promise(s=>{let r={};r[e]=t,chrome.storage.local.set(r,()=>{s()})})}chrome.runtime.onInstalled.addListener(function(){n().then(e=>{}),console.log("SWTT init")}),chrome.runtime.onMessage.addListener(function(e,t,s){if("_loadLocalizationData"===e.action)return o(e.url).then(e=>{s({result:e})}),!0}),chrome.runtime.onInstalled.addListener(function(){chrome.contextMenus.create({id:"translate",title:"切换翻译",contexts:["page"]})}),chrome.contextMenus.onClicked.addListener((e,t)=>{console.log("contextMenus",e,t),o("manual").then(e=>{chrome.tabs.sendMessage(t.id,{action:"_toggleTranslation",data:e})})})})();
|
2
dist/chrome/content_scripts/content-0.js
vendored
2
dist/chrome/content_scripts/content-0.js
vendored
File diff suppressed because one or more lines are too long
93
dist/firefox/action/default_popup.html
vendored
93
dist/firefox/action/default_popup.html
vendored
@ -1,93 +0,0 @@
|
||||
<!DOCTYPE html><html><head>
|
||||
<meta charset="UTF-8">
|
||||
<title>星际公民盒子浏览器拓展</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.card {
|
||||
border-radius: 8px;
|
||||
background-color: rgba(255, 255, 255, 0.3);
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
width: 250px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.card img,
|
||||
.card svg {
|
||||
height: 60px;
|
||||
width: 60px;
|
||||
}
|
||||
|
||||
.card a {
|
||||
text-decoration: none;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.card h3,
|
||||
.card p {
|
||||
margin: 5px 0;
|
||||
/* 上下间距为5px,左右间距为0 */
|
||||
}
|
||||
|
||||
.card a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="card" style="padding-top: 0; padding-bottom: 0; border-radius: 0;">
|
||||
<a href="https://github.com/xkeyC/StarCitizenBoxBrowserEx" target="_blank">
|
||||
<div>
|
||||
<h2>星际公民盒子浏览器拓展</h2>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<a href="https://robertsspaceindustries.com/" target="_blank">
|
||||
<svg viewBox="0 0 56 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M16.0716 0C17.111 0 17.7697 0.734004 17.5824 1.65153L17.5516 1.77773L16.4646 5.68023C16.2499 6.48564 15.6763 7.15995 14.9845 7.52983L14.8228 7.6097L11.6546 9.08403L12.3485 11.8374C12.4102 12.0494 12.6179 12.227 12.8583 12.2638L12.9497 12.2708H15.0308L14.0135 16H10.7299C9.96799 16 9.22678 15.4621 8.98803 14.8024L8.94926 14.6774L7.95482 10.8185L5.17986 12.1191L4.11629 16H0L4.34743 0H16.0716ZM30.028 0L30.0255 0.00849999L29.0084 3.71374L29.0048 3.72704H29.0004L22.8229 3.71374C22.4538 3.71374 22.1768 3.84407 22.0843 4.19052C22.0024 4.49868 22.1027 4.73832 22.3854 4.94011L22.4999 5.01406L29.1008 9.10927C29.7285 9.49516 30.0921 10.3574 29.9828 11.0527L29.9546 11.1894L29.0084 14.6781C28.8348 15.3511 28.0883 15.9282 27.3084 15.9938L27.1619 16H18.8519L19.8686 12.2728H24.8772C25.2464 12.2728 25.5232 12.0346 25.5925 11.8178C25.6756 11.5644 25.6278 11.3636 25.3483 11.1522L25.2464 11.0812L18.5995 6.92095C17.9719 6.53476 17.6081 5.67281 17.7173 4.97743L17.7455 4.84076L18.6914 1.33023C18.8654 0.657352 19.5912 0.0802618 20.3495 0.0146972L20.492 0.00849999L30.0218 0H30.028ZM34.8758 0L39.0028 0.00849999L34.6207 16H30.4473L34.8566 0.00849999H34.8735L34.8758 0ZM17.698 12.2956L16.6916 16H16.0205L17.0206 12.2956H17.698ZM16.356 12.2956L15.313 16H14.5946L15.6471 12.3028L15.6493 12.2956H16.356ZM19.124 12.2956L18.0887 16H17.3625L18.398 12.2956H19.124ZM12.2017 3.70443H7.46927L6.45853 7.48768L12.0409 4.81988C12.5006 4.60106 12.6614 4.33872 12.7304 4.12006C12.8222 3.83596 12.5694 3.70443 12.2017 3.70443ZM34.1379 0L33.1305 3.70443H32.4604L33.474 0H34.1379ZM32.712 0L31.7062 3.70443H31.0345L32.0511 0H32.712ZM31.3537 0L31.3515 0.00844828H31.37L30.3313 3.69121L30.3277 3.70443H29.6086L29.6121 3.69121L30.6322 0.00844828L30.6346 0H31.3537Z" fill="currentColor"></path>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M44.0993 0.5C45.1052 0.5 45.71 0.718656 46.0714 1.07635C46.4317 1.43287 46.6502 2.02678 46.6502 3.01365C46.6502 4.00008 46.4317 4.58521 46.0739 4.93447C45.7133 5.28641 45.1085 5.5 44.0993 5.5C43.0905 5.5 42.4701 5.28657 42.0962 4.9303C41.7277 4.57908 41.5 3.99382 41.5 3.01365C41.5 2.03297 41.7277 1.43898 42.0987 1.08055C42.4734 0.718531 43.0938 0.5 44.0993 0.5ZM47.1502 3.01365C47.1502 0.918004 46.2283 0 44.0993 0C41.9703 0 41 0.918004 41 3.01365C41 5.10816 41.9703 6 44.0993 6C46.2283 6 47.1502 5.10816 47.1502 3.01365ZM42.7675 1.363C43.2445 1.318 43.717 1.3 44.194 1.3C45.157 1.3 45.4855 1.633 45.4855 2.5105C45.4855 3.154 45.319 3.4555 44.842 3.577L45.607 4.7965C45.643 4.846 45.6205 4.8865 45.553 4.8865H44.725C44.6215 4.8865 44.59 4.855 44.545 4.7875L43.816 3.6355H43.645V4.8145C43.645 4.873 43.6315 4.8865 43.5775 4.8865H42.7675C42.7135 4.8865 42.7 4.873 42.7 4.8145V1.4215C42.7 1.381 42.7135 1.3675 42.7675 1.363ZM44.527 2.542C44.527 2.2495 44.428 2.1235 44.0905 2.1235H43.645V2.9425H44.0905C44.428 2.9425 44.527 2.839 44.527 2.542Z" fill="currentColor"></path>
|
||||
</svg>
|
||||
<h3>星际公民官网</h3>
|
||||
<p>罗伯茨航天工业公司,万物的起源</p>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<a href="https://uexcorp.space" target="_blank">
|
||||
<img src="https://assets.uexcorp.space/img/logo.svg" alt="">
|
||||
<h3>UEX</h3>
|
||||
<p>采矿、精炼、贸易计算器、价格、船信息</p>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<a href="https://www.erkul.games/live/calculator" target="_blank">
|
||||
<img src="https://www.erkul.games/assets/icons/icon-512x512.png">
|
||||
<h3>DPS 计算器</h3>
|
||||
<p>在线改船,查询伤害数值和配件购买地点</p>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<a href="https://ccugame.app" target="_blank">
|
||||
<img src="https://ccugame.app/assets/images/logo/logo.png">
|
||||
<h3>CCUGame(官方汉化)</h3>
|
||||
<p>资产管理和舰队规划,一定要理性消费.jpg</p>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</body></html>
|
1
dist/firefox/background/scripts.js
vendored
1
dist/firefox/background/scripts.js
vendored
@ -1 +0,0 @@
|
||||
(()=>{var e={},t={};function s(r){var n=t[r];if(void 0!==n)return n.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,s),o.exports}s.rv=()=>"1.3.8",s.ruid="bundler=rspack@1.3.8";let r=null;async function n(){r=await a("versions.json"),console.log("Localization Version ==="),console.log(r)}async function o(e){if(console.log("url ==="+e),null==r)return await n(),o(e);let t=r,s={};e.includes("robertsspaceindustries.com")||e.includes("manual")?(s["zh-CN"]=await a("zh-CN-rsi.json",{cacheKey:"zh-CN",version:t.rsi}),s.concierge=await a("concierge.json",{cacheKey:"concierge",version:t.concierge}),s.orgs=await a("orgs.json",t.orgs),s.address=await a("addresses.json",{cacheKey:"orgs",version:t.addresses}),s.hangar=await a("hangar.json",{cacheKey:"hangar",version:t.hangar})):e.includes("uexcorp.space")?s.UEX=await a("zh-CN-uex.json",{cacheKey:"uex",version:t.uex}):e.includes("erkul.games")&&(s.DPS=await a("zh-CN-dps.json",{cacheKey:"dps",version:t.dps}));let c=[];function i(e){c.push(...function(e,t){let s=[],r=e[t];if("object"==typeof r)for(let[e,t]of Object.entries(r)){let r=e.toString().trim().toLowerCase().replace(/\xa0/g," ").replace(/\s{2,}/g," ");s.push({word:r,replacement:t.toString()})}return s}(s,e))}if(e.includes("robertsspaceindustries.com")||e.includes("manual")){if(e.startsWith("https://robertsspaceindustries.com/spectrum/community/"))return;i("zh-CN"),(e.startsWith("https://robertsspaceindustries.com/orgs")||e.startsWith("https://robertsspaceindustries.com/citizens")||e.startsWith("https://robertsspaceindustries.com/account/organization"))&&(c.push({word:"members",replacement:"名成员"}),i("orgs")),e.startsWith("https://robertsspaceindustries.com/account/addresses")&&i("address"),e.startsWith("https://robertsspaceindustries.com/account/referral-program")&&c.push({word:"Total recruits: ",replacement:"总邀请数:"},{word:"Prospects ",replacement:"未完成的邀请"},{word:"Recruits",replacement:"已完成的邀请"}),e.startsWith("https://robertsspaceindustries.com/account/concierge")&&(c=[],i("concierge")),e.startsWith("https://robertsspaceindustries.com/account/pledges")&&i("hangar")}else e.includes("uexcorp.space")?i("UEX"):e.includes("erkul.games")&&i("DPS");return c}async function a(e,{cacheKey:t="",version:s=null}={}){if(url="https://git.scbox.xkeyc.cn/SCToolBox/ScWeb_Chinese_Translate/raw/branch/main/json/locales/"+e,t&&""!==t){let e=await c(`${t}_version`),r=await c(t);if(r&&"object"==typeof r&&Object.keys(r).length>0&&e===s)return r}let r=new Date,n=await fetch(url,{method:"GET",mode:"cors"}),o=new Date,u=await n.json();return t&&""!==t&&(console.log(`update ${t} v == ${s} time == ${(o-r)/1e3}s`),await i(t,u),await i(`${t}_version`,s)),u}function c(e){return new Promise(t=>{chrome.storage.local.get([e],s=>{t(s[e]||null)})})}function i(e,t){return new Promise(s=>{let r={};r[e]=t,chrome.storage.local.set(r,()=>{s()})})}chrome.runtime.onInstalled.addListener(function(){n().then(e=>{}),console.log("SWTT init")}),chrome.runtime.onMessage.addListener(function(e,t,s){if("_loadLocalizationData"===e.action)return o(e.url).then(e=>{s({result:e})}),!0}),chrome.runtime.onInstalled.addListener(function(){chrome.contextMenus.create({id:"translate",title:"翻译本页面",contexts:["page"]})}),chrome.contextMenus.onClicked.addListener((e,t)=>{console.log("contextMenus",e,t),o("manual").then(e=>{chrome.tabs.sendMessage(t.id,{action:"_initTranslation",data:e})})})})();
|
1
dist/firefox/content_scripts/content-0.js
vendored
1
dist/firefox/content_scripts/content-0.js
vendored
File diff suppressed because one or more lines are too long
1
dist/firefox/content_scripts/content-1.js
vendored
1
dist/firefox/content_scripts/content-1.js
vendored
File diff suppressed because one or more lines are too long
1
dist/firefox/content_scripts/content-2.js
vendored
1
dist/firefox/content_scripts/content-2.js
vendored
@ -1 +0,0 @@
|
||||
(()=>{var e={},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.exports}r.rv=()=>"1.3.8",r.ruid="bundler=rspack@1.3.8",function(){function e(t,r,n,o=100){let a=setInterval(()=>{let e=t.querySelector(r);e&&(clearInterval(a),n(e))},o)}function t(e){if(!e||e.parentNode.querySelector('a[data-cy-id="button"][href="/account/pledges"]'))return;let t=e.cloneNode(!0);t.href="/account/pledges";let r=t.querySelector('span[data-cy-id="button__text"]');r&&(r.innerText="My Hangar");let n=t.querySelector('i[data-cy-id="button__icon"]');n&&(n.className="a-button__icon a-icon -gridView"),e.parentNode.insertBefore(t,e)}e(document,"#sidePanel",r=>{new MutationObserver(r=>{for(let n of r)"childList"===n.type&&n.addedNodes.length>0&&n.addedNodes.forEach(r=>{1===r.nodeType&&e(r,'a[data-cy-id="button"][href="/account/settings"]',e=>{t(e)})})}).observe(r,{childList:!0,subtree:!0});let n=sidePanel.querySelector('a[data-cy-id="button"][href="/account/settings"]');n&&t(n)})}()})();
|
BIN
dist/firefox/icons/icon.png
vendored
BIN
dist/firefox/icons/icon.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 12 KiB |
62
dist/firefox/manifest.json
vendored
62
dist/firefox/manifest.json
vendored
@ -1,62 +0,0 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "星际公民盒子浏览器拓展",
|
||||
"version": "0.0.11",
|
||||
"description": "为星际公民网站及工具站提供汉化",
|
||||
"author": "xkeyC",
|
||||
"icons": {
|
||||
"16": "icons/icon.png",
|
||||
"48": "icons/icon.png",
|
||||
"192": "icons/icon.png"
|
||||
},
|
||||
"host_permissions": [
|
||||
"https://git.scbox.xkeyc.cn/*"
|
||||
],
|
||||
"permissions": [
|
||||
"storage",
|
||||
"contextMenus"
|
||||
],
|
||||
"action": {
|
||||
"default_popup": "action/default_popup.html"
|
||||
},
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background/scripts.js"
|
||||
]
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"*://*/*"
|
||||
],
|
||||
"exclude_matches": [
|
||||
"https://robertsspaceindustries.com/spectrum/*"
|
||||
],
|
||||
"js": [
|
||||
"content_scripts/content-0.js"
|
||||
],
|
||||
"run_at": "document_end",
|
||||
"css": []
|
||||
},
|
||||
{
|
||||
"matches": [
|
||||
"https://www.erkul.games/*"
|
||||
],
|
||||
"js": [
|
||||
"content_scripts/content-1.js"
|
||||
],
|
||||
"run_at": "document_end",
|
||||
"css": []
|
||||
},
|
||||
{
|
||||
"matches": [
|
||||
"https://robertsspaceindustries.com/*"
|
||||
],
|
||||
"js": [
|
||||
"content_scripts/content-2.js"
|
||||
],
|
||||
"run_at": "document_idle",
|
||||
"css": []
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user