Skip to content

Commit

Permalink
update dist
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 27, 2023
1 parent 0e3cce4 commit 0b10884
Show file tree
Hide file tree
Showing 19 changed files with 421 additions and 349 deletions.
14 changes: 7 additions & 7 deletions dist/chrome/background.js

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions dist/chrome/content_script.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/chrome/libs/foliate-js/make.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/chrome/libs/subtitle/subtitle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "__MSG_brandName__",
"description": "__MSG_brandDescription__",
"version": "0.7.13",
"version": "0.7.14",
"default_locale": "en",
"background": {
"service_worker": "background.js"
Expand Down
70 changes: 35 additions & 35 deletions dist/chrome/options.js

Large diffs are not rendered by default.

88 changes: 62 additions & 26 deletions dist/chrome/pdf/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
window.addEventListener("unhandledrejection", noHandleError);

function noHandleError(event) {
const message = typeof event.reason == "object" ? event.reason.message : event.reason;
const message = typeof event.reason == "object"
? event.reason.message
: event.reason;
if (message.indexOf("Missing PDF") >= 0) {
const ele = document.createElement("div");
ele.innerHTML = `
Expand All @@ -19,8 +21,8 @@ function noHandleError(event) {
</div>
<div>或者拖拽文件到此窗口导入</div>
</div>
`
const viewer = document.querySelector("#viewer")
`;
const viewer = document.querySelector("#viewer");
if (!viewer) return;
viewer.appendChild(ele);
}
Expand All @@ -39,23 +41,28 @@ window.addEventListener("DOMContentLoaded", function () {

const pdfBytes = await blob.arrayBuffer();
const pdfDoc = await PDFLib.PDFDocument.load(pdfBytes, {
updateMetadata: false
})
updateMetadata: false,
});

await handlePdf(pdfDoc);
if (cancelDialog) return;
const newPdfBytes = await pdfDoc.save()
oldDownload(new Blob([newPdfBytes], { type: "application/pdf" }), url, filename.replace(".pdf", "-tranlsated.pdf"), options);
}
const newPdfBytes = await pdfDoc.save();
oldDownload(
new Blob([newPdfBytes], { type: "application/pdf" }),
url,
filename.replace(".pdf", "-tranlsated.pdf"),
options,
);
};
startDownload = startDownload.bind(downloadManager);
showModal();
} catch (error) {
alert(error.message);
console.error(error);
}
}
};
}, 1000);
})
});

async function handlePdf(pdfDoc) {
try {
Expand All @@ -76,7 +83,9 @@ async function handlePdf(pdfDoc) {
sizeMap[`${width}-${height}`] = newPdfDoc.getPages().length - 1;
}

const [newPage] = await pdfDoc.copyPages(newPdfDoc, [sizeMap[`${width}-${height}`]]);
const [newPage] = await pdfDoc.copyPages(newPdfDoc, [
sizeMap[`${width}-${height}`],
]);
await drawElemetnToPage(pdfDoc, element, newPage);
pdfDoc.insertPage(pageNum * 2 + 1, newPage);
updateProgress(i + 1);
Expand All @@ -95,6 +104,7 @@ function showModal() {
const elements = document.querySelectorAll(".immersive-translate-page");
cancelDialog = false;
let dialog = document.getElementById("immersive-modal");
const disableDownload = isSafari();
if (!dialog) {
dialog = document.createElement("div");
dialog.id = "immersive-modal";
Expand All @@ -111,23 +121,36 @@ function showModal() {
<div class="immersive-translate-btn-warpper"><div class="immersive-translate-btn immersive-gary" data-action="close">取消</div><div class="immersive-translate-btn" id="immersive-download">确定下载</div></div>
</div>
`;
if (disableDownload) {
dialog.innerHTML = `
<div class="immersive-translate-modal-content">
<span data-action="close" class="immersive-translate-close">&times;</span>
<p>抱歉,Safari 对插件导出文件有限制,暂时无法导出,请使用其他浏览器替代。</p>
<div class="immersive-translate-btn-warpper"><div class="immersive-translate-btn immersive-gary" data-action="close">取消</div></div>
</div>
`;
}
document.body.appendChild(dialog);
const elements = document.querySelectorAll("[data-action='close']")
const elements = document.querySelectorAll("[data-action='close']");
const closeFun = () => {
cancelDialog = true;
closeModal();
};
elements.forEach(item => item.onclick = closeFun);
const downloadBtn = document.getElementById("immersive-download");
downloadBtn.onclick = () => {
if (downloadBtn.classList.contains("immersive-disable")) return;
startDownload?.();
downloadBtn.classList.add("immersive-disable");
elements.forEach((item) => item.onclick = closeFun);
if (!disableDownload) {
const downloadBtn = document.getElementById("immersive-download");
downloadBtn.onclick = () => {
if (downloadBtn.classList.contains("immersive-disable")) return;
startDownload?.();
downloadBtn.classList.add("immersive-disable");
};
}
}
const currentStateDOM = document.getElementById("immersive-state");
currentStateDOM.innerHTML = `已翻译 <b>${elements.length}</b> 页 / 总共 ${pagesCount} 页`;
dialog.style.display = "block";
if (disableDownload) return;
const currentStateDOM = document.getElementById("immersive-state");
currentStateDOM.innerHTML =
`已翻译 <b>${elements.length}</b> 页 / 总共 ${pagesCount} 页`;
const downloadBtn = document.getElementById("immersive-download");
downloadBtn.classList.remove("immersive-disable");
}
Expand All @@ -140,7 +163,9 @@ function closeModal() {
}

function updateProgress(value) {
const container = document.querySelector(".immersive-translate-progress-container");
const container = document.querySelector(
".immersive-translate-progress-container",
);
if (!container) return;
container.style.display = "block";
const elements = document.querySelectorAll(".immersive-translate-page");
Expand All @@ -149,7 +174,9 @@ function updateProgress(value) {
}

function hiddenProgress() {
const container = document.querySelector(".immersive-translate-progress-container");
const container = document.querySelector(
".immersive-translate-progress-container",
);
if (!container) return;
updateProgress(0);
container.style.display = "none";
Expand All @@ -159,9 +186,7 @@ async function drawElemetnToPage(pdfDoc, element, page) {
const canvas = await html2canvas(element);
const imageData = canvas.toDataURL("image/png");
const pngUrl = imageData.split(",")[1];
const pngImageBytes = Uint8Array.from(atob(pngUrl), (c) =>
c.charCodeAt(0)
);
const pngImageBytes = Uint8Array.from(atob(pngUrl), (c) => c.charCodeAt(0));
const pngImage = await pdfDoc.embedPng(pngImageBytes);
const { width, height } = page.getSize();
page.drawImage(pngImage, {
Expand All @@ -170,4 +195,15 @@ async function drawElemetnToPage(pdfDoc, element, page) {
width: width,
height: height,
});
}
}

function isSafari() {
const userAgentString = navigator.userAgent;
// Detect Chrome
const chromeAgent = userAgentString.indexOf("Chrome") > -1;
// Detect Safari
let safariAgent = userAgentString.indexOf("Safari") > -1;
// Discard Safari since it also matches Chrome
if (chromeAgent && safariAgent) safariAgent = false;
return safariAgent;
}
64 changes: 32 additions & 32 deletions dist/chrome/popup.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/firefox/background.js

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions dist/firefox/content_script.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/firefox/libs/foliate-js/make.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/firefox/libs/subtitle/subtitle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_brandName__",
"description": "__MSG_brandDescription__",
"version": "0.7.13",
"version": "0.7.14",
"default_locale": "en",
"background": {
"scripts": [
Expand Down
70 changes: 35 additions & 35 deletions dist/firefox/options.js

Large diffs are not rendered by default.

88 changes: 62 additions & 26 deletions dist/firefox/pdf/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
window.addEventListener("unhandledrejection", noHandleError);

function noHandleError(event) {
const message = typeof event.reason == "object" ? event.reason.message : event.reason;
const message = typeof event.reason == "object"
? event.reason.message
: event.reason;
if (message.indexOf("Missing PDF") >= 0) {
const ele = document.createElement("div");
ele.innerHTML = `
Expand All @@ -19,8 +21,8 @@ function noHandleError(event) {
</div>
<div>或者拖拽文件到此窗口导入</div>
</div>
`
const viewer = document.querySelector("#viewer")
`;
const viewer = document.querySelector("#viewer");
if (!viewer) return;
viewer.appendChild(ele);
}
Expand All @@ -39,23 +41,28 @@ window.addEventListener("DOMContentLoaded", function () {

const pdfBytes = await blob.arrayBuffer();
const pdfDoc = await PDFLib.PDFDocument.load(pdfBytes, {
updateMetadata: false
})
updateMetadata: false,
});

await handlePdf(pdfDoc);
if (cancelDialog) return;
const newPdfBytes = await pdfDoc.save()
oldDownload(new Blob([newPdfBytes], { type: "application/pdf" }), url, filename.replace(".pdf", "-tranlsated.pdf"), options);
}
const newPdfBytes = await pdfDoc.save();
oldDownload(
new Blob([newPdfBytes], { type: "application/pdf" }),
url,
filename.replace(".pdf", "-tranlsated.pdf"),
options,
);
};
startDownload = startDownload.bind(downloadManager);
showModal();
} catch (error) {
alert(error.message);
console.error(error);
}
}
};
}, 1000);
})
});

async function handlePdf(pdfDoc) {
try {
Expand All @@ -76,7 +83,9 @@ async function handlePdf(pdfDoc) {
sizeMap[`${width}-${height}`] = newPdfDoc.getPages().length - 1;
}

const [newPage] = await pdfDoc.copyPages(newPdfDoc, [sizeMap[`${width}-${height}`]]);
const [newPage] = await pdfDoc.copyPages(newPdfDoc, [
sizeMap[`${width}-${height}`],
]);
await drawElemetnToPage(pdfDoc, element, newPage);
pdfDoc.insertPage(pageNum * 2 + 1, newPage);
updateProgress(i + 1);
Expand All @@ -95,6 +104,7 @@ function showModal() {
const elements = document.querySelectorAll(".immersive-translate-page");
cancelDialog = false;
let dialog = document.getElementById("immersive-modal");
const disableDownload = isSafari();
if (!dialog) {
dialog = document.createElement("div");
dialog.id = "immersive-modal";
Expand All @@ -111,23 +121,36 @@ function showModal() {
<div class="immersive-translate-btn-warpper"><div class="immersive-translate-btn immersive-gary" data-action="close">取消</div><div class="immersive-translate-btn" id="immersive-download">确定下载</div></div>
</div>
`;
if (disableDownload) {
dialog.innerHTML = `
<div class="immersive-translate-modal-content">
<span data-action="close" class="immersive-translate-close">&times;</span>
<p>抱歉,Safari 对插件导出文件有限制,暂时无法导出,请使用其他浏览器替代。</p>
<div class="immersive-translate-btn-warpper"><div class="immersive-translate-btn immersive-gary" data-action="close">取消</div></div>
</div>
`;
}
document.body.appendChild(dialog);
const elements = document.querySelectorAll("[data-action='close']")
const elements = document.querySelectorAll("[data-action='close']");
const closeFun = () => {
cancelDialog = true;
closeModal();
};
elements.forEach(item => item.onclick = closeFun);
const downloadBtn = document.getElementById("immersive-download");
downloadBtn.onclick = () => {
if (downloadBtn.classList.contains("immersive-disable")) return;
startDownload?.();
downloadBtn.classList.add("immersive-disable");
elements.forEach((item) => item.onclick = closeFun);
if (!disableDownload) {
const downloadBtn = document.getElementById("immersive-download");
downloadBtn.onclick = () => {
if (downloadBtn.classList.contains("immersive-disable")) return;
startDownload?.();
downloadBtn.classList.add("immersive-disable");
};
}
}
const currentStateDOM = document.getElementById("immersive-state");
currentStateDOM.innerHTML = `已翻译 <b>${elements.length}</b> 页 / 总共 ${pagesCount} 页`;
dialog.style.display = "block";
if (disableDownload) return;
const currentStateDOM = document.getElementById("immersive-state");
currentStateDOM.innerHTML =
`已翻译 <b>${elements.length}</b> 页 / 总共 ${pagesCount} 页`;
const downloadBtn = document.getElementById("immersive-download");
downloadBtn.classList.remove("immersive-disable");
}
Expand All @@ -140,7 +163,9 @@ function closeModal() {
}

function updateProgress(value) {
const container = document.querySelector(".immersive-translate-progress-container");
const container = document.querySelector(
".immersive-translate-progress-container",
);
if (!container) return;
container.style.display = "block";
const elements = document.querySelectorAll(".immersive-translate-page");
Expand All @@ -149,7 +174,9 @@ function updateProgress(value) {
}

function hiddenProgress() {
const container = document.querySelector(".immersive-translate-progress-container");
const container = document.querySelector(
".immersive-translate-progress-container",
);
if (!container) return;
updateProgress(0);
container.style.display = "none";
Expand All @@ -159,9 +186,7 @@ async function drawElemetnToPage(pdfDoc, element, page) {
const canvas = await html2canvas(element);
const imageData = canvas.toDataURL("image/png");
const pngUrl = imageData.split(",")[1];
const pngImageBytes = Uint8Array.from(atob(pngUrl), (c) =>
c.charCodeAt(0)
);
const pngImageBytes = Uint8Array.from(atob(pngUrl), (c) => c.charCodeAt(0));
const pngImage = await pdfDoc.embedPng(pngImageBytes);
const { width, height } = page.getSize();
page.drawImage(pngImage, {
Expand All @@ -170,4 +195,15 @@ async function drawElemetnToPage(pdfDoc, element, page) {
width: width,
height: height,
});
}
}

function isSafari() {
const userAgentString = navigator.userAgent;
// Detect Chrome
const chromeAgent = userAgentString.indexOf("Chrome") > -1;
// Detect Safari
let safariAgent = userAgentString.indexOf("Safari") > -1;
// Discard Safari since it also matches Chrome
if (chromeAgent && safariAgent) safariAgent = false;
return safariAgent;
}
64 changes: 32 additions & 32 deletions dist/firefox/popup.js

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions dist/userscript/immersive-translate.user.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
value=""
/>
</div>
<script src="./options.js?v=02624b4a8174c3a9f35352ba48bf19dad3f776e139e6144a8abfa361b02c3649"></script>
<script src="./options.js?v=f012ff29c7dcf26294838749ee0e0934ce68aa2a1df6a057f9ace0985f4acb07"></script>
</body>
</html>
68 changes: 34 additions & 34 deletions docs/options/options.js

Large diffs are not rendered by default.

0 comments on commit 0b10884

Please sign in to comment.