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

Commit

Permalink
support nitter
Browse files Browse the repository at this point in the history
  • Loading branch information
theowenyoung committed Nov 7, 2022
1 parent 8711e44 commit 6979c95
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log


## 0.0.17

- Support Nitter

## 0.0.16

- Fix undefined error. Seriouse bug.
2 changes: 1 addition & 1 deletion src/chrome_manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"default_locale": "en",
"name": "Immersive Translate - 沉浸式翻译",
"name": "Immersive Translate",
"description": "支持整页翻译·双语显示·只翻译正文。布局全面优化,和浏览器阅读模式类似,对Twitter, Reddit等网站做了定制优化",
"version": "0.0.16",
"homepage_url": "https://github.com/theowenyoung/Traduzir-paginas-web",
Expand Down
24 changes: 21 additions & 3 deletions src/contentScript/enhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const translateSelectors = [
{
hostname:["www.wsj.com","www.economist.com"],
containerSelector:"main"
}
},

]

Expand Down Expand Up @@ -177,6 +177,18 @@ function getPageSpecialConfig(ctx){
}
}
}
// handle nitter, there are too many domains, so we detect it by meta, and element
// if og:sitename is "Nitter", and there is class name tweet-content, then it is nitter
const nitterMeta = document.querySelector('meta[property="og:site_name"]');
if(nitterMeta && nitterMeta.getAttribute('content') === 'Nitter'){
const nitterTweetContent = document.querySelector('.tweet-content');
if(nitterTweetContent){
return {
name:"nitter",
selectors:['.tweet-content','.quote-text']
}
}
}
}


Expand Down Expand Up @@ -360,9 +372,15 @@ function getNodesThatNeedToTranslate(root,ctx,options){
}else{
copyNode.style.paddingBottom = "8px";
}
copyNode.setAttribute(enhanceMarkAttributeName, "copiedNode");
// get original display value
const originalDisplay = node.style.display;
let originalDisplay = node.style.display;
// if nitter
console.log("pageSpecialConfig", pageSpecialConfig)
if(pageSpecialConfig && pageSpecialConfig.name && pageSpecialConfig.name === "nitter"){
// display to block
originalDisplay = "block";
}
copyNode.setAttribute(enhanceMarkAttributeName, "copiedNode");
// add data-translationoriginaldisplay
if(originalDisplay){
copyNode.setAttribute(enhanceOriginalDisplayValueAttributeName, originalDisplay);
Expand Down

0 comments on commit 6979c95

Please sign in to comment.