User:JJPMaster/AfC time logger.js
Appearance
(Redirected fromUser:JJPMaster/afc.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 guideto 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 theappropriate village pump. This codewillbe executed when previewing this page. |
Thisuser scriptseems to have a documentation page atUser:JJPMaster/AfC time logger. |
(()=>{
letns=mw.config.get("wgCanonicalNamespace");
letname=mw.config.get("wgPageName").replace(/_/g,' ');
vardate=newDate();
varstartTime=date.getTime();
varspent=0;
varnewDate;
functionformatDate(d){
letday=d.getDate();
letmonth=d.getMonth();
letyear=d.getFullYear();
constmonths=[
"January","February","March","April","May","June",
"July","August","September","October","November","December"
];
returnday+' '+months[month]+' '+year;
}
functiongetTime(){
newDate=newDate();
vartime=newDate.getTime();
spent=(time-startTime)/1000;
returnspent;
}
functionpostToLog(title,time,action,d){
varparams={
action:"query",
titles:"User:"+mw.config.get("wgUserName")+"/AfC time log",
format:"json"
},
api=newmw.Api();
api.get(params).done((data)=>{
if(data.query.pages["-1"]!=null){
params={
action:"edit",
title:"User:"+mw.config.get("wgUserName")+"/AfC time log",
text:"This page measures the amount of time it takes for me to review articles at AfC. This information is obtained using a [[User:JJPMaster/afc.js|user script]].\r\n* [["+title+"]] -"+action+"after"+time+"seconds ("+d+")",
summary:"Added [["+title+"]] to AfC time log using [[User:JJPMaster/afc.js]]",
format:"json"
},
api.postWithToken("csrf",params).done((data)=>{
console.log(data);
});
}
else{
params={
action:"edit",
title:"User:"+mw.config.get("wgUserName")+"/AfC time log",
appendtext:"\r\n* [["+title+"]] -"+action+"after"+time+"seconds ("+d+")",
summary:"Added [["+title+"]] to AfC time log using [[User:JJPMaster/afc.js]]",
format:"json"
},
api.postWithToken("csrf",params).done((data)=>{
console.log(data);
});
}
mw.notify($("<a target=\" _blank\ "style=\" color: black; text-decoration: none;\ "href=\" "+mw.config.get("wgServer")+mw.config.get("wgArticlePath").replace('$1',"User:"+mw.config.get("wgUserName"))+"/AfC time log\" >Article successfully added to User: "+mw.config.get("wgUserName")+"/AfC time log.<br />Click here to redirect there.</a>"));
});
}
$(document).ready(()=>{
if(ns=="Draft"){
console.log("Draft detected, start time is"+startTime);
$("#bodyContent").on("click","#afchSubmitForm",()=>{
console.log("Spent"+getTime()+"before reviewing"+name);
if($("#afchSubmitForm").hasClass("accept")){
postToLog(name,getTime(),"Accepted",formatDate(newDate));
}
elseif($("#afchSubmitForm").hasClass("decline")){
if($("#rejectInputWrapper").hasClass("hidden"))postToLog(name,getTime(),"Declined",formatDate(newDate));
elsepostToLog(name,getTime(),"Rejected",formatDate(newDate));
}
});
}
elseconsole.log("Not a draft");
});
})();