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

Commit

Permalink
support read.readwise.io
Browse files Browse the repository at this point in the history
  • Loading branch information
theowenyoung committed Nov 12, 2022
1 parent 27d91bd commit 32eb2a9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
23 changes: 23 additions & 0 deletions docs/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,26 @@ Or the Twitter homepage at
https://twitter.com/spectatorindex/

Then right click and select Translate that page and you can see the translated effect.





## Examples

- <https://twitter.com/elonmusk>
- <https://twitter.com/spectatorindex>
- <https://twitter.com/i/lists/1591319857319903233>
- <https://news.ycombinator.com/>
- <https://hn.algolia.com/>
- <https://www.reddit.com/>
- <https://www.judiciary.senate.gov/imo/media/doc/Haidt%20Testimony.pdf>
- <https://1paragraph.app/>
- <https://github.com/bitcoin/bitcoin>
- <https://www.nature.com/articles/d41586-022-03611-w>
- <https://www.cell.com/cell-reports/fulltext/S2211-1247(22)01482-6>
- <https://www.reuters.com/markets/currencies/exclusive-least-1-billion-client-funds-missing-failed-crypto-firm-ftx-sources-2022-11-12/>
- <https://www.youtube.com/watch?v=LNm9kZR15m8>
- <https://www.facebook.com/groups/cheapmealideas>


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",
"version": "0.0.22.1",
"homepage_url": "https://github.com/immersive-translate/immersive-translate",

"commands": {
Expand Down
48 changes: 33 additions & 15 deletions src/contentScript/enhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ const translateSelectors = [
},{
hostname:"hn.algolia.com",
selectors:[".Story_title"]
},{
hostname:"read.readwise.io",
selectors:['div[class^="_titleRow_"]','div[class^="_description_"]'],
containerSelectors:[
"#document-text-content"
]
}

]
Expand Down Expand Up @@ -367,7 +373,16 @@ async function getNodesThatNeedToTranslate(root,ctx,options){
if((pageSpecialConfig && pageSpecialConfig.containerSelectors) || allBlocksSelectors.length === 0){
const originalRoot = root;
const contentContainers = getContainers(root,pageSpecialConfig);
let containers = [root]
let containers = []
if(pageSpecialConfig && pageSpecialConfig.containerSelectors){
if(!Array.isArray(pageSpecialConfig.containerSelectors)){
pageSpecialConfig.containerSelectors = [pageSpecialConfig.containerSelectors];
}
// check length
if(pageSpecialConfig.containerSelectors.length ===0){
containers = [root]
}
}
if(contentContainers && Array.isArray(contentContainers)){
containers = contentContainers;
}
Expand Down Expand Up @@ -504,23 +519,26 @@ function getContainers(root,pageSpecialConfig){
if(!Array.isArray(pageSpecialConfig.containerSelectors)){
pageSpecialConfig.containerSelectors = [pageSpecialConfig.containerSelectors];
}
let containers =[];
for(const selector of pageSpecialConfig.containerSelectors){
const allContainer = root.querySelectorAll(pageSpecialConfig.containerSelectors);
if(allContainer){
for(const container of allContainer){
// check if brToParagraph
if(pageSpecialConfig.brToParagraph){
const pattern = new RegExp ("<br/?>[ \r\n\s]*<br/?>", "g");
container.innerHTML = container.innerHTML.replace(pattern, "</p><p>");
}

if(pageSpecialConfig.containerSelectors.length >0){
let containers =[];
for(const selector of pageSpecialConfig.containerSelectors){
const allContainer = root.querySelectorAll(pageSpecialConfig.containerSelectors);
if(allContainer){
for(const container of allContainer){
// check if brToParagraph
if(pageSpecialConfig.brToParagraph){
const pattern = new RegExp ("<br/?>[ \r\n\s]*<br/?>", "g");
container.innerHTML = container.innerHTML.replace(pattern, "</p><p>");
}

containers.push(container);
}
}

containers.push(container);
}
}
}
return containers.length>0?containers:null;
}
return containers.length>0?containers:null;
}

if(!(root && root.innerText)){
Expand Down
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",
"version": "0.0.22.1",
"homepage_url": "https://github.com/immersive-translate/immersive-translate",

"browser_specific_settings": {
Expand Down

0 comments on commit 32eb2a9

Please sign in to comment.