Greasy Fork

时间戳和hourId可读化

time formatter

目前为 2022-09-04 提交的版本。查看 最新版本

// ==UserScript==
// @name         时间戳和hourId可读化
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  time formatter
// @author       Yao Wu
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
     var _time_div = document.createElement('div')
    _time_div.id = "_time_div"
    _time_div.style.display = 'none'
    _time_div.style.position = 'fixed'
    _time_div.style.background = 'aquamarine';
    _time_div.style.border = 'solid';
    _time_div.style.padding = '10px'
    _time_div.style['z-index'] = 10000
    document.body.appendChild(_time_div)

    window.addEventListener('scroll', function(){_time_div.style.display = 'none'})
    window.addEventListener('resize', function(){_time_div.style.display = 'none'})
    window.addEventListener('keydown', function(){_time_div.style.display = 'none'})
    window.addEventListener('mousedown', function(){_time_div.style.display = 'none'})

    window.addEventListener('mouseup', function(){
        var str = getSelection().toString().trim()
        var rect = getSelection().getRangeAt(0).getBoundingClientRect()
        if (!str) return;
        var time = 0;
        if (str.match(/^1\d{12}$/g)){
            time = parseInt(str)
        }else if (str.match(/1^\d{9}$/g)){
            time = parseInt(str) * 1000;
        }else if (str.match(/^4\d{5}$/g)){
            time = parseInt(str) * 3600 * 1000
        }else return;
        console.log(time)
        _time_div.innerHTML = "UTC:" + new Date(time).toISOString()
        _time_div.style.top = (rect.top - 50 > 0? rect.top - 50 : 0) + 'px'
        _time_div.style.left = rect.left+'px'
        _time_div.style.display = 'block'
    })
})();