Jump to content
Wikipedia The Free Encyclopedia

User:MJL/Archer.js

From Wikipedia, the free encyclopedia
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.
This user script seems to have a documentation page at User:MJL/Archer.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
 // This is a modified version of [[User:Sam Sailor/Scripts/Sagittarius+.js]] ([[Special:Diff/899155791]])
 // Such script itself was a modified version of [[User:Kephir/gadgets/sagittarius.js]] ([[Special:PermaLink/785248045]])
 // Some code was also stolen from [[User:Wugapodes/Capricorn.js]] ([[Special:Permalink/1043412413]])
 // Docs: [[User:MJL/Archer]]
 // <nowiki>

 /*jshint undef:true, latedef:true, shadow:true, loopfunc:true, scripturl:true, undef:true */
 /*globals jQuery, mw, importStylesheet */
 mw.loader.using(['jquery.suggestions','mediawiki.api','mediawiki.Title','mediawiki.action.view.redirectPage'],function(){// <nowiki>
 'use strict';

 if(mw.config.get('wgNamespaceNumber')<0)
 return;

 functionnormaliseAnchor(anchor){
 functionencodeCodePoint(c){
 if(c===0x20)
 return'_';
 if(c<0x80){
 return'.'+c.toString(16).toUpperCase();
 }elseif(c<0x800){
 return'.'+(0xc0|(c>>>6)).toString(16).toUpperCase()+
 '.'+(0x80|(c&0x3f)).toString(16).toUpperCase();
 }elseif(c<0x10000){
 return'.'+(0xe0|(c>>>12)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>6)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|(c&0x3f)).toString(16).toUpperCase();
 }elseif(c<0x200000){
 return'.'+(0xf0|(c>>>18)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>12)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>6)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|(c&0x3f)).toString(16).toUpperCase();
 }elseif(c<0x4000000){
 return'.'+(0xf8|(c>>>24)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>18)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>12)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>6)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|(c&0x3f)).toString(16).toUpperCase();
 }elseif(c<0x80000000){
 return'.'+(0xfc|(c>>>30)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>24)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>18)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>12)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|((c>>>6)&0x3f)).toString(16).toUpperCase()+
 '.'+(0x80|(c&0x3f)).toString(16).toUpperCase();
 }
 }

 // "." is not escaped!
 returnanchor.replace(/[^0-9A-Za-z_:\.]/g,function(m){/* [\ud800-\udbff][\udc00-\dfff]| */
 if(m.length===2){// surrogate pair
 returnencodeCodePoint((m.charCodeAt(0)&0x3ff)<<10|m.charCodeAt(1)&0x3ff);
 }else{
 returnencodeCodePoint(m.charCodeAt(0));
 }
 });
 }

 functionnormaliseTitle(title){
 try{
 vart=newmw.Title(title);
 returnt.getPrefixedText();
 }catch(e){
 returnnull;
 }
 }

 functionel(tag,child,attr,events){
 varnode=document.createElement(tag);

 if(child){
 if((typeofchild==='string')||(typeofchild.length!=='number'))
 child=[child];
 for(vari=0;i<child.length;++i){
 varch=child[i];
 if((ch===void(null))||(ch===null))
 continue;
 elseif(typeofch!=='object')
 ch=document.createTextNode(String(ch));
 node.appendChild(ch);
 }
 }

 if(attr)for(varkeyinattr){
 if((attr[key]===void(0))||(attr[key]===null))
 continue;
 node.setAttribute(key,String(attr[key]));
 }

 if(events)for(varkeyinevents){
 varhandler=events[key];
 if((key==='input')&&(window.oninput===void(0))){
 key='change';
 }
 node.addEventListener(key,handler,false);
 }

 returnnode;
 }

 functionlink(child,href,attr,ev){
 attr=attr||{};
 ev=ev||{};
 if(typeofattr==='string'){
 attr={"title":attr};
 }
 if(typeofhref==='string')
 attr.href=href;
 else{
 attr.href='javascript:void(null);';
 ev.click=href;
 }
 returnel('a',child,attr,ev);
 }

 vartemplateGroups={
 "fromabbreviationcapitalisationandgrammar":"From – abbreviation, capitalisation, and grammar",
 "frompartsofspeach":"From parts of speach",
 "fromspelling":"From – spelling",
 "fromalternativenamesgeneral":"From alternative names, general",
 "fromalternativenamesgeography":"From alternative names, geography",
 "fromalternativenamespeople":"From alternative names, people",
 "fromalternativenamesscientific":"From alternative names, scientific",
 "fromalternativenamestechnical":"From alternative names, technical",
 "frompostalinfo":"From postal information",
 "fromcomics":"From comics",
 "fromdisambiguations":"From disambiguations",
 "fromfiction":"From fiction",
 "frommiddleearth":"From Middle Earth",
 "fromisocodes":"From ISO codes",
 "fromrelatedinfo":"From related info",
 "frommusic":"From music",
 "fromsocialmedia":"From social media",
 "fromrelatedpeople":"From related people",
 "fromtransportation":"From – transportation",
 "frommergersduplicatesandmoves":"From mergers, duplicates, and moves",
 "fromnavigation":"From – navigation",
 "togrammarpunctuationandspelling":"To – grammar, punctuation, and spelling",
 "toalternativenames":"To alternative names",
 "tonavigationanddisambiguation":"To – navigation and disambiguation",
 "tonamespaces":"To namespaces",
 "tocomics":"To comics",
 "tomiddleearth":"To Middle Earth",
 "totime":"To time articles",
 "totemplates":"To Wikipedia templates",
 "tomiscellaneous":"To miscellaneous",
 "misc":"Miscellaneous"
 };

 functionmainCallback(aliasJSON,templateJSON){
 vartemplateAliases=aliasJSON;
 varredirectTemplates=templateJSON;
 //console.log(templateAliases);
 //console.log(redirectTemplates);
 // <nowiki>
 'use strict';

 importStylesheet('User:MJL/Archer/Kephir.css');

 varwgNamespaceIds=mw.config.get('wgNamespaceIds');
 varapi=newmw.Api();
 varcontentText=document.getElementById('mw-content-text');
 varfirstHeading=document.getElementById('firstHeading');
 varredirMsg=contentText.getElementsByClassName('redirectMsg')[0];
 varuiWrapper=el('div');
 varedittoken=null;

 functionMarkupBlob(markup){
 if(!markup){
 this.target='';
 this.rcatt={};
 this.tail='';
 }else
 this.parse(markup);
 }

 MarkupBlob.prototype.parse=function(markup){
 varrdrx=/^#REDIRECT\s*\[\[\s*([^\|{}[\]]+?)\s*]]\s*/i;
 vartprx=/^\s*{{([A-Za-z ]+)((?:\|(?:[^|{}]*|{{[^|}]*}})+)*)}}\s*/i;
 varm;

 if(!(m=rdrx.exec(markup.trim())))
 thrownewError('Not a redirect');
 markup=markup.substr(m[0].length);
 this.target=m[1];

 this.rcatt={};
 out:while((m=tprx.exec(markup))){
 varalias=normaliseTitle(m[1]);
 while(templateAliases[alias])
 alias=templateAliases[alias];// hopefully there are no loops.

 if(alias==="This is a redirect"){
 varparams=m[2].split('|');
 for(varj=0;j<params.length;++j){
 if(!params[j])
 continue;
 if(params[j].indexOf('=')!==-1)
 breakout;
 alias=normaliseTitle("R "+params[j]);
 while(templateAliases[alias])
 alias=templateAliases[alias];// hopefully there are still no loops.
 if(aliasinredirectTemplates)
 this.rcatt[alias]=true;
 else
 breakout;
 }
 }elseif(alias==="Redirect category shell"){
 varmm,rr=/{{(.*?)}}/g;
 while(mm=rr.exec(m[2])){
 alias=normaliseTitle(mm[1]);
 while(templateAliases[alias])
 alias=templateAliases[alias];
 if(aliasinredirectTemplates)
 this.rcatt[alias]=true;
 }
 }elseif(aliasinredirectTemplates){
 if(m[2])// TODO
 break;
 this.rcatt[alias]=true;
 }else{
 break;
 }
 markup=markup.substr(m[0].length);
 }

 this.tail=markup;
 };

 MarkupBlob.prototype.toString=function(){
 varmarkup='#REDIRECT [['+this.target+']]';
 vartail='';
 varwrapped=[];
 for(varkeyinthis.rcatt){
 if(this.rcatt[key])
 if((wrapped.length<6)&&/^R\s+/.test(key))
 wrapped.push('{{'+key+'}}\n');
 else
 tail+='{{'+key+'}}\n';

 }
 if(wrapped.length)
 markup+="\n{{Redirect category shell|\n"+wrapped.join("")+"}}\n";
 markup+=tail+'\n';
 markup+=this.tail;
 returnmarkup;
 };

 functionbuildTagList(rcatt){
 functionmakeCheckBox(key){
 returnel('label',[
 el('input',null,{
 type:"checkbox",
 checked:(keyinrcatt)?"checked":null,
 },{
 change:function(ev){
 rcatt[key]=this.checked;
 }
 }),
 ' ',
 redirectTemplates[key].label
 ],{
 "title":redirectTemplates[key].tooltip
 });
 }
 varlist=el('dl',null,{"class":"tag-list"});
 vargroup={};
 for(varkeyintemplateGroups){
 list.appendChild(el('dt',templateGroups[key]));
 list.appendChild(el('dd',group[key]=el('ul')));
 }
 for(varkeyinredirectTemplates){
 varlabel=makeCheckBox(key);
 group[redirectTemplates[key].group].appendChild(el('li',label));
 }
 returnlist;
 }

 functionbuildEditingUI(mblob,saveCallback){
 varstatusbar;
 varneedsCheck=true;
 vardoSave;
 varuiLink,uiTarget;
 mblob=mblob||newMarkupBlob();

 functionsetStatus(status){
 while(statusbar.firstChild)
 statusbar.removeChild(statusbar.firstChild);
 if(status){
 if(typeofstatus==='string')
 statusbar.appendChild(document.createTextNode(status));
 else{
 for(varj=0;j<status.length;++j){
 if(typeofstatus[j]==='string')
 statusbar.appendChild(document.createTextNode(status[j]));
 else
 statusbar.appendChild(status[j]);
 }
 }
 }
 }

 functioninputChanged(ev){
 /*jshint validthis:true */
 try{
 mblob.target=this.value;
 vart=newmw.Title(this.value);
 varfrag=t.getFragment()?'#'+normaliseAnchor(t.getFragment()):'';
 uiLink.href=mw.util.getUrl(t.getPrefixedDb(),{redirect:"no"})+frag;
 setStatus();
 }catch(e){
 setStatus('Invalid title.');
 if(uiLink)uiLink.href='javascript:void(0);';
 }
 needsCheck=true;
 }

 varuiStatusLine;
 varui=el('form',[
 el('div',[
 el('ul',[
 el('li',[
 uiTarget=el('input',null,{
 'type':'text',
 'class':'redirectText',
 'value':mblob.target
 },{
 'input':inputChanged,
 'change':inputChanged,
 'blur':function(ev){// i would not have to write this, if it were not for jQuery. seriously.
 if(mblob.target===this.value)
 return;
 inputChanged.call(this,ev);
 }
 })
 ])
 ],{'class':'redirectText'})
 ],{'class':'redirectMsg'}),
 buildTagList(mblob.rcatt),
 uiStatusLine=el('p',[
 statusbar=el('span',[],{
 'class':'status-line'
 }),
 el('span',[
 link(["Statistics for this page"],'https://tools.wmflabs.org/pageviews?project=en.wikipedia.org&pages='+encodeURIComponent(mw.config.get('wgPageName'))),
 ' • ',
 link(["WP:TMR"],mw.util.getUrl("Wikipedia:Template messages/Redirect pages")),
 ' • ',
 link(["About Archer"],mw.util.getUrl("User:MJL/Archer"))
 ],{
 'style':'float: right;'
 })
 ])
 ],{
 'action':'javascript:void(0)',
 'class':'kephir-sagittarius-editor'
 },{
 'submit':function(ev){
 ev.preventDefault();
 ui.doCheck(saveCallback);
 }
 });
 ui.statusLine=uiStatusLine;

 varsectCache={};
 var$uiTarget=jQuery(uiTarget);
 $uiTarget.suggestions({
 submitOnClick:false,
 delay:500,
 fetch:function(query){
 $uiTarget.suggestions('suggestions',[]);
 if(query.indexOf('#')!==-1){
 vartitle=query.substr(0,query.indexOf('#'));
 varsect=query.substr(query.indexOf('#')+1);

 if(sectCache[title]){
 varnormSect=normaliseAnchor(sect);
 $uiTarget.suggestions('suggestions',
 sectCache[title].filter(function(item){
 varnorm=normaliseAnchor(item.anchor);
 returnnorm.substr(0,normSect.length)===normSect;
 })
 );
 return;
 }

 api.get({
 action:'parse',
 page:title,
 prop:'sections|properties',
 redirects:'1'
 }).then(function(result){
 if(result.parse.redirects&&result.parse.redirects.length){
 // XXX
 return;
 }

 vardisambig=false;// XXX

 varnormSect=normaliseAnchor(sect);
 sectCache[title]=result.parse.sections.map(function(item){
 return{
 anchor:item.anchor,
 title:title+'#'+decodeURIComponent(item.anchor.replace(/_/g,' ').replace(/\.([0-9A-Fa-f][0-9A-Fa-f])/g,'%')),// XXX: hack
 disambig:disambig,
 toString:function(){
 returnthis.title;
 }
 };
 });

 $uiTarget.suggestions('suggestions',
 sectCache[title].filter(function(item){
 varnorm=normaliseAnchor(item.anchor);
 returnnorm.substr(0,normSect.length)===normSect;
 })
 );
 });
 return;
 }

 api.get({
 action:'query',
 generator:'allpages',
 gapprefix:query,
 gaplimit:16,
 prop:'info|pageprops',
 }).then(function(result){
 varpglist=[];
 for(varpgidinresult.query.pages){
 varpage=result.query.pages[pgid];
 pglist.push({
 title:page.title,
 pageid:page.pageid,
 disambig:page.pageprops&&('disambiguation'inpage.pageprops),
 redirect:'redirect'inpage,
 toString:function(){
 returnthis.title;
 }
 });
 }
 $uiTarget.suggestions('suggestions',pglist);
 });
 },
 result:{
 render:function(item,content){
 varelm=this[0];
 elm.appendChild(el('span',[item.title],{
 style:item.redirect?'font-style: italic':''
 }));
 if(item.disambig)
 elm.appendChild(el('small',[' (disambiguation page)']));
 if(item.redirect)
 elm.appendChild(el('small',[' (redirect)']));
 },

 select:function($textbox){
 varitem=this.data('text');
 vartextbox=$textbox[0];

 textbox.value=item.title;
 if(item.redirect){
 api.get({
 action:'query',
 pageids:item.pageid,
 redirects:'1'
 }).then(function(result){
 varredir=result.query.redirects.pop();
 textbox.value=redir.to+(redir.tofragment?'#'+redir.tofragment:'');
 });
 }

 returntrue;
 }
 }
 });

 ui.doCheck=function(callback){
 varthat=this;

 if(!/^\s*[^\|{}[\]]+\s*$/.test(mblob.target)){
 setStatus(['Error: the target page name is invalid.']);
 return;
 }

 if(needsCheck){
 varoldTarget=mblob.target;
 varnormTarget;
 try{
 normTarget=newmw.Title(oldTarget);
 }catch(e){
 setStatus(['"',oldTarget,'" is not a valid page name. Try again to proceed anyway.']);
 return;
 }

 setStatus(['Checking target validity...']);
 needsCheck=false;

 api.get({
 action:'parse',
 page:oldTarget=mblob.target,
 prop:'sections',
 redirects:'1'
 },{
 success:function(result){
 varm;
 if(result.error){
 if(result.error.code==='missingtitle'){
 setStatus([
 'Error: The target page "',
 link([normTarget.getPrefixedText()],mw.util.getUrl(normTarget.getPrefixedText(),{"class":"new"})),
 '" does not exist. Try again to proceed anyway.'
 ]);
 }else{
 setStatus([
 'API error: "',
 result.error.info,
 '" [code: ',el('code',[result.error.code]),']'
 ]);
 }
 return;
 }

 if(result.parse.redirects&&result.parse.redirects[0]){
 varnewTarget=result.parse.redirects[0].to+(result.parse.redirects[0].tofragment?"#"+result.parse.redirects[0].tofragment:"");
 setStatus([
 'Error: The target page "',
 link([normTarget.getPrefixedText()],mw.util.getUrl(normTarget.getPrefixedText(),{redirect:"no"})),
 '" is already a redirect to "',
 link([newTarget],mw.util.getUrl(newTarget,{redirect:"no"})),
 '". Try again to proceed anyway, or ',
 link(['retarget this redirect to point there directly'],function(){
 uiTarget.value=mblob.target=newTarget+
 ((!result.parse.redirects[0].tofragment&&normTarget.fragment)?'#'+normTarget.fragment:'');
 needsCheck=true;
 }),
 '.'
 ]);
 return;
 }

 if(normTarget.fragment){// we have a section link
 varsect=normaliseAnchor(normTarget.fragment);
 varisValidSect=false;

 varsectlist=result.parse.sections;
 for(varj=0;j<sectlist.length;++j){
 if(sectlist[j].anchor===sect)
 isValidSect=true;
 }

 if(!isValidSect){
 setStatus([
 'Error: The target page "',
 link([normTarget.getPrefixedText()],mw.util.getUrl(normTarget.getPrefixedText(),{redirect:"no"})),
 '" does not have a section called "',
 normTarget.fragment,
 '". Try again to proceed anyway.'
 ]);

 return;
 }
 }

 callback(setStatus);
 }
 });

 return;
 }

 callback(setStatus);
 };

 returnui;
 }

 if((mw.config.get('wgAction')==='view')&&(mw.config.get('wgArticleId')===0)){// nonexistent page.
 uiWrapper.appendChild(el('div',[
 link(['Create a redirect'],function(){
 while(uiWrapper.hasChildNodes())
 uiWrapper.removeChild(uiWrapper.firstChild);
 varmblob=newMarkupBlob();
 varui=buildEditingUI(mblob,function(setStatus){
 setStatus(['Saving...']);
 api.post({
 action:'edit',
 title:mw.config.get('wgPageName'),
 token:mw.user.tokens.get('csrfToken'),
 createonly:1,
 summary:'Redirecting to [['+mblob.target+']] ([[User:MJL/Archer|Archer]])',
 text:mblob.toString()
 },{
 success:function(result){
 if(result.error){
 setStatus([
 'API error: "',
 result.error.info,
 '" [code: ',el('code',[result.error.code]),']'
 ]);
 return;
 }
 setStatus(['Saved. Reloading page...']);
 if(/redirect=no/.test(location.href))// XXX
 location.reload();
 else
 location.search=location.search?location.search+'&redirect=no':'?redirect=no';
 }
 });
 });
 ui.statusLine.insertBefore(el('input',null,{
 type:'submit',
 value:'Save'
 }),ui.statusLine.firstChild);
 uiWrapper.appendChild(ui);
 }),' from this page with Archer'
 ],{
 "class":"kephir-sagittarius-invite"
 }));
 contentText.parentNode.insertBefore(uiWrapper,contentText);
 }elseif((mw.config.get('wgAction')==='view')&&mw.config.get('wgIsRedirect')&&redirMsg){
 // start editor immediately
 uiWrapper.appendChild(el('div',['Loading page source...'],{
 "class":"kephir-sagittarius-loading"
 }));
 contentText.insertBefore(uiWrapper,contentText.firstChild);
 api.get({
 action:'query',
 prop:'info|revisions',
 rvprop:'timestamp|content',
 pageids:mw.config.get('wgArticleId'),
 rvstartid:mw.config.get('wgRevisionId'),
 rvlimit:1,
 rvdir:'older',
 intoken:'edit',
 },{
 success:function(result){
 if(result.error){
 uiWrapper.appendChild(el('div',[
 'API error: "',
 result.error.info,
 '" [code: ',el('code',[result.error.code]),']. Reload to try again.'
 ],{
 "class":"kephir-sagittarius-error"
 }));
 return;
 }
 while(uiWrapper.hasChildNodes())
 uiWrapper.removeChild(uiWrapper.firstChild);
 varpage=result.query.pages[mw.config.get('wgArticleId')];
 varmblob;
 vartoken=page.edittoken;
 try{
 mblob=newMarkupBlob(page.revisions[0]['*']);
 }catch(e){
 uiWrapper.appendChild(el('div',['Error: unable to parse page. Edit the source manually.'],{
 "class":"kephir-sagittarius-error"
 }));
 return;
 }
 redirMsg.parentNode.removeChild(redirMsg);
 varui=buildEditingUI(mblob,function(setStatus){
 setStatus(['Saving...']);
 api.post({
 action:'edit',
 title:mw.config.get('wgPageName'),
 basetimestamp:page.revisions[0].timestamp,
 token:mw.user.tokens.get('csrfToken'),
 summary:'Redirecting to [['+mblob.target+']] ([[User:MJL/Archer|Archer]])',
 text:mblob.toString()
 },{
 success:function(result){
 if(result.error){
 setStatus([
 'API error: "',
 result.error.info,
 '" [code: ',el('code',[result.error.code]),']'
 ]);
 return;
 }
 setStatus(['Saved. Reloading page...']);
 if(/redirect=no/.test(location.href))// XXX
 location.reload();
 else
 location.search=location.search?location.search+'&redirect=no':'?redirect=no';
 }
 });
 });
 ui.statusLine.insertBefore(el('input',null,{
 type:'submit',
 value:'Save'
 }),ui.statusLine.firstChild);
 uiWrapper.appendChild(ui);
 }
 });
 }elseif((mw.config.get('wgPageContentModel')==='wikitext')&&((mw.config.get('wgAction')==='edit')||(mw.config.get('wgAction')==='submit'))){
 if(mw.util.getParamValue('section'))
 return;
 vareditform=document.getElementById('editform');

 if(editform.wpTextbox1.readOnly)
 return;

 varuiPivot=document.getElementsByClassName('wikiEditor-ui')[0];

 varui,mblob;
 firstHeading.appendChild(document.createTextNode(' '));
 firstHeading.appendChild(link(['♐'],function(){
 if(ui&&ui.parentNode)
 ui.parentNode.removeChild(ui);

 try{
 mblob=newMarkupBlob(editform.wpTextbox1.value);
 }catch(e){
 alert("Error: unable to parse page. This page is probably not a redirect.");
 return;
 }

 ui=buildEditingUI(mblob,function(){
 editform.wpSummary.value='Redirecting to [['+mblob.target+']] ([[User:MJL/Archer|Archer]])';
 editform.wpTextbox1.value=mblob.toString();
 mblob=null;
 ui.style.display='none';
 uiPivot.style.display='';
 });
 ui.style.display='none';
 ui.statusLine.insertBefore(el('input',null,{
 type:"button",
 value:"Cancel",
 },{
 click:function(){
 mblob=null;
 ui.style.display='none';
 uiPivot.style.display='';
 }
 }),ui.statusLine.firstChild);
 ui.statusLine.insertBefore(el('input',null,{
 type:"submit",
 value:"Check"
 }),ui.statusLine.firstChild);
 uiPivot.parentNode.insertBefore(ui,uiPivot);
 uiPivot.style.display='none';
 ui.style.display='';
 },{
 "class":"kephir-sagittarius-editlink",
 "title":"Edit this redirect with Archer"
 }));

 varsubmitButton;
 varinputs=editform.getElementsByTagName('input');
 for(vari=0;i<inputs.length;++i){
 inputs[i].addEventListener('click',function(ev){
 submitButton=this;
 },false);
 }

 editform.addEventListener('submit',function(ev){
 if(submitButton!==editform.wpSave)
 return;
 if(mblob){
 ev.preventDefault();
 ev.stopImmediatePropagation();
 ui.doCheck(function(setStatus){
 setStatus(['Proceeding with saving...']);
 editform.wpTextbox1.value=mblob.toString();
 editform.wpSummary.value='Redirecting to [['+mblob.target+']] ([[User:MJL/Archer|Archer]])';
 mblob=null;
 editform.submit();
 });
 }
 },false);
 }

 if(!window.kephirSagittariusFollowCategoryRedirects)
 if((mw.config.get('wgAction')==='view')&&(mw.config.get('wgNamespaceNumber')===wgNamespaceIds.category)){
 varpagesList=document.getElementById('mw-pages').getElementsByClassName('mw-redirect');
 for(vari=0;i<pagesList.length;++i){
 pagesList[i].href+='?redirect=no';
 }
 }
 }

 functionabortConditions(){
 if(window.location.href.includes('&diff=')){
 throw'Archer does not run when viewing page diffs. Please revert before editing redirect.';
 }

 if(mw.config.get('wgNamespaceNumber')<0){
 throw'Page is in a virtual namespace. Archer aborts.';
 }
 }

 functionArcherMain(){
 $.getJSON("https://en.wikipedia.org/w/index.php?title=User:MJL/Archer/Aliases.json&action=raw&ctype=application/json",function(aliasJSON){
 $.getJSON("https://en.wikipedia.org/w/index.php?title=User:MJL/Archer/Templates.json&action=raw&ctype=application/json",function(templateJSON){
 mw.loader.using(['jquery.suggestions','mediawiki.api','mediawiki.Title','mediawiki.action.view.redirectPage'],function(){
 mainCallback(aliasJSON,templateJSON);
 });
 });
 });
 }

 varapi=newmw.Api();

 api.get({
 action:"query",
 format:"json",
 prop:"info",
 formatversion:2,
 titles:mw.config.get('wgPageName')
 },{
 success:function(result){
 try{
 abortConditions();
 }catch(abortMessage){
 console.info(abortMessage)
 return;
 }
 if(result.query.pages[0].redirect||(window.location.href.includes('&redlink=1'))){
 ArcherMain();
 }else{
 console.debug('Page is not a redirect.')
 return;
 }
 }
 });

 });

 // </nowiki>
 /*
 [[Category:Wikipedia scripts]]
 */

AltStyle によって変換されたページ (->オリジナル) /