displayMillisecOnTwitter

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

Verze ze dne 06. 07. 2018. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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