NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name UnixTime // @version 1.0.0 // @description Convert unix time // @copyright 2018, iSkile (https://openuserjs.org/users/iSkile) // @author iSkile // @license MIT // @run-at document-idle // @include *://*/* // ==/UserScript== /* jshint -W097 */ 'use strict'; function textNodesUnder(el) { let arr = []; let walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, { acceptNode: function (node) { let name, tNode = node; while ((tNode = tNode.parentNode) && (name = tNode.nodeName.toLowerCase()) != 'body') { if (~['style', 'script', 'texarea', 'pre', 'code'].indexOf(name)) { return NodeFilter.FILTER_REJECT; } } if (node.data.trim() !== '') { return NodeFilter.FILTER_ACCEPT; } } }, false); while ((el = walk.nextNode())) { arr.push(el); } return arr; } function replace(root) { if (!root) return; let textNodes = textNodesUnder(root); for (let node of textNodes) { let txt = node.data; if(/^\d{8,12}$/.test(txt)) { let date = new Date(+txt * 1000); let pNode = node.parentNode; let timeStr = date.toLocaleString(); if (pNode.title != timeStr) { pNode.title = (pNode.title.trim().length ? pNode.title + "\nUnix time: " : '') + timeStr; } } } } let observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { mutation.addedNodes.forEach(function (addedNode) { if (addedNode.nodeType === 1) { replace(addedNode); } }); }); }); observer.observe(document.documentElement, { childList: true, subtree: true }); replace(document.body);