Pengguna:Hariadhi/userinfo.js
Tampilan
Catatan: Setelah menyimpan, Anda harus memintas tembolok (cache) peramban Anda untuk melihat perubahannya. Google Chrome, Firefox, Microsoft Edge dan Safari: Tahan tombol ⇧ Shift dan klik Muat ulang (Reload) di tombol bilah alat. Untuk detail dan instruksi tentang peramban lain, lihat halaman menghapus singgahan (Inggris).
/* <nowiki>
* UserInfo.js by [[User:Ricordisamoa]]
* uses jQuery & Ajax
* inspired from [[:en:User:PleaseStand/User info]] by PleaseStand (taken also some code, Thanks!)
* translate to Indonesian [[:id:User:Iwan_Novirion/userinfo.js]]
*/
$(document).ready(function(){
if((wgNamespaceNumber!=2&&wgNamespaceNumber!=3)||(/\//.test(wgTitle))) return;
var user=wgTitle.split("/")[0];
var siteData=wgServer.replace(/^\/\/(.+)$/,"$1").split(".").slice(-3,2);
$.get(
mw.util.wikiScript("api"),
{
action:"query",
format:"json",
meta:"allmessages",
amlang:wgUserLanguage,
ammessages:"ago|usereditcount|duration-seconds|duration-minutes|duration-hours|duration-days|duration-weeks|months|duration-years"
},
function(seujnyvukesrn){
var messages={};
$.each(seujnyvukesrn.query.allmessages,function(i,e){
messages[e.name]=e["*"];
if(e["*"].indexOf("{{PLURAL")!=-1){
var s=e["*"].match(/^(.*)\{\{PLURAL: ?\$1\|([^\|]*)(\|([^\|]*))?\}\}(.*)$/).slice(1);
s.splice(2,1);
if(typeof s[2]=="undefined") s[2]="";
messages[e.name]=s;
}
});
var dateDiff=function(date,precision){// state-of-the-art function for date differences!
var labels=[
messages["duration-years"],
messages["months"],
messages["duration-weeks"],
messages["duration-days"],
messages["duration-hours"],
messages["duration-minutes"],
messages["duration-seconds"]
];
var mult=[12,4.34,7,24,60,60,1000];
var diff=new Date()-date;
var message=[];
$.each(mult,function(i,e){
if(i<=precision||message.length===0){
var f=parseInt(eval(mult.slice(i).join("*")));
if(Math.floor(diff/f)>0){
var msg=(
typeof labels[i]==="string"?labels[i]:
(labels[i][0]+(Math.floor(diff/f)>1?labels[i][2]:labels[i][1])+labels[i][3])
)
.replace(/\$1/g,Math.floor(diff/f));
message.push(msg);
diff-=Math.floor(diff/f)*f;
}
}
});
return prettyJoin(message);
};
var prettyJoin=function(array){
switch(array.length){
case 0:return "";break;
case 1:return array[0];break;
case 2:return array.join(" dan ");break;
default:return array.slice(0,-1).join(", ")+", dan "+array[array.length-1];break;
}
};
var friendlyGroups={
// Exclude implicit user group information provided by MW 1.17 --PS 2010-02-17
sysop:"pengurus",
accountcreator:"account creator",
"import":"importer",
transwiki:"transwiki importer",
"ipblock-exempt":"pengecualian IP",
oversight:"pengawas",
confirmed:"confirmed user",
abusefilter:"edit filter manager",
autoreviewer:"autopatrolled user"
};
$.getJSON(
mw.util.wikiScript("api"),
{
action:"query",
format:"json",
list:"users|usercontribs",
maxage:300,
usprop:"blockinfo|editcount|gender|registration|groups",
ususers:user,
ucuser:user,
ucprop:"timestamp",
uclimit:1
},
function(data){
var query=data.query;
var user=query.users[0];
var userDesc="";
if(typeof(user.missing)!="undefined"||typeof(user.invalid)!="undefined"){
// invalid/anonymous user
if(mw.util.isIPv4Address(user.name)) userDesc="pengguna anonim IPv4";
else if(mw.util.isIPv6Address(user.name)) userDesc="pengguna anonim IPv6";
else userDesc="unspecified user";
userDesc="A"+(/^[aeio]/i.test(userDesc)?"n":"")+" "+userDesc;
}
else{
var gender=typeof(user.gender)!="undefined"?user.gender:"";
var groups=$.map(
$(user.groups).not(["*","user","autoconfirmed"]),
function(e){
return (friendlyGroups[e]&&typeof(friendlyGroups[e])!="undefined")?friendlyGroups[e]:e;
}
);
var userDesc=groups.length>0?prettyJoin(groups):"pengguna terdaftar";
if(typeof(user.blockedby)!="undefined"){
userDesc=$("<span>").append("A ")
.append(
$("<a>")
.text("blocked")
.attr("href",mw.util.getUrl("Special:Log")+"?type=block&page="+user.name)
.html()
).append(" "+userDesc);
}
else userDesc="Seorang"+(/^[aeio]/i.test(userDesc)?"":"")+" "+userDesc;
var regDate=new Date(user.registration);
if(user.registration==null) console.warn("UserInfo.js: cannot determine user's registration timestamp");
var lastContribDate=new Date(query.usercontribs[0].timestamp);
if(gender&&gender!=""){
$("<span>")
.text(gender==="male"?"\u2642":(gender==="female"?"\u2640":""))
.css({
paddingLeft:"0.25em",
fontFamily:"'Lucida Grande','Lucida Sans Unicode',sans-serif",
fontSize:"1em",
})
.appendTo("#firstHeading");
}
var userActiveKeys={
inactive:["c73535","c33003"],
uncertain:["949494","7e7e7e"],
active:["6bc431","1fbf00"]
};
var userActiveKey="inactive";
if(new Date()-lastContribDate<120000) userActiveKey="active";
else if(new Date()-lastContribDate<3600000) userActiveKey="uncertain";
var userActiveColors=userActiveKeys[userActiveKey];
var userActiveGradient="radial-gradient(center,ellipse cover,#"+userActiveColors.join(",#")+")";
$("<span>")
.attr("title","this user is probably "+userActiveKey+" at the moment")
.css({
borderRadius:"100%",
background:"lime",
height:".8em",
width:".8em",
marginRight:".3em",
display:"inline-block",
lineHeight:0,
background:"#"+userActiveColors[0]
})
.css("background","-webkit-"+userActiveGradient)
.css("background","-moz-"+userActiveGradient)
.css("background","-ms-"+userActiveGradient)
.css("background","-o-"+userActiveGradient)
.css("background",userActiveGradient)
.prependTo("#firstHeading");
userDesc=$("<span>").text(userDesc)
.append(", "+(user.registration!=null?dateDiff(regDate,2)+" yang lalu, ":"")+"dengan ")
.append(
$("<a>")
.text(
(typeof messages.usereditcount==="string"?messages.usereditcount:
messages.usereditcount[0]+
(user.editcount>1?messages.usereditcount[2]:messages.usereditcount[1])+
messages.usereditcount[3]
)
.replace(/\$1/g,user.editcount.toLocaleString())
)
.attr("href","http://toolserver.org/~tparis/count/index.php?"+
$.param({
name:user.name,
lang:siteData[0],
wiki:siteData[1]
})
)
)
.append(". Suntingan terakhir ")
.append(
$("<a>")
.text(messages.ago.replace(/\$1/g,dateDiff(lastContribDate,2)))
.attr("href",mw.util.getUrl("Special:Contributions/"+user.name))
);
}
$("#siteSub").show().prepend(". ").prepend(userDesc);
}
);
}
);
});