diff --git a/css/style.css b/css/style.css
index 04c06225..66902a7f 100644
--- a/css/style.css
+++ b/css/style.css
@@ -1256,6 +1256,7 @@ ol.toptrends-list {
{
display: none;
}
+.post-translate,
.post-reply,
.post-propagate,
.post-favorite
@@ -1266,30 +1267,36 @@ ol.toptrends-list {
opacity: .7;
display: none;
}
+.post:hover .post-translate,
.post:hover .post-reply,
.post:hover .post-propagate,
.post:hover .post-favorite,
+.original.open .post-interactions .post-translate,
.original.open .post-interactions .post-reply,
.original.open .post-interactions .post-propagate,
.original.open .post-interactions .post-favorite,
+.post:hover .original .post-interactions .post-translate,
.post:hover .original .post-interactions .post-reply,
.post:hover .original .post-interactions .post-propagate,
.post:hover .original .post-interactions .post-favorite
{
display: inline-block;
}
+.related.post:hover .post-translate,
.related.post:hover .post-reply,
.related.post:hover .post-propagate,
.related.post:hover .post-favorite
{
display: inline-block;
}
+.open .related .post-translate,
.open .related .post-reply,
.open .related .post-propagate,
.open .related .post-favorite
{
display: none!important;
}
+.open .related:hover .post-translate,
.open .related:hover .post-reply,
.open .related:hover .post-propagate,
.open .related:hover .post-favorite
@@ -1300,6 +1307,11 @@ ol.toptrends-list {
{
background: url(../img/repost.png) no-repeat left center;
}
+.post-translate
+{
+ background: none;
+ padding-left: 0;
+}
.post-favorite
{
background: none;
@@ -1310,6 +1322,7 @@ ol.toptrends-list {
content: "★";
font-size: 18px;
}
+.post-translate:hover,
.post-reply:hover,
.post-propagate:hover,
.post-favorite:hover
diff --git a/home.html b/home.html
index 2d9628a7..e259ef9b 100644
--- a/home.html
+++ b/home.html
@@ -365,6 +365,7 @@
+
Translate
Reply
Retransmit
Favorite
diff --git a/js/interface_common.js b/js/interface_common.js
index 9cf54892..55e56c98 100644
--- a/js/interface_common.js
+++ b/js/interface_common.js
@@ -1873,6 +1873,43 @@ function postReplyClick(event) {
event.stopPropagation();
}
+function postTranslateClick(event) {
+
+ if ($.Options.TranslationEnabled.val === 'enable' && $.Options.TranslationAPI.val.length > 0) {
+
+ var post = $(this).closest('.post').find('.post-text');
+
+ // prevent merge string on tabulation usage
+ post.html(post.html().replaceAll('
',' '));
+
+ // some APIs not accept slash as the part of the get request routing
+ var request = post.text().replaceAll('/','|');
+
+ $.ajax({
+ dataType: 'json',
+ url: $.Options.TranslationAPI.val + encodeURIComponent(request),
+ success: function(json) {
+
+ if (json.translation) {
+
+ var translation = htmlFormatMsg(json.translation.replaceAll('|','/'));
+
+ post.html(translation.html);
+ }
+
+ if (json.error) {
+ alert(json.error);
+ }
+ },
+ error: function(xhr, ajaxOptions, thrownError) {
+ alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
+ }
+ })
+ }
+
+ event.stopPropagation();
+}
+
// Expande Área do Novo post
function composeNewPost(e, postAreaNew) {
e.stopPropagation();
@@ -3028,6 +3065,12 @@ function initInterfaceCommon() {
postExpandFunction(event, $(this));
})
;
+
+ if ($.Options.TranslationEnabled.val !== 'enable') {
+ twister.tmpl.post.find('.post-translate').remove();
+ }
+
+ twister.tmpl.post.find('.post-translate').on('click', postTranslateClick);
twister.tmpl.post.find('.post-reply').on('click', postReplyClick);
twister.tmpl.post.find('.post-propagate').on('click', reTwistPopup);
twister.tmpl.post.find('.post-favorite').on('click', favPopup);
diff --git a/js/options.js b/js/options.js
index 585144ce..1752ea67 100644
--- a/js/options.js
+++ b/js/options.js
@@ -340,6 +340,20 @@ function twisterOptions() {
type: 'checkbox',
valDefault: false
});
+ this.add({
+ name: 'TranslationEnabled',
+ valDefault: 'disable',
+ tickMethod: function (elem) {
+ $('#TranslationCont').css('display', (elem.value === 'enable') ? 'block' : 'none');
+ }
+ });
+ this.add({
+ name: 'TranslationAPI',
+ type: 'text',
+ valDefault: 'https://lingva.ml/api/v1/auto/en/',
+ valMes: 'characters',
+ getMethod: function (val) {return val;}
+ });
}
twisterOptions.prototype.add = function (option) {
diff --git a/options.html b/options.html
index 25768d84..9f59323d 100644
--- a/options.html
+++ b/options.html
@@ -60,6 +60,8 @@
+
+
@@ -539,6 +541,29 @@
+