displayMillisecOnTwitter

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

2018/07/06のページです。最新版はこちら

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

作者のサイトでサポートを受ける。または、このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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()}日`
    }
})();