displayMillisecOnTwitter

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

Stan na 06-07-2018. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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()}日`
    }
})();