4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GITHUBの日付の表示を相対表示から絶対表示に変換するブックマークレット

Posted at

GITHUBの日付の表示が...4days agoみたいな相対表示なのを、
絶対表示で確認するために設定などを探していた時に見つけたブックマークレット(https://qiita.com/kobake@github/items/06dcc5b6135fd38adeb7)が古くて動かなくなっていたため、新しく作りました。

javascript:var%20times%3Ddocument.querySelectorAll('relative-time')%3Bfor(var%20i%3D0%3Bi%20%3C%20times.length%3Bi%2B%2B)%7Bvar%20date%3Dnew%20Date(times%5Bi%5D.getAttribute('datetime'))%3Bvar%20dateString%3D''%3BdateString%20%2B%3Ddate.getFullYear()%2B%20'%2F'%3BdateString%20%2B%3D('0'%20%2B(date.getMonth()%2B%201)).slice(-2)%2B%20'%2F'%3BdateString%20%2B%3D('0'%20%2B%20date.getDate()).slice(-2)%2B%20'%20'%3BdateString%20%2B%3D('0'%20%2B%20date.getHours()).slice(-2)%2B%20'%3A'%3BdateString%20%2B%3D('0'%20%2B%20date.getMinutes()).slice(-2)%2B%20'%3A'%3BdateString%20%2B%3D('0'%20%2B%20date.getSeconds()).slice(-2)%3Btimes%5Bi%5D.innerText%3DdateString%3B%7Dvoid(0);

元のスクリプト

var times = document.querySelectorAll("relative-time");
for (var i = 0; i < times.length; i++) {
  var date = new Date(times[i].getAttribute("datetime"));
  var dateString = "";
  dateString += date.getFullYear() + "/";
  dateString += ("0" + (date.getMonth() + 1)).slice(-2) + "/";
  dateString += ("0" + date.getDate()).slice(-2) + " ";
  dateString += ("0" + date.getHours()).slice(-2) + ":";
  dateString += ("0" + date.getMinutes()).slice(-2) + ":";
  dateString += ("0" + date.getSeconds()).slice(-2);
  times[i].innerText = dateString;
}
4
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?