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

Commit

Permalink
support seekingalpha.com
Browse files Browse the repository at this point in the history
  • Loading branch information
theowenyoung committed Nov 12, 2022
1 parent dde51c9 commit 1bbc645
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Immersive Translate - 沉浸式翻译扩展

Let's experience immersive web translation, with bilingual simultaneous display and translation of only the important content. Think of the browser's reading mode, but in immersive translation.

[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/immersive-translate/immersive-translate?label=latest%20version&sort=semver)](https://github.com/immersive-translate/releases)
[![GitHub release date](https://img.shields.io/github/release-date/immersive-translate/immersive-translate?labely)](https://github.com/immersive-translate/immersive-translate/latest)
[![GitHub issues](https://img.shields.io/github/issues/immersive-translate/immersive-translate?color=red)](https://github.com/immersive-translate/immersive-translate/issues)
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.20",
"version": "0.0.20.1",
"homepage_url": "https://github.com/immersive-translate/immersive-translate",

"commands": {
Expand Down
31 changes: 28 additions & 3 deletions 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', 'LI', 'P',
];
if (twpConfig.get('translateTag_pre') !== 'yes') {
blockElements.push('PRE')
Expand Down Expand Up @@ -174,6 +174,10 @@ const translateSelectors = [
{
hostname:"www.nature.com",
containerSelectors:"article"
},{
hostname:"seekingalpha.com",
containerSelectors:"div.wsb_section",
brToParagraph: true
}

]
Expand Down Expand Up @@ -226,6 +230,18 @@ function getPageSpecialConfig(ctx){
// html tag class clearly-overflow
// console.log("document.documentElement", document.documentElement.classList)
// if(document.documentElement && document.documentElement.classList.contains('clearly-overflow')){
// // id=clearly-container iframe
// // remove referrerpolicy attribute
// const clearlyContainer = document.querySelector('iframe#clearly-container');
// if(clearlyContainer){
// // clearlyContainer.removeAttribute('referrerpolicy');
// console.log("clearlyContainer", clearlyContainer)
// // change referrerpolicy to unsafe-url
// clearlyContainer.setAttribute('referrerpolicy', 'unsafe-url');
// // remove this node
// // clearlyContainer.parentNode.removeChild(clearlyContainer);
//
// }
// specialConfig = {
// containerSelectors:[
// "div#container"
Expand Down Expand Up @@ -315,7 +331,6 @@ function isDuplicatedChild(array,child){
function getNodesThatNeedToTranslate(root,ctx,options){
options = options || {};
const pageSpecialConfig = getPageSpecialConfig(ctx);
console.log("pageSpecialConfig", pageSpecialConfig)
const twpConfig = ctx.twpConfig
const isShowDualLanguage = twpConfig.get("isShowDualLanguage")==='no'?false:true;
const allBlocksSelectors = pageSpecialConfig && pageSpecialConfig.selectors || []
Expand Down Expand Up @@ -441,7 +456,10 @@ function getNodesThatNeedToTranslate(root,ctx,options){
// add a space
copyNode.style.paddingRight = "8px";
}else{
copyNode.style.paddingBottom = "8px";
// if not li element
if(copyNode.nodeName.toLowerCase() !== "li"){
copyNode.style.paddingBottom = "8px";
}
}
// get original display value
let originalDisplay = node.style.display;
Expand Down Expand Up @@ -492,6 +510,13 @@ function getContainers(root,pageSpecialConfig){
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);
}
}
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.20",
"version": "0.0.20.1",
"homepage_url": "https://github.com/immersive-translate/immersive-translate",

"browser_specific_settings": {
Expand Down

0 comments on commit 1bbc645

Please sign in to comment.