User:Ah.arabzadeh/common.js

mw.loader.load("https://en.wikipedia.org/w/index.php?title=User:Ebraminio/ArticleTranslator.js&action=raw&ctype=text/javascript");

function GTJ(	g_y,	g_m,	g_d,	choice	) { var g_days_in_month = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var j_days_in_month = new Array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); var j_month_name = new Array("", "Farvardin", "Ordibehesht", "Khordad", "Tir",						 "Mordad", "Shahrivar", "Mehr", "Aban", "Azar",						  "Dey", "Bahman", "Esfand");

var gy, gm, gd; var jy, jm, jd; var g_day_no, j_day_no; var j_np;

var i;	gy = g_y - 1600; gm = g_m - 1; gd = g_d - 1;

g_day_no = 365 * gy + Math.floor((gy + 3) / 4) - Math.floor((gy + 99) / 100) + Math.floor((gy + 399) / 400); for (i = 0; i < gm; ++i) g_day_no += g_days_in_month[i]; if (gm > 1 && ((gy % 4 == 0 && gy % 100 != 0) || (gy % 400 == 0))) /* leap and after Feb */ ++g_day_no; g_day_no += gd;

j_day_no = g_day_no - 79;

j_np = Math.floor(j_day_no / 12053); j_day_no %= 12053;

jy = 979 + 33 * j_np + 4 * Math.floor((j_day_no / 1461)); j_day_no %= 1461;

if (j_day_no >= 366) { jy += Math.floor((j_day_no - 1) / 365); j_day_no = (j_day_no - 1) % 365; }

for (i = 0; i < 11 && j_day_no >= j_days_in_month[i]; ++i) { j_day_no -= j_days_in_month[i]; }	jm = i + 1; jd = j_day_no + 1;

var strjm = new String(jm); var strjd = new String(jd);

if (jm < 10) strjm = "0" + jm; if (jd < 10) strjd = "0" + jd;

if (choice == 'y' || choice == 'Y') return String(jy); else if (choice == 'm' || choice == 'M') return strjm; else if (choice == 'd' || choice == 'D') return strjd; else return String(jy) + '/' + strjm + '/' +  strjd; }

$('#editform').append('');

$('#curr_date').click(function { var areaId = 'wpTextbox1'; var d = new Date; var text = GTJ(d.getFullYear, (d.getMonth+1), + d.getDate, 'a'); text += ' ~ ' + d.getFullYear + '/' +(d.getMonth+1) +'/'+ d.getDate;

var txtarea = document.getElementById(areaId); var scrollPos = txtarea.scrollTop; var strPos = 0; var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?        "ff" : (document.selection ? "ie" : false ) );

if ($.browser.msie) { txtarea.focus; var range = document.selection.createRange; range.moveStart ('character', -txtarea.value.length); strPos = range.text.length; }   else if (br == "ff") strPos = txtarea.selectionStart;

var front = (txtarea.value).substring(0,strPos); var back = (txtarea.value).substring(strPos,txtarea.value.length); txtarea.value=front+text+back; strPos = strPos + text.length; if (br == "ie") { txtarea.focus; var range = document.selection.createRange; range.moveStart ('character', -txtarea.value.length); range.moveStart ('character', strPos); range.moveEnd ('character', 0); range.select; }   else if (br == "ff") { txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus; }   txtarea.scrollTop = scrollPos; });