Skip to content

Instantly share code, notes, and snippets.

@htsuruo
Last active December 28, 2022 07:27
Show Gist options
  • Save htsuruo/441ccda762ba4d587c68bb2215adc23d to your computer and use it in GitHub Desktop.
Save htsuruo/441ccda762ba4d587c68bb2215adc23d to your computer and use it in GitHub Desktop.
GitHubの相対時間をリアル時間に変換するブックマークレット
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)})})())();
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);
});
})()
@htsuruo
Copy link
Author

htsuruo commented Dec 28, 2022

Before After
スクリーンショット 2022-12-28 15 52 52 スクリーンショット 2022-12-28 15 52 44

@htsuruo
Copy link
Author

htsuruo commented Dec 28, 2022

ブックマークレットの追加・実行手順

  1. Google Chromeのブックマークから「ブックマークレットを追加」へ
  2. URL欄に github-relative-time-expand-bookmarklet の中身をコピペ
  3. 表示形式を切り替えたい画面を開いた状態でブックマークレットを実行

image

※今回は単純に相対時間を変換しているだけですが、JavaScriptが勝手に実行されてしまうのでソースが公開されていないブックマークレットは無闇矢鱈に実行しないほうが良いです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment