// ==UserScript== // @name 时间戳和hourId可读化 // @namespace http://tampermonkey.net/ // @version 0.1 // @description time formatter // @author Yao Wu // @match *://*/* // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com // @grant none // @license MIT // @downloadURL none // ==/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(/^16\d{11}$/g)){ time = parseInt(str) }else if (str.match(/16^\d{8}$/g)){ time = parseInt(str) * 1000; }else if (str.match(/^4\d{5}$/g)){ time = parseInt(str) * 3600 * 1000 }else return; _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' }) })();