Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added New feature - "Hide Original Language when Translated" #955

Merged
merged 8 commits into from
Oct 23, 2024
5 changes: 3 additions & 2 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@
"show_user_previews_on_mobile": { "message": "Show user previews on hold (this can be annoying)", "description": "This option only appears on mobile" },
"separate_text": { "message": "Separate text", "description": "This option appears in three-dot menu of tweets only on mobile and makes text bigger and adds padding on top and bottom on tap" },
"leave_conversation": { "message": "Are you sure you want to leave/remove this conversation?"},
"autotranslation_help1": { "message": "This function can find the tweets and trigger translation automatically, without having to click the button manually."},
"autotranslation_help1": { "message": "This function can find the tweets and trigger translation automatically, without having to click the button manually."},
"autotranslation_help2": { "message": "To use it, select autotranslation mode and set the language list. The tweets that meet the conditions will be automatically translated."},
"autotranslation_help3": { "message": "Specifically:"},
"autotranslation_help4": { "message": "\"Translate when in language list\" with no languages set cause function to be disabled (default)."},
Expand Down Expand Up @@ -645,5 +645,6 @@
"nonexistent_user_desc": { "message": "Try searching for another." },
"suspended_user": { "message": "Account suspended" },
"suspended_user_desc": { "message": "The profile you are trying to view has been suspended." },
"show_boring_indicators": { "message": "Show indicator in followers/following page if last tweet of person is a retweet/quote/non-existent/old" }
"show_boring_indicators": { "message": "Show indicator in followers/following page if last tweet of person is a retweet/quote/non-existent/old" },
"hide_original_languages":{"message": "Hide original languages when translated" }
}
5 changes: 4 additions & 1 deletion _locales/he/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -858,5 +858,8 @@
"no_big_font": { "message": "ביטול גופן מוגדל עבור ציוצים קצרים/פופולריים" },
"mmdd":{ "message": "$MONTH$ $DATE$", "description":"July 1st", "placeholders": { "month": { "content": "July" }, "date": { "content": "1st" } }},
"mmddyy":{ "message": "$MONTH$ $DATE$, $YEAR$", "description":"July 1st, 2015", "placeholders": { "year": { "content": "2015" },"month": { "content": "July" }, "date": { "content": "1st" } }},
"yyyy":{ "message": "$YEAR$", "description":"2015", "placeholders": { "year": { "content": "2015" } } }
"yyyy":{ "message": "$YEAR$", "description":"2015", "placeholders": { "year": { "content": "2015" } } },
"hide_original_languages":{
"message": "הסר טקסט מקורי כאשר ציוצים מתורגמים"
}
}
3 changes: 3 additions & 0 deletions layouts/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ <h2>__MSG_autotranslation__</h2> <span class="option-help" id="autotl-help">?</s
</select>
<button id="add-autotranslate-language" class="nice-button" disabled>__MSG_add__</button>
</div>
<div class="setting">
<input type="checkbox" id="hide-original-languages"> <label for="hide-original-languages">__MSG_hide_original_languages__</label>
</div>
<div id="mobile-setting">
<h2>__MSG_mobile__</h2><br>
<div class="setting" id="disable-data-saver-div">
Expand Down
8 changes: 8 additions & 0 deletions layouts/settings/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ setTimeout(async () => {
let showExactValues = document.getElementById('show-exact-values');
let localizeDigit = document.getElementById('localize-digit');
let hideTimelineTypes = document.getElementById('hide-timeline-types');
let hideOriginalLanguages = document.getElementById('hide-original-languages');
let autotranslationMode = document.getElementById('autotranslation-mode');
let autotranslateLanguages = document.getElementById('autotranslate-languages');
let autotranslateLanguageList = document.getElementById('autotranslate-language-list');
Expand Down Expand Up @@ -980,6 +981,12 @@ setTimeout(async () => {
autotranslateLanguages.appendChild(div);
}

hideOriginalLanguages.addEventListener('change', () => {
chrome.storage.sync.set({
hideOriginalLanguages: hideOriginalLanguages.checked
}, () => { });
});

// Set values
if(vars.linkColor) {
linkColor.value = vars.linkColor;
Expand Down Expand Up @@ -1049,6 +1056,7 @@ setTimeout(async () => {
pinBookmarksOnNavbar.checked = !!vars.pinBookmarksOnNavbar;
pinListsOnNavbar.checked = !!vars.pinListsOnNavbar;
useOldDefaultProfileImage.checked = !!vars.useOldDefaultProfileImage;
hideOriginalLanguages.checked = !!vars.hideOriginalLanguages;
uncensorAdultContentAutomatically.checked = !!vars.uncensorAdultContentAutomatically;
uncensorGraphicViolenceAutomatically.checked = !!vars.uncensorGraphicViolenceAutomatically;
uncensorSensitiveContentAutomatically.checked = !!vars.uncensorSensitiveContentAutomatically;
Expand Down
8 changes: 7 additions & 1 deletion scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function loadVars() {
'uncensorGraphicViolenceAutomatically', 'uncensorAdultContentAutomatically', 'uncensorSensitiveContentAutomatically', 'useOldStyleReply',
'enableAd', 'acknowledgedCssAccess', 'disableProfileCustomizations', 'openNotifsAsModal', 'enableIframeNavigation',
'acknowledgedCustomizationButton', 'modernUI', 'showExactValues', 'hideTimelineTypes', 'autotranslateLanguages',
'autotranslationMode', 'muteVideos', 'dontPauseVideos', 'showUserPreviewsOnMobile', 'systemDarkMode', 'localizeDigit',
'autotranslationMode', 'hideOriginalLanguages', 'muteVideos', 'dontPauseVideos', 'showUserPreviewsOnMobile', 'systemDarkMode', 'localizeDigit',
'disableRetweetHotkey', 'disableLikeHotkey', 'disableFindHotkey', 'extensionCompatibilityMode', 'disableDataSaver', 'disableAcceptType',
'showUserFollowerCountsInLists', 'showQuoteCount', 'hideUnfollowersPage', 'transitionProfileBanner', 'customDownloadTemplate',
'showBoringIndicators'
Expand Down Expand Up @@ -210,6 +210,12 @@ async function loadVars() {
disableAcceptType: false
}, () => {});
}
if(typeof(data.hideOriginalLanguages) !== 'boolean') {
data.hideOriginalLanguages = false;
chrome.storage.sync.set({
hideOriginalLanguages: false
}, () => {});
}
if(typeof(data.autotranslateProfiles) !== 'object') {
data.autotranslateProfiles = [];
chrome.storage.sync.set({
Expand Down
17 changes: 16 additions & 1 deletion scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,7 @@ async function appendTweet(t, timelineContainer, options = {}) {
let tt = t.full_text.replace(/^(@[a-zA-Z0-9_]{1,15}\s?)*/, "").replace(/\shttps:\/\/t.co\/[a-zA-Z0-9\-]{8,10}$/, "").trim();
if(translated.text.trim() === tt) return;
if(translated.text.trim() === tt.replace(/(hihi)|(hehe)/g, 'lol')) return; // lol
const { hideOriginalLanguages } = await chrome.storage.sync.get('hideOriginalLanguages');
let translatedMessage;
if(LOC.translated_from.message.includes("$LANGUAGE$")) {
translatedMessage = LOC.translated_from.message.replace("$LANGUAGE$", `[${translated.translated_lang}]`);
Expand All @@ -2653,6 +2654,10 @@ async function appendTweet(t, timelineContainer, options = {}) {
if(translated.text.length > 600) {
translated.text = translated.text.substring(0, 600) + '...';
}
if (hideOriginalLanguages) {
translatedMessage = '';
tweetBodyQuoteText.innerHTML = '';
}
tweetBodyQuoteText.innerHTML +=
`<span class="translated-from" style="margin-bottom:3px">${translatedMessage}:</span>`+
`<span class="tweet-translated-text" style="color:var(--default-text-color)!important">${escapeHTML(translated.text)}</span>`;
Expand Down Expand Up @@ -2683,6 +2688,8 @@ async function appendTweet(t, timelineContainer, options = {}) {
let tt = t.full_text.replace(/^(@[a-zA-Z0-9_]{1,15}\s?)*/, "").replace(/\shttps:\/\/t.co\/[a-zA-Z0-9\-]{8,10}$/, "").trim();
if(translated.text.trim() === tt) return;
if(translated.text.trim() === tt.replace(/(hihi)|(hehe)/g, 'lol')) return; // lol
const { hideOriginalLanguages } = await chrome.storage.sync.get('hideOriginalLanguages');

let translatedMessage;
if(LOC.translated_from.message.includes("$LANGUAGE$")) {
translatedMessage = LOC.translated_from.message.replace("$LANGUAGE$", `[${translated.translated_lang}]`);
Expand All @@ -2696,10 +2703,18 @@ async function appendTweet(t, timelineContainer, options = {}) {
let translatedFrom = document.createElement('span');
translatedFrom.classList.add('translated-from');
translatedFrom.innerText = translatedMessage;



let translatedText = document.createElement('span');
translatedText.classList.add('tweet-translated-text');
translatedText.innerHTML = await renderTweetBodyHTML(translatedT);
tweetBodyText.append(document.createElement('br'), translatedFrom, translatedText);
if (hideOriginalLanguages) {
tweetBodyText.innerHTML = '';
tweetBodyText.append(translatedText);
} else {
tweetBodyText.append(document.createElement('br'), translatedFrom, translatedText);
}
if(vars.enableTwemoji) twemoji.parse(tweetBodyText);
});
if(options.translate || vars.autotranslateProfiles.includes(t.user.id_str) || (typeof toAutotranslate !== 'undefined' && toAutotranslate) || (vars.autotranslateLanguages.includes(t.lang) && vars.autotranslationMode === 'whitelist') || (!vars.autotranslateLanguages.includes(t.lang) && vars.autotranslationMode === 'blacklist')) {
Expand Down
19 changes: 18 additions & 1 deletion scripts/tweetviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,8 @@ class TweetViewer {
let tt = t.full_text.replace(/^(@[a-zA-Z0-9_]{1,15}\s?)*/, "").replace(/\shttps:\/\/t.co\/[a-zA-Z0-9\-]{8,10}$/, "").trim();
if(translated.text.trim() === tt) return;
if(translated.text.trim() === tt.replace(/(hihi)|(hehe)/g, 'lol')) return; // lol
const { hideOriginalLanguages } = await chrome.storage.sync.get('hideOriginalLanguages');

let translatedMessage;
if(LOC.translated_from.message.includes("$LANGUAGE$")) {
translatedMessage = LOC.translated_from.message.replace("$LANGUAGE$", `[${translated.translated_lang}]`);
Expand All @@ -1617,6 +1619,10 @@ class TweetViewer {
if(translated.text.length > 600) {
translated.text = translated.text.substring(0, 600) + '...';
}
if (hideOriginalLanguages) {
translatedMessage = '';
tweetBodyQuoteText.innerHTML = '';
}
tweetBodyQuoteText.innerHTML +=
`<span class="translated-from" style="margin-bottom:3px">${translatedMessage}:</span>`+
`<span class="tweet-translated-text" style="color:var(--default-text-color)!important">${escapeHTML(translated.text)}</span>`;
Expand Down Expand Up @@ -1647,6 +1653,9 @@ class TweetViewer {
let tt = t.full_text.replace(/^(@[a-zA-Z0-9_]{1,15}\s?)*/, "").replace(/\shttps:\/\/t.co\/[a-zA-Z0-9\-]{8,10}$/, "").trim();
if(translated.text.trim() === tt) return;
if(translated.text.trim() === tt.replace(/(hihi)|(hehe)/g, 'lol')) return; // lol

const { hideOriginalLanguages } = await chrome.storage.sync.get('hideOriginalLanguages');

let translatedMessage;
if(LOC.translated_from.message.includes("$LANGUAGE$")) {
translatedMessage = LOC.translated_from.message.replace("$LANGUAGE$", `[${translated.translated_lang}]`);
Expand All @@ -1660,10 +1669,18 @@ class TweetViewer {
let translatedFrom = document.createElement('span');
translatedFrom.classList.add('translated-from');
translatedFrom.innerText = translatedMessage;



let translatedText = document.createElement('span');
translatedText.classList.add('tweet-translated-text');
translatedText.innerHTML = await renderTweetBodyHTML(translatedT);
tweetBodyText.append(document.createElement('br'), translatedFrom, translatedText);
if (hideOriginalLanguages) {
tweetBodyText.innerHTML = '';
tweetBodyText.append(translatedText);
} else {
tweetBodyText.append(document.createElement('br'), translatedFrom, translatedText);
}
if(vars.enableTwemoji) twemoji.parse(tweetBodyText);
});
if(options.translate || vars.autotranslateProfiles.includes(t.user.id_str) || (typeof toAutotranslate !== 'undefined' && toAutotranslate) || (vars.autotranslateLanguages.includes(t.lang) && vars.autotranslationMode === 'whitelist') || (!vars.autotranslateLanguages.includes(t.lang) && vars.autotranslationMode === 'blacklist')) {
Expand Down
Loading