Skip to content

Commit

Permalink
Correções e melhorias
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipePS committed May 18, 2023
1 parent 5173bf0 commit e7ba73d
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 19 deletions.
19 changes: 12 additions & 7 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,18 @@ if (typeof chrome.contextMenus !== "undefined") {

chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId == "translate-web-page") {
chrome.tabs.sendMessage(
tab.id,
{
action: "toggle-translation",
},
checkedLastError
);
const mimeType = tabToMimeType[tab.id];
if (mimeType && mimeType.toLowerCase() === "application/pdf" && chrome.pageAction && chrome.pageAction.openPopup) {
chrome.pageAction.openPopup();
} else {
chrome.tabs.sendMessage(
tab.id,
{
action: "toggle-translation",
},
checkedLastError
);
}
} else if (info.menuItemId == "translate-selected-text") {
if (
chrome.pageAction &&
Expand Down
25 changes: 20 additions & 5 deletions src/contentScript/pageTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ Promise.all([twpConfig.onReady(), getTabHostName()]).then(function (_) {
const htmlTagsInlineIgnore = ["br", "code", "kbd", "wbr"]; // and input if type is submit or button, and <pre> depending on settings
const htmlTagsNoTranslate = ["title", "script", "style", "textarea", "svg"];

if (location.hostname === "pdf.translatewebpages.org") {
const index = htmlTagsInlineText.indexOf("span");
if (index !== -1) {
htmlTagsInlineText.splice(index, 1);
}
}

if (twpConfig.get("translateTag_pre") !== "yes") {
htmlTagsInlineIgnore.push("pre");
}
Expand Down Expand Up @@ -762,7 +769,7 @@ Promise.all([twpConfig.onReady(), getTabHostName()]).then(function (_) {
} else {
node.textContent = text;
}
};
}

function translateResults(piecesToTranslateNow, results) {
if (dontSortResults) {
Expand Down Expand Up @@ -1199,7 +1206,11 @@ Promise.all([twpConfig.onReady(), getTabHostName()]).then(function (_) {
if (result === "und") {
originalTabLanguage = result;
if (
twpConfig.get("alwaysTranslateSites").indexOf(tabHostName) !== -1
twpConfig.get("alwaysTranslateSites").indexOf(tabHostName) !==
-1 ||
(location.hostname === "pdf.translatewebpages.org" &&
twpConfig.get("neverTranslateSites").indexOf(tabHostName) ===
-1)
) {
pageTranslator.translatePage();
}
Expand All @@ -1209,9 +1220,13 @@ Promise.all([twpConfig.onReady(), getTabHostName()]).then(function (_) {
originalTabLanguage = langCode;
}
if (
location.hostname === "translatewebpages.org" &&
location.href.indexOf("?autotranslate") !== -1 &&
twpConfig.get("neverTranslateSites").indexOf(tabHostName) === -1
(location.hostname === "translatewebpages.org" &&
location.href.indexOf("?autotranslate") !== -1 &&
twpConfig.get("neverTranslateSites").indexOf(tabHostName) ===
-1) ||
(location.hostname === "pdf.translatewebpages.org" &&
twpConfig.get("neverTranslateSites").indexOf(tabHostName) ===
-1)
) {
pageTranslator.translatePage();
} else {
Expand Down
19 changes: 18 additions & 1 deletion src/options/release-notes/en.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ <h4>9.8 - June 1, 2023</h4>
<ul>
<li>Release notes since version 1.0</li>
<li>Added option to set extension UI language</li>
<li>A new way to translate <b>PDF</b>
<ol>
<li>Open website <a href="https://pdf.translatewebpages.org" target="_blank">pdf.translatewebpages.org</a></li>
<li>Select or drag and drop a PDF file</li>
<li>The translation will start immediately and happen dynamically as you scroll through the page</li>
</ol>
</li>
<li><b>Improve translation</b> button in page translation panel, with the options:
<ul>
<li>Select the original website language</li>
Expand Down Expand Up @@ -57,12 +64,22 @@ <h4>9.8 - June 1, 2023</h4>
</li>
</ul>
</li>
<li>Changes
<ul>
<li>Nodes modified by <i>jiffyreader</i> will not be translated</li>
<li>Links in Twitter posts will not be translated to improve translation quality</li>
<li>When translating selected text on PDF and other restrictive websites, you now have the option to listen to the original text as well</li>
</ul>
</li>
<li>Fixed
<ul>
<li>Gitako doesn't work with TWP</li>
<!-- <li>Gitako doesn't work with TWP</li> -->
<li>Selected text translation not working in other extensions popup</li>
<li>Layout breaks on some <i>Wikipedia</i> pages when the <i><code>Do not sort translation results</code></i> option is enabled</li>
<li>Keep whitespace in textNodes to prevent the translation from getting truncated</li>
</ul>
</li>
<li>Bug fixes and general improvements</li>
<li>Update interface translations</li>
</ul>
</section>
Expand Down
6 changes: 0 additions & 6 deletions src/popup/detect-pdf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0].url.toLowerCase().endsWith(".pdf")) {
window.location = "popup-translate-document.html";
}
});

chrome.runtime.sendMessage({ action: "getTabMimeType" }, (mimeType) => {
checkedLastError();

Expand Down
1 change: 1 addition & 0 deletions src/popup/old-popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<option value="moreOptions" data-i18n="btnMoreOptions">
More options
</option>
<option value="translatePDF" data-i18n="msgTranslatePDF">Translate PDF</option>
<option value="donate" data-i18n="btnDonate">Donate</option>
</select>
<div id="btnOptionB" style="
Expand Down
5 changes: 5 additions & 0 deletions src/popup/old-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,11 @@ twpConfig.onReady().then(() => twpI18n.updateUiMessages()).then(() => {
url: chrome.runtime.getURL("/options/options.html#donation"),
});
break;
case "translatePDF":
chrome.tabs.create({
url: "https://pdf.translatewebpages.org/",
});
break;
default:
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/popup/popup-translate-document.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
<div class="servicebutton" id="googletranslate" data-name="google">
translate.google.com
</div>
<div class="servicebutton" id="deepltranslate" data-name="deepl">
deepl.com
</div>
<div class="servicebutton" id="onlinedoctranslator" data-name="onlinedoctranslator">
onlinedoctranslator.com
</div>
</div>
<div style="margin: 13px; display: none" id="cannotusegoogle"></div>
<div id="send" style="display: none" data-i18n="msgOpenTranslated" class="sendbutton">
Expand Down
7 changes: 7 additions & 0 deletions src/popup/popup-translate-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ selectService.onclick = async (e) => {
"_blank"
);
window.close();
} else if (e.target.dataset.name === "deepl") {
window.open("https://www.deepl.com/translator/files", "_blank");
} else if (e.target.dataset.name === "onlinedoctranslator") {
window.open(
"https://www.onlinedoctranslator.com/translationform",
"_blank"
);
} else if (e.target.dataset.name === "pdftwp") {
window.open("https://pdf.translatewebpages.org", "_blank");
window.close();
Expand Down
1 change: 1 addition & 0 deletions src/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<option data-i18n="btnOpenOnGoogleTranslate" value="translateInExternalSite">Open in google translate
</option>
<option data-i18n="btnMoreOptions" value="moreOptions">More options</option>
<option data-i18n="msgTranslatePDF" value="translatePDF">Translate PDF</option>
<option data-i18n="btnDonate" value="donate">Donate</option>
</select>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,11 @@ twpConfig.onReady().then(() => twpI18n.updateUiMessages()).then(() => {
url: chrome.runtime.getURL("/options/options.html#donation"),
});
break;
case "translatePDF":
chrome.tabs.create({
url: "https://pdf.translatewebpages.org/",
});
break;
default:
break;
}
Expand Down

0 comments on commit e7ba73d

Please sign in to comment.