displayMillisecOnTwitter

Twitter上の日時表示の場所をSnowFrakeを元にミリ秒単位の表示に修正します

נכון ליום 06-07-2018. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        displayMillisecOnTwitter
// @namespace   https://twitter.com/kymn_
// @version     0.1.0
// @description Twitter上の日時表示の場所をSnowFrakeを元にミリ秒単位の表示に修正します
// @author      keymoon
// @license     MIT
// @supportURL  https://twitter.com/kymn_
// @match       https://twitter.com/*
// ==/UserScript==

(function(){
    //タイムライン更新の監視
    (() => {
        const target = document.getElementById('stream-items-id');
        const observer = new MutationObserver(records => {OverrideToolTip()})
        const options = {childList: true};
        var flag = false;
        observer.observe(target, options);
        //各ツイートのツールチップの書き換え
        function OverrideToolTip(){
            if(flag) return;
            $('.tweet-timestamp').each(function(index, element){
                var id =element.getAttribute('data-conversation-id');
                $(`a[data-conversation-id=${id}]`).attr('title',formatDate(getDateFromSnowFrake(id)));
            })
            flag = false;
        }
    })();

    //ツイート詳細ウィンドウの開閉の監視
    (() => {
        const target = document.getElementsByClassName('PermalinkOverlay-modal')[0];
        const observer = new MutationObserver(records => {OverrideMetaData()})
        const options = {attributes: true,subtree:true};
        observer.observe(target, options);
        //ツイートのメタデータ部の書き換え
        function OverrideMetaData(){
            var tweetContainer = target.getElementsByClassName('permalink-tweet')[0];
            if(tweetContainer) target.getElementsByClassName('metadata')[0].textContent = formatDate(getDateFromSnowFrake(tweetContainer.getAttribute("data-tweet-id")));
        }
    })();

    //アカウント画面のアカウント登録日時
    (() => {
        var joinDate = document.getElementsByClassName("ProfileHeaderCard-joinDateText")[0];
        if(joinDate) joinDate.setAttribute("title",formatDate(getDateFromSnowFrake(document.getElementsByClassName("Avatar")[0].getAttribute("data-user-id"))))
    })();


    function getDateFromSnowFrake(ID){
        var unixTime = Math.floor(parseInt(ID) / 4194304) + 1288834974657;
        return new Date(unixTime);
    }
    function formatDate(date){
        return `${date.getHours()}:${date.getMinutes().toString().padStart(2,'0')}:${date.getSeconds().toString().padStart(2,'0')}.${date.getMilliseconds().toString().padStart(3,'0')} - ${1900 + date.getYear()}年${date.getMonth()}月${date.getDate()}日`
    }
})();