zoukankan      html  css  js  c++  java
  • 时间戳转日期,日期装时间戳快速tempermonkey脚本

    使用 ####

    1.安装chrome tempermonkey插件.
    2.安装此脚本.
    3.连续按t键3次, 调出时间戳转日期输入框,按回车转换,按esc退出.
    4.连续按d键3次,调出日期转时间戳选择框,按回车转化,按esc退出.

    // ==UserScript==
    // @name         time-date-convertor
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @description  press [t/d] key three time then show [timestamp/date] convertor
    // @author       arvim.lo <bigpao.luo@gmail.com>
    // @require       http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js
    // @match        http*://*/*
    // @grant        none
    // ==/UserScript==
    
    (function() {
        'use strict';
        var timeTemplateEle = $('<div  style="display: inline; position: fixed; z-index:10000; right: 10px; top: 10px;"><input type="number" id="time-ipt" /><br/><span id="time-result"></span></div>');
        var dateTemplateEle = $('<div  style=" display: inline; position: fixed; z-index: 10000; right: 10px; top: 10px;"><input type="date" id="date-ipt" /><br/><span id="date-result"></span></div>');
        var bodyEle = $("body");
        var timeResultEle = $("#time-result", timeTemplateEle);
        var timeIptEle = $("#time-ipt", timeTemplateEle);
        var cssStyle =  {
            "font-size": "12px",
            "padding": " 5px",
            "color": "#555",
            "vertial-align": "middle",
            "border": "1px solid #ccc",
            "border-radius": "3px",
        };
        timeIptEle.css(cssStyle);
    
        var dateResultEle = $("#date-result", dateTemplateEle);
        var dateIptEle = $("#date-ipt", dateTemplateEle);
        dateIptEle.css(cssStyle);
        var keyCounter = new Map();
    
        /**
         * 响应t事件, 当t连续三次后, 调出输入框, 输入时间戳, 回车时间计算, esc键干掉
         */
        bodyEle.on("keyup", "#time-ipt", function (evt) {
            var timeIptEle = $(this);
            if (evt.keyCode == 13) {
                var value = timeIptEle.val();
                if ($.trim(value) === "") {
                    alert(" Please Input Value ! ");
                } else {
                    var dateObj = new Date(value * 1000);
                    timeResultEle.html(dateObj.getFullYear() + '/' + (dateObj.getMonth() + 1) + '/' + dateObj.getDate() + ' ' + dateObj.getHours() + ':' + dateObj.getMinutes() + ':' + dateObj.getSeconds());
                }
            } else if (evt.keyCode == 27) {
                timeTemplateEle.remove();
            }
        });
    
        /**
         * 响应d事件, 当日期选择好后, 回车转换成时间JavaScript时间戳,esc键干掉
         */
        bodyEle.on("keyup", "#date-ipt", function (evt) {
            var dateIptEle = $(this);
            if (evt.keyCode == 13) {
                var value = dateIptEle.val();
                if ($.trim(value) === "") {
                    alert(" Please Input Date ! ");
                } else {
                    var dateObj = new Date(value);
                    dateResultEle.html(dateObj.getTime());
                    return;
                }
            } else if (evt.keyCode == 27) {
                dateTemplateEle.remove();
            }
        });
    
        /**
         * 响应 t,d事件, 当t,d连续三次, 调出时间,日期转input框
         */
        bodyEle.on("keyup", function (evt) {
            var keyCode = evt.keyCode,
            keyFlag = 'key-' + keyCode,
            keyCount = keyCounter.get(keyFlag) || 0;
    
            if (keyCode == 84) {
                keyCounter.set(keyFlag, ++keyCount);
                if (keyCount == 3) {
                    bodyEle.prepend(timeTemplateEle);
                    timeIptEle.focus();
                    keyCounter.clear();
                }
            } else if (keyCode == 68) {
                keyCounter.set(keyFlag, ++keyCount);
                if (keyCount === 3) {
                    bodyEle.prepend(dateTemplateEle);
                    dateIptEle.focus();
                    keyCounter.clear();
                }
            } else {
                keyCounter.clear();
            }
        });
    })();
    
  • 相关阅读:
    自定义实现wcf的用户名密码验证
    EF6:编写你自己的code first 数据迁移操作(睡前来一篇,翻译的)
    .net 连接Redis
    idea external libraries 只有jdk问题
    MAC vim安装gruvbox主题
    Mac gitk安装与优化
    spring security 4 filter 顺序及作用
    mysql 采样查询 / 间隔查询 / 跳跃查询的两种实现思路
    nginx warn an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/ while reading upstream
    nginx日志 logrotate配置
  • 原文地址:https://www.cnblogs.com/luowen/p/5389399.html
Copyright © 2011-2022 走看看