User:Yethrosh/HotInterwiki.js
Appearance
(Redirected from User:محمد شعیب/HotInterwiki.js)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Yethrosh/HotInterwiki. This user script seems to have an accompanying .css page at User:Yethrosh/HotInterwiki.css. |
//[[:fr:Projet:JavaScript/Notices/HotInterwiki]]
//<source lang=javascript>//<pre>//<nowiki>
//***********************************************
// متغيرات
//////////////////////
// متن
var HotInterwiki_Text = new Array();
HotInterwiki_Text["Autres langues"] = "دیگر زبانیں";
HotInterwiki_Text["(-)"] = "(-)";
HotInterwiki_Text["ConfirmRemove"] = "کیا آپ ربط حذف کرنا چاہتے ہیں\n[[$1]]";
HotInterwiki_Text["SummaryRemove"] = "ربط حذف کریں [[$1]]";
HotInterwiki_Text["(±)"] = "(±)";
HotInterwiki_Text["ConfirmModify"] = "کیا آپ ربط تبدیل کرنا چاہتے ہیں\n[[$1]]\nبجانب\n[[$2]]\n";
HotInterwiki_Text["SummaryModify"] = "منتقل ربط برائے [[$1]] بجانب [[$2]]";
HotInterwiki_Text["(+)"] = "(+)";
HotInterwiki_Text["ConfirmAdd"] = "کیا آپ ربط کا اضافہ کرنا چاہتے ہیں\n[[$1]]";
HotInterwiki_Text["SummaryAdd"] = "اضافہ ربط برائے زبان [[$1]]";
HotInterwiki_Text["IntputOK"] = "ٹھیک";
HotInterwiki_Text["IntputCancel"] = "منسوخ";
HotInterwiki_Text["InterwikiTemplate"] = "$1:$2";
HotInterwiki_Text["InterwikiError"] = "ربط درست نہیں";
//////////////////////
// وسائط
var HotInterwiki_Param = new Array();
HotInterwiki_Param["AutoSubmit"] = true;
//////////////////////
// دیگر متغیرات
var HotInterwiki_Matrix = new Array();
HotInterwiki_Matrix['li'] = new Array();
HotInterwiki_Matrix['interwiki'] = new Array();
HotInterwiki_Matrix['form'] = new Array();
// ***********************************************
// حرکت
if(wgNamespaceNumber>-1&&document.URL.indexOf("printable=yes")==-1&&wgAction!="history"){
// Importation styles CSS
importStylesheetURI('//http://en.wikipedia.org/wiki/User:%D9%85%D8%AD%D9%85%D8%AF_%D8%B4%D8%B9%DB%8C%D8%A8/HotInterwiki.css');
// Lancement
addOnloadHook(HotInterwiki_Init);
}
// ***********************************************
// آغاز
function HotInterwiki_Init(){
if(typeof(HotInterwiki_LangCustom)=="function") HotInterwiki_LangCustom();
if(typeof(HotInterwiki_SiteCustom)=="function") HotInterwiki_SiteCustom();
if(typeof(HotInterwiki_UserCustom)=="function") HotInterwiki_UserCustom();
var PLang = document.getElementById('p-lang');
if(!PLang) PLang = HotInterwiki_CreatePLang();
if(!PLang) return;
HotInterwiki_ModifyUl(PLang);
HotInterwiki_AddIWLi(PLang);
}
// ***********************************************
// قطعہ "دیگر زبانیں"
function HotInterwiki_CreatePLang(){
try{
var Target = document.getElementById('p-tb');
var TargetClassName = Target.className
var TargetBodyClassName = Target.getElementsByTagName('div')[0].className;
}catch(e){
return false;
}
var PLang = document.createElement('div');
PLang.id = "p-lang";
PLang.className = TargetClassName
var H5Lang = document.createElement('h5');
H5Lang.appendChild(document.createTextNode(HotInterwiki_Text["Autres langues"]));
var BodyLang = document.createElement('div');
BodyLang.className = TargetBodyClassName;
BodyLang.appendChild(document.createElement('ul'));
PLang.appendChild(H5Lang);
PLang.appendChild(BodyLang);
Target.parentNode.appendChild(PLang);
return PLang;
}
// ***********************************************
// ربط کو تبدیل یا ختم کرنا
function HotInterwiki_ModifyUl(PLang){
var Ul = PLang.getElementsByTagName('ul')[0];
if(!Ul) return;
var Lis = Ul.getElementsByTagName('li');
for(var a=0,l=Lis.length;a<l;a++){
var Li = Lis[a];
HotInterwiki_Matrix['li'][a] = Li;
Li.id = "Interwiki_"+a;
var Link = Li.getElementsByTagName('a')[0];
var LinkText = Link.title;
var Lang = Li.className.split("interwiki-").join("");
HotInterwiki_Matrix['interwiki'][a] = Lang + ":" + LinkText;
var SpanLinks = document.createElement('span');
var RemoveLink = document.createElement('a');
RemoveLink.href = "javascript:HotInterwiki_RemoveIW("+a+");";
RemoveLink.appendChild(document.createTextNode(HotInterwiki_Text["(-)"]));
var ModifyLink = document.createElement('a');
ModifyLink.href = "javascript:HotInterwiki_CreateForm("+a+");";
ModifyLink.appendChild(document.createTextNode(HotInterwiki_Text["(±)"]));
SpanLinks.appendChild(document.createTextNode(" "));
SpanLinks.appendChild(RemoveLink);
SpanLinks.appendChild(document.createTextNode(" "));
SpanLinks.appendChild(ModifyLink);
Li.appendChild(SpanLinks);
}
}
// ***********************************************
// ربط کا اضافہ
function HotInterwiki_AddIWLi(PLang){
var Ul = PLang.getElementsByTagName('ul')[0];
if(!Ul) return;
var AddLi = document.createElement('li');
AddLi.id = "Interwiki_1000";
var AddLink = document.createElement('a');
AddLink.appendChild(document.createTextNode(HotInterwiki_Text["(+)"]));
AddLink.href = "javascript:HotInterwiki_CreateForm(1000);";
AddLi.appendChild(AddLink);
Ul.appendChild(AddLi);
HotInterwiki_Matrix['li'][1000] = AddLi;
HotInterwiki_Matrix['interwiki'][1000] = "";
}
// ***********************************************
// ربط کو حذف کرنا
function HotInterwiki_RemoveIW(LiID){
var Li = document.getElementById("Interwiki_"+LiID);
var Lang = Li.className.split("interwiki-").join("");
var Link = Li.getElementsByTagName('a')[0];
var Text = Link.title;
var Interwiki = HotInterwiki_Text["InterwikiTemplate"].split('$1').join(Lang).split('$2').join(Text)
var SurEtCertain = confirm(HotInterwiki_Text["ConfirmRemove"].split('$1').join(Interwiki));
if(SurEtCertain) HotInterwiki_Edit(Interwiki, false);
}
// ***********************************************
// توثیق برائے اضافہ وحذف
function HotInterwiki_CreateForm(Index){
var Li = document.getElementById("Interwiki_"+Index);
if(!Li) return;
var Link = Li.getElementsByTagName('a')[0];
var Span = Li.getElementsByTagName('span')[0];
if(Link) Link.style.display = "none";
if(Span) Span.style.display = "none";
var Form = document.createElement('form');
Form.style.display = "inline";
Form.id = "InterwikiForm_"+Index;
Form.method = "post" ;
Form.onsubmit = function () {
var FormIndex = HotInterwiki_getIndex(this);
HotInterwiki_OK(FormIndex);
return false;
} ;
var InputText = document.createElement('input');
InputText.type = "text";
InputText.value = HotInterwiki_Matrix['interwiki'][Index];
var InputOK = document.createElement('input');
InputOK.type = "button";
InputOK.id = "InterwikiOKInput_"+Index;
InputOK.className = "InterwikiInput";
InputOK.value = HotInterwiki_Text["IntputOK"];
InputOK.onclick = function(){
var FormIndex = HotInterwiki_getIndex(this);
HotInterwiki_OK(FormIndex);
}
InputOK.onselect = function(){
var FormIndex = HotInterwiki_getIndex(this);
HotInterwiki_OK(FormIndex);
}
var InputCancel = document.createElement('input');
InputCancel.type = "button";
InputCancel.id = "InterwikiOKInput_"+Index;
InputCancel.className = "InterwikiInput";
InputCancel.value = HotInterwiki_Text["IntputCancel"];
InputCancel.onclick = function(){
var FormIndex = HotInterwiki_getIndex(this);
HotInterwiki_Cancel(FormIndex);
}
InputCancel.onselect = function(){
var FormIndex = HotInterwiki_getIndex(this);
HotInterwiki_Cancel(FormIndex);
}
Form.appendChild(InputText);
Form.appendChild(InputOK);
Form.appendChild(InputCancel);
Li.appendChild(Form);
HotInterwiki_Matrix['form'][Index] = Form;
}
// ***********************************************
// توثیق برائے اضافہ وتبدیلی برائے ربط
function HotInterwiki_OK(FormIndex){
var Li = HotInterwiki_Matrix['li'][FormIndex];
var Form = HotInterwiki_Matrix['form'][FormIndex];
var OldText = HotInterwiki_Matrix['interwiki'][FormIndex];
var NewText = Form.getElementsByTagName('input')[0].value;
if(NewText == "") return;
var IWRegExp = new RegExp('^([a-z][a-z].?(x?-[^\\]]+)?|simple|tokipona):([^\\]]*)$');
if(NewText.match(IWRegExp)==null){
alert(HotInterwiki_Text["InterwikiError"]);
return;
}
var ConfirmText;
if(OldText == ""){
ConfirmText = HotInterwiki_Text["ConfirmAdd"].split('$1').join(NewText);
OldText = false;
}else{
ConfirmText = HotInterwiki_Text["ConfirmModify"].split('$1').join(OldText).split('$2').join(NewText);
}
var SurEtCertain = confirm(ConfirmText);
if(SurEtCertain) HotInterwiki_Edit(OldText, NewText);
}
// ***********************************************
// منسوخی ربط
function HotInterwiki_Cancel(FormIndex){
var Li = HotInterwiki_Matrix['li'][FormIndex];
var Form = HotInterwiki_Matrix['form'][FormIndex];
Form.parentNode.removeChild(Form);
var Link = Li.getElementsByTagName('a')[0];
var Span = Li.getElementsByTagName('span')[0];
if(Link) Link.style.display = "";
if(Span) Span.style.display = "";
}
// ***********************************************
// آغاز ترمیم
function HotInterwiki_Edit(IWtoRemove, IwToAdd){
var URL = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + wgPageName.replace(/&/g, "%26") + '&action=edit';
var NouvelleRequete = sajax_init_object();
NouvelleRequete.open("GET", URL, true);
NouvelleRequete.onreadystatechange = function() {
if(NouvelleRequete.readyState != 4) return;
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = NouvelleRequete.responseText;
HotInterwiki_DoEdit(IWtoRemove, IwToAdd);
}
NouvelleRequete.send(null);
}
// ***********************************************
// تبدیلی
function HotInterwiki_DoEdit(IWtoRemove, IwToAdd){
var OldText = document.getElementById("wpTextbox1").value;
var IWRegExp = new RegExp('^\\s*\\[\\[([a-z][a-z].?(x?-[^\\]]+)?|simple|tokipona):([^\\]]*)\\]\\]\\s*$');
var blankRegExp = new RegExp('^\\s*$');
var lines = OldText.split('\n');
var BeforeInterwikis = new Array();
var Interwikis = new Array();
var FoundInterwiki = false;
for (var lineId = lines.length - 1; lineId >= 0; --lineId){
if (!IWRegExp.exec(lines[lineId]) && !blankRegExp.exec(lines[lineId])){
BeforeInterwikis = lines.slice(0, lineId + 1);
Interwikis = lines.slice(lineId + 1);
break;
}
}
BeforeInterwikis = BeforeInterwikis.join('\n') + '\n';
Interwikis = Interwikis.join('\n');
var Summary = "";
if(IWtoRemove==false && IwToAdd!=false){ // ************ Add
if(Interwikis!=""){
Interwikis = Interwikis.replace(/^\n/, "");
Interwikis = Interwikis.split('\n');
Interwikis.push("[["+IwToAdd+"]]");
Interwikis = Interwikis.sort();
Interwikis = "\n" + Interwikis.join('\n');
}else{
Interwikis = "\n[["+IwToAdd+"]]\n";
}
Summary = HotInterwiki_Text["SummaryAdd"].split('$1').join(IwToAdd);
}else if(IWtoRemove!=false && IwToAdd==false){ // ****** Remove
Interwikis = Interwikis.split("[["+IWtoRemove+"]]\n").join("");
Summary = HotInterwiki_Text["SummaryRemove"].split('$1').join(IWtoRemove);
}else if(IWtoRemove!=false && IwToAdd!=false){ // ****** Modify
Interwikis = Interwikis.split("[["+IWtoRemove+"]]\n").join("[["+IwToAdd+"]]\n");
Interwikis = Interwikis.replace(/^\n/, "");
Interwikis = Interwikis.split('\n');
Interwikis = Interwikis.sort();
Interwikis = "\n" + Interwikis.join('\n');
Summary = HotInterwiki_Text["SummaryModify"].split('$1').join(IWtoRemove).split('$2').join(IwToAdd);
}
document.getElementById("wpTextbox1").value = BeforeInterwikis+Interwikis;
document.getElementById("wpSummary").value = Summary;
if(HotInterwiki_Param["AutoSubmit"]) document.editform.submit();
}
// ***********************************************
// استرجع
function HotInterwiki_getIndex(Element){
return parseInt(Element.id.replace(/[^0-9]/g, ""));
}
//</nowiki></pre></source>