مدیاویکی:TofawikiSection.js
نکته: برای دیدن تغییرات، ممکن است نیاز باشد که حافظهٔ نهانی مرورگر خود را پس از انتشار پاکسازی کنید. گوگل کروم، فایرفاکس، مایکروسافت اج و سافاری: کلید ⇧ Shift را نگه دارید و روی دکمهٔ Reload در نوار ابزار مرورگر کلیک کنید. برای آگاهی از جزئیات و نحوهٔ پاکسازی حافظهٔ نهانی سایر مرورگرها، صفحهٔ ویکیپدیا:میانگیر مرورگرتان را خالی کنید را ببینید.
$(function () {
var query = new mw.Uri(location.href).query;
if (query.enTitle === undefined || query.enSectionId === undefined) return;
if (query.editintro === undefined) return; // add a &editintro=Template:Null
$('.mw-editintro').css({
'font-weight': 'bold',
'white-space': 'pre-wrap',
border: '2px solid #54595d',
padding: '1em',
'background-color': '#f0f0f0',
'margin-bottom': '8px',
'border-radius': '15px'
}).empty().append($('<center>', {
text: 'در حال دریافت ترجمه…'
}));
$.get('https://rezabot.toolforge.org/targoman3.php', {
title: query.enTitle,
subsection: query.enSectionId
}).then(function (result) {
$('.mw-editintro').empty().append($('<div>').append([
$('<center>', {
style: 'font-weight: bold; font-size: large;',
title: 'توسط مترجم ترگمان',
text: 'ترجمهٔ ماشینی',
}),
$('<div>', {
style: 'white-space: pre-wrap; float: right; width: 100%; font-weight: bold;',
text: 'لطفاً ترجمهٔ ماشینی را با متن اصلی انگلیسی مقایسه کنید و پس از بازبینی و اصلاح در جای مناسب قرار دهید:',
title: 'توسط مترجم ترگمان',
}),
$('<div>', {
id: 'tofawiki-translation',
contenteditable: 'true',
spellcheck: 'true',
lang: 'fa',
style: 'white-space: pre-wrap; float: right; width: 50%;',
title: 'ترجمه پیشنهادی؛ شما میتوانید در اینجا متن را ویرایش کنید و از دکمهٔ ابرابزار هم استفاده کنید.',
text: window.persianWikiTools
? window.persianWikiTools.superTool(result.translation)
: result.translation
}),
$('<div>', {
dir: 'ltr',
lang: 'en',
style: 'white-space: pre-wrap; float: right; width: 50%;',
title: 'متن ویکیپدیای انگلیسی',
text: result.original
}),
$('<div>', { style: 'clear:both;' }),
$('<span>', { text: 'رونوشت', class: 'mw-ui-button' }).click(function () {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(document.getElementById('tofawiki-translation'));
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
})
]));
}).catch(function (e) {
console.error(e);
$('.mw-editintro').empty().append('خطا در دریافت ترجمه: ' + JSON.stringify(e));
});
});