jQuery(document).ready(function(){
if(wgNamespaceNumber == 0 && (wgAction=='edit'||wgAction=='submit') && document.getElementById("wpTextbox1")){
var editformstartstate = document.getElementById("wpTextbox1").value;
var clickedbutton, nowsubmit;
$("#editform ").click(function(){clickedbutton=this});
$("#editform").submit(function(e){
if(editformstartstate.indexOf("-syncforms|") > -1 || document.getElementById("wpTextbox1").value.indexOf("-syncforms|") > -1){
var rr = /(+)(==\n*?\{\{+-syncforms\|)(+)\}\}+?(?=(----|\]+:|$))/g;
var t = rr.exec(document.getElementById("wpTextbox1").value);rr.exec();
var g = rr.exec(editformstartstate);
var th=this;
for(var x = {}, y = {}, i = 0; t && t; i += 5) {
y] = ,t]; // y = {langname:}
}
if(clickedbutton && (clickedbutton.id == "wpPreview" || clickedbutton.id == "wpDiff")){
$.each(y, function(d,e){ // d = langname, e =
var h = $.inArray(d, g);
if(e != (g&&g)){
th.action += "§ionsync"+d+"=true"
} else {
delete y
}
})
for(var i = 1, a = location.search.split("§ionsync"); a; i++){
if(!(a in y)){
th.action += "§ionsync"+a;
}
}//e.preventDefault();
} else {
if(!nowsubmit){
var tasks = 0, b = {};
$.each(y, function(d, e){ // d = language, e =
var h = $.inArray(d, g);//console.log(e)
if(e != g || location.search.indexOf("§ionsync"+d) != -1){
$.each(e.split("|"), function(kk,k){
if(k != wgPageName.replace(/\_/g,' ')){
b = b || ;
b.push(d) // reformatting into b={entry:}
}
})
}
});//e.preventDefault();return;
$.each(b, function(vv,v){
tasks++;
JsMwApi().page(vv).edit(function(text,save){
$.each(v, function(ll,l){
var st = text.indexOf(l+"==\n"), end = text.indexOf("----", st); end = end==-1?text.length:end;
if(text.length == 0){
text = "==" + y
}
else if(st == -1){
text += "\n----\n\n==" + y
}
else{
text = text.substr(0,st) + y + text.substr(end)
}
})
save(text, {summary:"autosync from ]"}, function(){
if(!--tasks){
nowsubmit = true;
$("#editform").submit();
}
})
})
})
e.preventDefault();
}
}
}
})
}
})