Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
support producthunt, gmail, sidekick
Browse files Browse the repository at this point in the history
  • Loading branch information
theowenyoung committed Nov 12, 2022
1 parent 32eb2a9 commit bc1139b
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 0.0.23

- Support mail.google.com
- Support Sidekick browser
- Support Producthunt

## 0.0.19.2

- Support nature.com
Expand Down
2 changes: 1 addition & 1 deletion src/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"message": "翻译中..."
},
"lblTranslated": {
"message": "译文"
"message": "已翻译"
},
"lblError": {
"message": "无法翻译此页面"
Expand Down
6 changes: 5 additions & 1 deletion src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
chrome.tabs.sendMessage(sender.tab.id, {action: "anotherFrameIsInFocus"}, checkedLastError)
} else if (request.action === "getTabMimeType") {
chrome.tabs.query({active: true, currentWindow: true}, tabs => {
sendResponse(tabToMimeType[tabs[0].id])
if(tabs && tabs.length > 0) {
sendResponse(tabToMimeType[tabs[0].id])
}else{
sendResponse(null)
}
})
return true
}else if(request.action ==='detectLanguage'){
Expand Down
6 changes: 5 additions & 1 deletion src/background/chrome_background.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
chrome.tabs.sendMessage(sender.tab.id, {action: "anotherFrameIsInFocus"}, checkedLastError)
} else if (request.action === "getTabMimeType") {
chrome.tabs.query({active: true, currentWindow: true}, tabs => {
sendResponse(tabToMimeType[tabs[0].id])
if(tabs && tabs.length > 0) {
sendResponse(tabToMimeType[tabs[0].id])
}else{
sendResponse(null)
}
})
return true
}else if(request.action ==='detectLanguage'){
Expand Down
2 changes: 1 addition & 1 deletion src/chrome_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"default_locale": "en",
"name": "Immersive Translate",
"description": "Let's experience immersive web translation, with bilingual simultaneous display and translation of only the important content.",
"version": "0.0.22.1",
"version": "0.0.23",
"homepage_url": "https://github.com/immersive-translate/immersive-translate",

"commands": {
Expand Down
18 changes: 17 additions & 1 deletion src/contentScript/enhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const enhanceOriginalDisplayValueAttributeName = "data-translationoriginaldispla
const enhanceHtmlTagsInlineIgnore = ['BR', 'CODE', 'KBD', 'WBR'] // and input if type is submit or button, and pre depending on settings
const enhanceHtmlTagsNoTranslate = ['TITLE', 'SCRIPT', 'STYLE', 'TEXTAREA', 'SVG', 'svg'] //TODO verificar porque 'svg' é com letras minúsculas
const blockElements = [
'H1', 'H2', 'H3', 'H4', 'H5', 'H6','TABLE', 'OL',"UL", 'P',
'H1', 'H2', 'H3', 'H4', 'H5', 'H6','TABLE', 'OL', 'P','LI'
];
if (twpConfig.get('translateTag_pre') !== 'yes') {
blockElements.push('PRE')
Expand Down Expand Up @@ -187,6 +187,22 @@ const translateSelectors = [
containerSelectors:[
"#document-text-content"
]
},{
hostname:"www.inoreader.com",
selectors:[".article_title",],
containerSelectors:[
".article_content"
]
},
{
hostname:"mail.google.com",
selectors:["h2[data-thread-perm-id]","span[data-thread-id]"],
containerSelectors:[
"div[data-message-id] > div > div[class='']"
]
},{
hostname:"www.producthunt.com",
selectors:["a[data-test^='post-']",'h2',"div.layoutCompact div[class^='styles_htmlText__']"],
}

]
Expand Down
32 changes: 31 additions & 1 deletion src/contentScript/pageTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,16 @@ Promise.all([twpConfig.onReady(), getTabUrl()])
const onTabVisible = function () {
chrome.runtime.sendMessage({
action: "detectTabLanguage"
}, result => {
},async result => {
// if und, manual check

if(result === 'und'){
result = await detectPageLanguage()
}

result = result || "und"


if (result === "und") {
originalTabLanguage = result
} else {
Expand Down Expand Up @@ -1034,3 +1042,25 @@ Promise.all([twpConfig.onReady(), getTabUrl()])
})
}
})

function detectPageLanguage() {
return new Promise((resolve, reject) => {
if(document.documentElement && document.documentElement.lang){
resolve(document.documentElement.lang)
}else{
// use detect language api
if(document.body && document.body.innerText){
chrome.runtime.sendMessage({
action: "detectLanguage",
text: document.body.innerText
}, response => {
resolve(response)
})
}else{
resolve(undefined)
}
}
})

}

2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"default_locale": "en",
"name": "Immersive Translate",
"description": "Let's experience immersive web translation, with bilingual simultaneous display and translation of only the important content.",
"version": "0.0.22.1",
"version": "0.0.23",
"homepage_url": "https://github.com/immersive-translate/immersive-translate",

"browser_specific_settings": {
Expand Down
14 changes: 7 additions & 7 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ <h3 class="w3-wide"><b>Immersive Translate</b></h3>
<div style="color:#999;" class="w3-margin">Exmaple:&nbsp;&nbsp;<code>border-bottom: 2px solid #72ECE9;</code></div>


<div class="desktopOnly">
<p><b data-i18n="msgUseOldPopupInterface">Use the old popup interface</b></p>
<select id="useOldPopup" class="w3-select w3-margin">
<option value="no" data-i18n="msgNo">No</option>
<option value="yes" data-i18n="msgYes">Yes</option>
</select>
</div>
<!-- <div class="desktopOnly"> -->
<!-- <p><b data-i18n="msgUseOldPopupInterface">Use the old popup interface</b></p> -->
<!-- <select id="useOldPopup" class="w3-select w3-margin"> -->
<!-- <option value="no" data-i18n="msgNo">No</option> -->
<!-- <option value="yes" data-i18n="msgYes">Yes</option> -->
<!-- </select> -->
<!-- </div> -->

<p><b data-i18n="lblDarkMode">Dark mode</b></p>
<select id="darkMode" class="w3-select w3-margin">
Expand Down
10 changes: 5 additions & 5 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,11 @@ twpConfig.onReady(function () {
$("#dontShowIfSelectedTextIsUnknown").checked = twpConfig.get("dontShowIfSelectedTextIsUnknown") === "yes" ? true : false

// style options
$("#useOldPopup").onchange = e => {
twpConfig.set("useOldPopup", e.target.value)
updateDarkMode()
}
$("#useOldPopup").value = twpConfig.get("useOldPopup")
// $("#useOldPopup").onchange = e => {
// twpConfig.set("useOldPopup", e.target.value)
// updateDarkMode()
// }
// $("#useOldPopup").value = twpConfig.get("useOldPopup")

$("#isShowDualLanguage").onchange = e => {
twpConfig.set("isShowDualLanguage", e.target.value)
Expand Down
2 changes: 1 addition & 1 deletion src/popup/detect-pdf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
chrome.tabs.query({active: true, currentWindow: true}, tabs => {
if (tabs[0].url.toLowerCase().endsWith(".pdf")) {
if (tabs && tabs[0] && tabs[0].url.toLowerCase().endsWith(".pdf")) {
window.location.href = "popup-translate-document.html"
}
})
Expand Down
8 changes: 4 additions & 4 deletions src/popup/old-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ twpConfig.onReady(function () {
lblTranslating.style.display = "none"
lblTranslated.style.display = "inline"
lblError.style.display = "none"
showAlwaysTranslateCheckbox ? divAlwaysTranslate.style.display = "block" : divAlwaysTranslate.style.display = "none";

divAlwaysTranslate.style.display = "none"
btnTranslate.style.display = "none"
btnRestore.style.display = "inline"
btnTryAgain.style.display = "none"
Expand All @@ -266,8 +266,8 @@ twpConfig.onReady(function () {
lblTranslating.style.display = "inline"
lblTranslated.style.display = "none"
lblError.style.display = "none"
showAlwaysTranslateCheckbox ? divAlwaysTranslate.style.display = "block" : divAlwaysTranslate.style.display = "none";

divAlwaysTranslate.style.display = "none"
btnTranslate.style.display = "none"
btnRestore.style.display = "inline"
btnTryAgain.style.display = "none"
Expand All @@ -282,8 +282,8 @@ twpConfig.onReady(function () {
lblTranslating.style.display = "none"
lblTranslated.style.display = "none"
lblError.style.display = "inline"

divAlwaysTranslate.style.display = "none"
showAlwaysTranslateCheckbox ? divAlwaysTranslate.style.display = "block" : divAlwaysTranslate.style.display = "none";
// divAlwaysTranslate.style.display = "none"
btnTranslate.style.display = "none"
btnRestore.style.display = "none"
btnTryAgain.style.display = "inline"
Expand Down

0 comments on commit bc1139b

Please sign in to comment.