User:Alifakoor/common.js

From translatewiki.net

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
mw.loader.load('http://meta.wikimedia.org/w/index.php?title=User:Reza1615/smalltools.js&action=raw&ctype=text/javascript');

//targoman
$(function () {
        $('<button>', { text: 'ترگمان', title: 'ترجمه از ترگمان' }).css('float', 'left').click(function (e) {
        var txt= $("div.row.tux-message.open > div.row.tux-message-editor > div.seven.columns.editcolumn >div.row >span.twelve.columns.sourcemessage")[0]
        if (txt==undefined){
            mw.notify('ابتدا یکی از موارد ترجمه را انتخاب کنید بعد بر روی این دکمه کلیک کنید')
            return
        }
        txt=txt.textContent.replace(/ /g,'%20').replace(/\_/g,'%20')
        $.getJSON('//tools.wmflabs.org/rezabot/targoman2.php', { entitle: mw.config.get('wgSiteName'), type:txt }).then(function (result) {
                $("div.row.tux-message.open > div.row.tux-message-editor > div.seven.columns.editcolumn >div.row.tux-editor-editarea-block >div.editarea.twelve.columns >div.tux-notices-block ").next('textarea').val(result.TrResult)
                mw.notify('ترجمه پیشنهادی ترگمان در بخش ویرایش قرار داده شد')
            });
    }).insertBefore('.row.tux-message-selector');
    
});