Last active
December 28, 2022 07:27
-
-
Save htsuruo/441ccda762ba4d587c68bb2215adc23d to your computer and use it in GitHub Desktop.
GitHubの相対時間をリアル時間に変換するブックマークレット
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:((function(){var b={year:"numeric",month:"long",day:"numeric"};document.querySelectorAll("relative-time").forEach(function(a){var c=(new Date(a.datetime)).toLocaleDateString("ja-JP",b);a.replaceWith(c)})})())(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function f() { | |
const nodes = document.querySelectorAll('relative-time'); | |
const options = { year: 'numeric', month: 'long', day: 'numeric' }; | |
nodes.forEach(function(node){ | |
const date = new Date(node.datetime); | |
// ref. https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString | |
const formatted = date.toLocaleDateString('ja-JP', options); | |
node.replaceWith(formatted); | |
}); | |
})() |
Google Closure Compilerでブックマークレットで実行できるように整形する
https://closure-compiler.appspot.com/home
ブックマークレットの追加・実行手順
- Google Chromeのブックマークから「ブックマークレットを追加」へ
- URL欄に github-relative-time-expand-bookmarklet の中身をコピペ
- 表示形式を切り替えたい画面を開いた状態でブックマークレットを実行
※今回は単純に相対時間を変換しているだけですが、JavaScriptが勝手に実行されてしまうのでソースが公開されていないブックマークレットは無闇矢鱈に実行しないほうが良いです。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Displaying Real Commit Times in Github が機能しなくなってしまったので、原因探るより自分で作ったほうが早いと思い実行。
基本的にGitHubの時間表記は
relative-time
タグで敢えて相対時間表示にしているが、証跡格納などの用途では相対時間では困るケースがあるので、そのためブックマークレット。GitHubのrelative-time-element
https://github.com/github/relative-time-element