Jump to content
Wikipedia The Free Encyclopedia

User:Awesome Aasim/editrequestor.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:Awesome Aasim/editrequestor.
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.
 // <nowiki>
 if(!EditRequestor){
 varEditRequestor={}
 mw.loader.using("jquery.ui",function(){
 $(document).ready(function(){
 EditRequestor.url=newURL(location);
 leturl=EditRequestor.url;
 if(mw.config.get('wgAction')=='edit'&&url.searchParams.get('section')=='new'&&url.searchParams.get('preload')=='Template:Submit an edit request/preload'){
 EditRequestor.requestPage='';
 EditRequestor.requestType='';
 varpreloadArray=EditRequestor.url.searchParams.getAll('preloadparams[]');
 EditRequestor.requestType=preloadArray[0];
 EditRequestor.requestPage=preloadArray[1];
 $('<form id="editrequestor-form"></form>').append('<p>Please make the change that you unambiguously would like to implement.</p><textarea id="editrequestor-area" disabled></textarea><textarea name="reason" id="editrequestor-reason" disabled placeholder="Explanation for change, or explanation of change if unsure what needs changing."></textarea><div id="editrequestor-reason-preview"></div>').dialog({
 'buttons':[{
 "text":"Submit",
 "click":asyncfunction(){
 // fetch diff
 letwikitext=$("#editrequestor-area").val();
 letreason=$("#editrequestor-reason").val();
 letcompareRes=await$.get(mw.config.get('wgScriptPath')+'/api.php',{
 'action':'compare',
 'format':'json',
 'fromtitle':EditRequestor.requestPage,
 'toslots':'main',
 'totext-main':wikitext
 });
 if(compareRes.error){
 alert(compareRes.error.info);
 return;
 }
 letdiffHTML=compareRes.compare['*'];
 diffHTML=diffHTML.replaceAll(/'/g,"&#39;");
 if(diffHTML==''&&reason==''){
 alert("Cannot complete the edit request. Change and reason is missing!");
 return;
 }elseif(diffHTML==''){
 if(!confirm("Change is missing. Make sure that the change is explained well in the reason field, or your edit request will be declined as unclear!")){
 return;
 }
 }elseif(reason==''){
 if(!confirm("Reason is missing. Your edit request may be declined if the reason for the uncontroversial change is not obvious!")){
 return;
 }
 }
 // place in edit request
 leteditRequestWikitext=`
 == ${url.searchParams.get("preloadtitle")} ==
 {{${EditRequestor.requestType}|1=${EditRequestor.requestPage}|answered=no}}
 ${diffHTML?`
 Please change the following (click show to expand diff):

 <table class="diff diff-type-table diff-contentalign-left diff-editfont-monospace mw-collapsible mw-collapsed">${diffHTML}</table>${reason?`

 Reason: ${reason}`:``}

 ~~~~
 `:reason+" ~~~~"}
 `;
 // save
 letsaveResult=await(newmw.Api()).postWithEditToken({
 "action":"edit",
 "title":mw.config.get("wgPageName"),
 "appendtext":editRequestWikitext,
 "summary":"Creating new edit request ([[User:Awesome Aasim/editrequestor|EditRequestor]])"
 })
 console.log(saveResult);
 if(saveResult.error){
 alert(saveResult.error.info);
 }else{
 letnexturl=newURL(location.href);
 nexturl.searchParams.delete("action");
 location.href=nexturl;
 }
 }
 },
 {
 "text":"Preview",
 "click":asyncfunction(){
 // preview change
 letwikitext=$("#editrequestor-area").val();
 letparsedText=await(newmw.Api()).parse(wikitext,{"title":EditRequestor.requestPage})
 $(`<div id="editrequestor-preview"></div>`).html(parsedText).dialog({modal:true,width:(0.75*window.innerWidth>300)?0.75*window.innerWidth:300});
 }
 },
 {
 "text":"Show change",
 "click":asyncfunction(){
 // show diff of change
 letwikitext=$("#editrequestor-area").val();
 letcompareRes=await$.get(mw.config.get('wgScriptPath')+'/api.php',{
 'action':'compare',
 'format':'json',
 'fromtitle':EditRequestor.requestPage,
 'toslots':'main',
 'totext-main':wikitext
 });
 console.log(compareRes);
 $(`<div id="editrequestor-change"></div>`).html(`
 <table class="diff diff-type-table diff-contentalign-left diff-editfont-monospace">
 <colgroup><col class="diff-marker">
 <col class="diff-content">
 <col class="diff-marker">
 <col class="diff-content">
 </colgroup>
 ${compareRes.compare['*']}</table>`).dialog({modal:true,width:(0.75*window.innerWidth>300)?0.75*window.innerWidth:300});
 }
 }
 ],
 width:(0.50*window.innerWidth>300)?0.50*window.innerWidth:300,
 modal:true
 });
 $("#editrequestor-area").text("Loading...");
 EditRequestor.timeout=null;
 $("#editrequestor-reason").keydown(function(){
 if(EditRequestor.timeout)return;
 letthat=this;
 EditRequestor.timeout=window.setTimeout(asyncfunction(){
 letpreviewResult=await(newmw.Api()).parse($(that).val(),{"title":mw.config.get('wgPageName')});
 $("#editrequestor-reason-preview").html(previewResult);
 EditRequestor.timeout=null;
 },500);
 });
 $.get(mw.config.get('wgScriptPath')+'/api.php',{
 'action':'parse',
 'format':'json',
 'prop':'wikitext',
 'page':EditRequestor.requestPage
 }).done(function(result){
 if(result.error){
 $("#editrequestor-area").text('Error: '+result.error.info);
 }else{
 $("#editrequestor-area").text(result.parse.wikitext['*']);
 $("#editrequestor-area").prop("disabled",false);
 $("#editrequestor-reason").prop("disabled",false);
 }
 });
 }
 });
 });
 }
 // </nowiki>

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