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); | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ブックマークレットの追加・実行手順
※今回は単純に相対時間を変換しているだけですが、JavaScriptが勝手に実行されてしまうのでソースが公開されていないブックマークレットは無闇矢鱈に実行しないほうが良いです。