Github Comment显示24小时时间(仅适用国内用户-北京时间)

github的comment默认显示英语日期,此脚本自动替换push时间为此次push的第一笔commit的时间,并且使用北京时间24小时计时法显示. 能力有限,需要F5刷新一次才能完成替换,原因不明。

当前为 2021-02-28 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Github Comment显示24小时时间(仅适用国内用户-北京时间)
// @name:en      Github Comment English Time to GTM8 (Beijing)
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  github的comment默认显示英语日期,此脚本自动替换push时间为此次push的第一笔commit的时间,并且使用北京时间24小时计时法显示. 能力有限,需要F5刷新一次才能完成替换,原因不明。
// @description:en github comment default shows English date without time, this script replace it as GTM8(Beijing time) 24h time
// @homepage     https://greasyfork.org/zh-CN/scripts/422423
// @icon         https://github.com/fluidicon.png
// @author       tumuyan
// @match        https://github.com/*/commits/*
// @run-at         document-end
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    document.querySelectorAll(`.TimelineItem-body`).forEach((item) => {
        var t = item.querySelector(`relative-time`).title.toString();
        t = t.replace("年","-").replace("月","-").replace("日","").replace("GMT+8","");

        if(t.indexOf("下午")>0){
            t=t.replace("下午0","下午")
                .replace(" 下午0:","12:")
                .replace(" 下午1:","13:")
                .replace(" 下午2:","14:")
                .replace(" 下午3:","15:")
                .replace(" 下午4:","16:")
                .replace(" 下午5:","17:")
                .replace(" 下午6:","18:")
                .replace(" 下午7:","19:")
                .replace(" 下午8:","20:")
                .replace(" 下午9:","21:")
                .replace(" 下午10:","22:")
                .replace(" 下午11:","23:")
                .replace(" 下午12:","12:");
        }else{
            t=t.replace("上午0","上午")
                .replace(" 上午0:","00:")
                .replace(" 上午1:","01:")
                .replace(" 上午2:","02:")
                .replace(" 上午3:","03:")
                .replace(" 上午4:","04:")
                .replace(" 上午5:","05:")
                .replace(" 上午6:","06:")
                .replace(" 上午7:","07:")
                .replace(" 上午8:","08:")
                .replace(" 上午9:","09:")
                .replace(" 上午10:","10:")
                .replace(" 上午11:","11:")
                .replace(" 上午12:","00:");
        }

        // var t= "2020年11月9日 GMT+8 下午11:00".replace("年","-").replace("月","-").replace("日","").replace("GMT+8","");
        item.querySelector(`h2`).innerText=t;
        //        console.log(item.text);
    });

    document.querySelectorAll(`.TimelineItem-body relative-time`).forEach((item) => {
        var t = item.title.toString();
        t = t.replace("年","-").replace("月","-").replace("日","").replace("GMT+8","");
        item.innerText="于 "+t;
    });


    /*
////@require http://code.jquery.com/jquery-1.11.0.min.js
    setTimeout(function(){
        //要执行的事件
        $(".TimelineItem-body").ready(function(){
            var t = $(this).find("relative-time").attr("title");
            t = t.replace("年","-").replace("月","-").replace("日","").replace("GMT+8","").replace(" 上午","");

            if(t.indexOf("下午")>0){
                t=t.replace("下午0","下午")
                    .replace(" 下午0:","12:")
                    .replace(" 下午1:","13:")
                    .replace(" 下午2:","14:")
                    .replace(" 下午3:","15:")
                    .replace(" 下午4:","16:")
                    .replace(" 下午5:","17:")
                    .replace(" 下午6:","18:")
                    .replace(" 下午7:","19:")
                    .replace(" 下午8:","20:")
                    .replace(" 下午9:","21:")
                    .replace(" 下午10:","22:")
                    .replace(" 下午11:","23:")
                    .replace(" 下午12:","24:");
            }
            $(this).find("h2").text(t);
        });
    },3000);
 */
})();