Jump to content
Wikimedia Meta-Wiki

User:ASammour/test.js

From Meta, a Wikimedia project coordination wiki

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
 if(mw.config.get('wgArticleId')==130130){//Works only in Steward requests/Global
 mw.loader.using(["mediawiki.api"]).then(function(){
 varmyArray=[];

 /*Counting the sections in the page*/
 $(".toctext").each(function(index){
 myArray[index]=$(this).text();// Setting the index to the section title
 });

 //A function to get the index of specified section tit
 functiongetIndex(title){
 varresult=0;
 for(vari=1;i<myArray.length;i++){
 if(myArray[i]==title){
 result=i;
 break;
 }
 }
 returnresult;
 }

 //Append X close button beside each section
 $(".mw-editsection").each(function(){
 $(this).append(" <span class = 'closeButton' style = 'color: white;background-color: #f95a5a;border: 1px white dashed;border-radius: 3px;cursor:pointer;'>X Close</span>");
 });

 $(document).on('click','.closeButton',function(){
 vardecision=prompt("Please answer if you want to mark the request as done (1) or notdone (0)");
 if(decision=="0"){
 decision="notdone";
 }
 elseif(decision=="1"){
 decision="done";
 }
 else{
 returnfalse;
 }

 //Get the content of the page
 varapi=newmw.Api();
 varcontent="";
 api.get({
 "action":"query",
 "format":"json",
 "prop":"revisions",
 "titles":"Steward requests/Global",
 "utf8":1,
 "rvprop":"content",
 "formatversion":"latest",
 }).done(function(result){
 content=result.query.pages[0].revisions[0].content;
 });

 //Get the content of the section
 varsectionContent=api.get({
 "action":"query",
 "format":"json",
 "prop":"revisions",
 "titles":"Steward requests/Global",
 "utf8":1,
 "rvprop":"content",
 "formatversion":"latest",
 "rvsection":parseInt(getIndex($(this).parent().prev().text()))+1
 }).done(function(result){
 varsectionContent=result.query.pages[0].revisions[0].content.toString();

 //Replace the status
 varnewSectionContent="";
 newSectionContent=sectionContent.replace("{{status}}","{{status|"+decision+"}}");
 newSectionContent=newSectionContent.replace("{{Status}}","{{status|"+decision+"}}");
 newSectionContent=newSectionContent.replace("{{Status|}}","{{status|"+decision+"}}");
 newSectionContent=newSectionContent.replace("{{status|}}","{{status|"+decision+"}}");

 //Add {{done}} or {{notdone}}
 newSectionContent=newSectionContent+"\n\n{{"+decision+"}}.-\~\~\~\~";

 content=content.replace(sectionContent,newSectionContent);

 if(content!=""){
 //Edit goes here
 edit(content,($(this).parent().prev().text()),decision);
 }
 });
 });

 functionedit(content,title,decision){
 newmw.Api().edit(
 'Steward requests/Global',
 function(){
 return{
 text:content,
 summary:"Re: "+title+" {{"+decision+"}}",
 minor:true
 };
 }
 )
 .then(function(){
 alert("Done!");
 console.log('Done!');
 });
 }
 });
 }

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