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

Commit

Permalink
support google,urban,microsoft
Browse files Browse the repository at this point in the history
  • Loading branch information
theowenyoung committed Nov 19, 2022
1 parent d95f646 commit 13b2d7b
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# ChangeLog


## 0.0.33

- Support google.com
- Add Option for is translate page title in others panel
- Fix chrome extension report errors in extension manager.
- Support www.urbandictionary.com
- Support answers.microsoft.com

## 0.0.32

- Fix popup More option, always translate site
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.Phony: start
start:
web-ext run -s ./src
web-ext run -s ./src -f firefoxdeveloperedition

.Phony: build
build:
Expand Down
4 changes: 3 additions & 1 deletion src/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@
},
"msgCommon":{
"message":"常用配置"
},
"optionIsTranslateTitle":{
"message":"是否翻译页面标题?"
}

}
5 changes: 3 additions & 2 deletions src/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@
},
"msgCommon":{
"message":"常用設置"
},
"optionIsTranslateTitle":{
"message":"是否翻譯頁面標題?"
}


}
1 change: 1 addition & 0 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function resetBrowserAction(forceShow = false) {
}

if (typeof chrome.contextMenus !== "undefined") {
chrome.contextMenus.removeAll()
chrome.contextMenus.create({
id: "browserAction-showPopup",
title: chrome.i18n.getMessage("btnShowPopup"),
Expand Down
1 change: 1 addition & 0 deletions src/background/chrome_background.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function resetBrowserAction(forceShow = false) {
}

if (typeof chrome.contextMenus !== "undefined") {
chrome.contextMenus.removeAll()
chrome.contextMenus.create({
id: "browserAction-showPopup",
title: chrome.i18n.getMessage("btnShowPopup"),
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.32",
"version": "0.0.33",
"homepage_url": "https://github.com/immersive-translate/immersive-translate",

"commands": {
Expand Down
13 changes: 10 additions & 3 deletions src/contentScript/enhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ async function getNodesThatNeedToTranslate(root,ctx,options){
})



// check node language is target language, if yes, remove it

let newAllNodes = [];
Expand Down Expand Up @@ -366,7 +367,8 @@ async function getNodesThatNeedToTranslate(root,ctx,options){
if(!previousSibling || !previousSibling.hasAttribute || !previousSibling.hasAttribute(enhanceMarkAttributeName)){
// add
let copyNode = node.cloneNode(true);

// get original display value
let originalDisplay = node.style.display;
if(ctx.tabHostName==="www.reddit.com"){
// append child <br>
if(copyNode.nodeName.toLowerCase() === "h3" || copyNode.nodeName.toLowerCase() === "h1"){
Expand All @@ -391,7 +393,14 @@ async function getNodesThatNeedToTranslate(root,ctx,options){
const br = document.createElement("br");
copyNode.appendChild(br);
}
}else if(pageSpecialConfig && pageSpecialConfig.name==='google'){
if(node.nodeName.toLowerCase() === "h3" ){
// check copy node display to block
originalDisplay = "block";
}

}


if(inlineElements.includes(copyNode.nodeName.toLowerCase())){
// add a space
Expand All @@ -403,8 +412,6 @@ async function getNodesThatNeedToTranslate(root,ctx,options){
copyNode.style.paddingBottom = "8px";
}
}
// get original display value
let originalDisplay = node.style.display;
// if nitter
if(pageSpecialConfig && pageSpecialConfig.name && pageSpecialConfig.name === "nitter"){
// display to block
Expand Down
7 changes: 4 additions & 3 deletions src/contentScript/pageTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,9 +872,10 @@ Promise.all([twpConfig.onReady(), getTabUrl()])
})
pageLanguageStateObservers.forEach(callback => callback(pageLanguageState))
currentPageLanguage = currentTargetLanguage

// do not translate title, it not need
// translatePageTitle()
const isTranslateTitle = twpConfig.get("isTranslateTitle") == "yes" ? true : false
if (isTranslateTitle) {
translatePageTitle()
}

enableMutatinObserver()

Expand Down
1 change: 1 addition & 0 deletions src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const twpConfig = (function () {
textTranslatorService: "google", // google yandex bing deepl
ttsSpeed: 1.0,
enableDeepL: "yes",
isTranslateTitle: "no",
targetLanguage: null,
targetLanguageTextTranslation: null,
targetLanguages: [], // "en", "es", "de"
Expand Down
13 changes: 13 additions & 0 deletions src/lib/specialRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,18 @@ const specialRules = [
"hostname":"app.daily.dev",
"selectors":["h1",".typo-body","article h3"],
"containerSelectors":"[class^=markdown_markdown]"
},{
"name":"google",
"regex":"^https:\/\/www\.google\.",
"selectors":["h2","a h3","div[data-content-feature='1'] > div","a [aria-level='3']","a [aria-level='3'] + div",".Uroaid"],
"detectLanguage":true

},{
"hostname":"www.urbandictionary.com",
"selectors":["div.meaning","div.example"],
},{
"hostname":"answers.microsoft.com",
"selectors":["h1","div.thread-message-content div.thread-message-content-body-text"],
"containerSelectors":["div.thread-message-content-body-text",]
}
]
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.32",
"version": "0.0.33",
"homepage_url": "https://github.com/immersive-translate/immersive-translate",

"browser_specific_settings": {
Expand Down
9 changes: 9 additions & 0 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ <h3 class="w3-wide"><b>Immersive Translate</b></h3>
<option value="threeFingersOnTheScreen" data-i18n="optionPopupThreeFingers">When I touch three
fingers on the screen</option>
</select>

<br>

<p><b data-i18n="optionIsTranslateTitle">Translate Page Title?</b></p>
<select id="isTranslateTitle" class="w3-select w3-margin">
<option value="yes" data-i18n="msgYes">Yes</option>
<option value="no" data-i18n="msgNo">No</option>
</select>

<div class="desktopOnly">
<br>
<p><b data-i18n="lblButtonInTheAddressBar">Show button in the address bar</b></p>
Expand Down
5 changes: 5 additions & 0 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,11 @@ twpConfig.onReady(function () {
}
$("#showPopupMobile").value = twpConfig.get("showPopupMobile")

$("#isTranslateTitle").onchange = e => {
twpConfig.set("isTranslateTitle", e.target.value)
}
$("#isTranslateTitle").value = twpConfig.get("isTranslateTitle")

$("#showTranslatePageContextMenu").onchange = e => {
twpConfig.set("showTranslatePageContextMenu", e.target.value)
}
Expand Down

0 comments on commit 13b2d7b

Please sign in to comment.