快速聚焦在百度搜索页面可以使用Ctrl+Q 快速聚焦搜索框,在其他页面可在右下角显示当前日期和时间

在百度搜索页面可以使用Ctrl+Q 快速聚焦搜索框,在其他页面可在右下角显示当前日期和时间。

// ==UserScript==
// @name         快速聚焦在百度搜索页面可以使用Ctrl+Q 快速聚焦搜索框,在其他页面可在右下角显示当前日期和时间
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  在百度搜索页面可以使用Ctrl+Q 快速聚焦搜索框,在其他页面可在右下角显示当前日期和时间。
// @author       wulei
// @include *
// @match        https://www.baidu.com/**
// @icon         https://www.google.com/s2/favicons?sz=64&domain=baidu.com
// @grant        none
// @license MIT
// 
// ==/UserScript==
(function() {
    'use strict';
    'esversion:6';
    if(window.parent!==window)return;
    var fg = document.createDocumentFragment();
    var div = document.createElement("div");
    div.onselectstart = () => false
    setInterval(() => {
        var date = new Date(),
            year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate(),
            week = date.getDay(),
            hour = date.getHours(),
            minute = date.getMinutes(),
            second = date.getSeconds();
        div.innerText = `${year}年${month}月${day}日 ${hour}时${minute}分${second}秒 周${week}`
    }, 1000);
    div.setAttribute("class", "qf-date");
    fg.appendChild(div);
    document.body.appendChild(fg);
    //聚焦搜索框
    var arr = [];
    document.onkeydown = function (event) {
        arr.push(event.key)
        if (arr.toString().toUpperCase() === 'CONTROL,Q') {
            var is = false;
            Array.from(document.querySelectorAll("input"))
                .forEach((item) => {
                if (item.type === "text" && !is) {
                    item.focus();
                    is = true
                }
            })

        }
    }
    document.onkeyup = function () {
        arr.length = 0;
    }
    // Your code here...
})();
(function (){
    var style=document.createElement("style")
    style.innerHTML=`.qf-date {
    position: fixed;
    bottom: 3px;
    right: 3px;
    color: rgba(37, 134, 151, 0.281);
    color: red;
    font-size: 11px;
    font-weight: bold;
    /* zoom: 0.5; */
    z-index: 999;
}
`;
    document.head.appendChild(style)
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址