Javascriptの勉強の成果

javascript:
q=location.href;
p=/http:\/\/d\.hatena\.ne\.jp\/\w+/;
p2=/http:\/\/(\w+\.)?g\.hatena\.ne\.jp\/\w+/;

if(p.test(q)==true){
   location.href='http://g.hatena.ne.jp/'+q.split("/")[3]+'/';
}
else if(p2.test(q)==true){
   location.href='http://d.hatena.ne.jp/'+q.split("/")[3]+'/';
}
else{
   alert('error');
}

グループ,ダイアリーの相互移動ブックマークレット。どちらのページでもないときはアラート。勉強の一環なんで使える使えないは勘弁。