必应Bing主页美化/集成百度搜索按钮 by 电工李达康

必应Bing主页美化/集成百度搜索按钮,欢迎反馈意见→知乎@电工李达康

目前为 2020-04-16 提交的版本。查看 最新版本

// ==UserScript==
// @author      知乎@电工李达康
// @icon        https://cn.bing.com/sa/simg/bing_p_rr_teal_min.ico
// @name        必应Bing主页美化/集成百度搜索按钮 by 电工李达康
// @namespace   必应Bing主页美化/集成百度搜索按钮
// @description 必应Bing主页美化/集成百度搜索按钮,欢迎反馈意见→知乎@电工李达康
// @include     *://cn.bing.com/
// @include     *://www.bing.com/
// @include     *://www.bing.com/?*
// @include     *://cn.bing.com/?*
// @run-at      document-start
// @version     1.2.1
// @grant       none
// @supportURL  https://www.zhihu.com/people/qizhenkang
// ==/UserScript==
// 


(function() {
  'use strict';

  function Element_killer(){
    var footer = document.querySelector('#b_footer');   // 移除下方信息栏
    var top = document.querySelector('#hp_sw_hdr');     // 移除顶部信息栏
    var QR = document.querySelector('#showBingAppQR');  // 移除下方二维码
    var Binglogo = document.querySelector('#sbox');     // 移除搜索处Bing标志
    
    if(footer){
      footer.remove();
    }
    if(top){
    top.remove();
    }
    if(QR){
      QR.nextElementSibling.remove();
      QR.remove();
    }
    if(Binglogo){
      Binglogo.firstElementChild.remove();
      Binglogo.firstElementChild.remove();
    }
  }
  window.setTimeout(Element_killer,200);//移除下方信息栏
  
  function BaiduSearch(){ // 提交百度搜索函数
    var keywords = document.getElementById("sb_form_q").value.trim();
    var url = "https://www.baidu.com/s?ie=UTF-8&wd=" + encodeURIComponent(keywords);
    window.open(url, "_self");
  }
  
  function BaiduSearch_KeyUp(){//百度搜索快捷键
    if(window.event.keyCode == 13 && window.event.ctrlKey){ // ctrl + Enter 快捷键 百度搜索
      BaiduSearch();
    }
  }
  
  
  // **********************************************************************************************
  // 
  // 初始化函数
  //
  // **********************************************************************************************
  function Function_init(){
    
    // ***********************************************
    // 时间获取初始化
    // ***********************************************
    //创建Date对象
    var today = new Date();
    //分别取出年、月、日、时、分、秒
    var year = today.getFullYear();
    var month = today.getMonth()+1;
    var day = today.getDate();
    var hours = today.getHours();
    var minutes = today.getMinutes();
    var seconds = today.getSeconds();
    //如果是单个数,则前面补0
    month  = month<10  ? "0"+month : month;
    day  = day <10  ? "0"+day : day;
    hours  = hours<10  ? "0"+hours : hours;
    minutes = minutes<10 ? "0"+minutes : minutes;
    seconds = seconds<10 ? "0"+seconds : seconds;

    //构建要输出的字符串
    // var str = year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds;
    var str = "TIME "+hours+":"+minutes+":"+seconds;

    //获取id=result的对象
    var obj = document.getElementById("hp_container");
    var TimeDiv = document.createElement("div");
    TimeDiv.innerHTML = str;//内容信息
    TimeDiv.id = "TimeDiv";// 标签id
    TimeDiv.style.fontWeight = '400'; // 字体粗细
    TimeDiv.style.position = "fixed"; // 位置信息
    TimeDiv.style.zIndex = '100'; // 窗口置顶
    TimeDiv.style.top = "20%"; // 位置信息
    TimeDiv.style.left = "38.5%"; // 位置信息
    TimeDiv.style.fontSize = "5em";// 字体大小
    // TimeDiv.style.fontFamily = 'Times New Roman';
    TimeDiv.style.color = "#F1F1F1E0";//字体白色
    TimeDiv.style.textAlign = "center";//居中
    TimeDiv.style.userSelect = "none";//鼠标无法选中
    TimeDiv.style.backgroundColor = '#000000B0'; //背景黑色
    
    // 鼠标悬停效果
    function TimeDivMouseEnter(){    //鼠标进入
      TimeDiv.style.color = "#00002BE0";//字体黑色
      TimeDiv.style.backgroundColor = '#FFFFFF60'; //背景白色
      TimeDiv.style.fontWeight = '400'; // 字体粗细

    }
    // 鼠标悬停效果
    function TimeDivMouseLeave(){    //鼠标离开
      TimeDiv.style.color = "#F1F1F1E0";//字体白色
      TimeDiv.style.backgroundColor = '#000000B0'; //背景黑色
      TimeDiv.style.fontWeight = '400'; // 字体粗细
    }
    function TimeDivDblClick(){
      var temp = TimeDiv.onmouseenter;
      TimeDiv.onmouseenter = TimeDiv.onmouseleave;
      TimeDiv.onmouseleave = temp;
    }
    
    TimeDiv.onmouseenter = TimeDivMouseEnter;
    TimeDiv.onmouseleave = TimeDivMouseLeave;
    TimeDiv.ondblclick = TimeDivDblClick;

    // TimeDiv.style.backgroundImage = '-webkit-gradient(linear, left top, right top,color-stop(0, #f22), color-stop(0.9, #ff2))';
    // TimeDiv.style.webkitBackgroundClip = 'text';
    // TimeDiv.style.webkitTextFillColor = 'transparent';
    TimeDiv.style.padding = '0.2em'; //边框设置
    TimeDiv.style.borderRadius = '0.35em';//背景圆角

    
    obj.insertBefore(TimeDiv,obj.firstChild);
    
    // **********************************************************************************************
    //
    //  百度搜索功能
    //
    // **********************************************************************************************
    document.querySelector('#sb_go_par').onclick = BaiduSearch; // 设置百度搜索(借用定时器)
    var BaiduButton = document.createElement('button');
    BaiduButton.innerHTML = '百度一下'; // 按钮文字
    BaiduButton.onclick = BaiduSearch; //绑定点击事件

    // 添加百度搜索按钮元素
    var BaiduSearchTag = document.querySelector('#sbox').appendChild(BaiduButton);
    // var BaiduSearchTag = document.querySelector('#BaiduSearchTag');
    BaiduSearchTag.style.position = "fixed"; // 位置信息
    BaiduSearchTag.style.zIndex = '100'; // 窗口置顶
    BaiduSearchTag.id = "BaiduSearchTag";// 标签id
    BaiduSearchTag.style.fontWeight = '400'; // 字体粗细
    // BaiduSearchTag.style.position = "fixed"; // 位置信息
    // BaiduSearchTag.style.top = "40.2%"; // 位置信息
    // BaiduSearchTag.style.left = "75.75%"; // 位置信息
    BaiduSearchTag.style.height = "2.70em"; // 按钮框高度
    BaiduSearchTag.style.width = "6.0em"; // 按钮框宽度
    BaiduSearchTag.style.fontSize = "1.50em";// 字体大小
    // BaiduSearchTag.style.fontFamily = 'Times New Roman';
    BaiduSearchTag.style.color = "#000000";//字体颜色
    BaiduSearchTag.style.textAlign = "center";//居中
    BaiduSearchTag.style.backgroundColor = '#FFFFFFB0'; //背景颜色
    BaiduSearchTag.style.border = 'none';
    BaiduSearchTag.style.userSelect = "none";//鼠标无法选中
    
    
    // 鼠标点击效果
    function BaiduSearchTagMouseDown(){    //鼠标进入
      BaiduSearchTag.style.color = "#FFFFFF";//字体白色
      BaiduSearchTag.style.backgroundColor = '#000000B0'; //背景黑色
    }
    // 鼠标点击效果
    function BaiduSearchTagMouseUp(){    //鼠标离开
      BaiduSearchTag.style.color = "#000000";//字体黑色
      BaiduSearchTag.style.backgroundColor = '#FFFFFFB0'; //背景白色
    }
    // 鼠标离开效果
    function BaiduSearchTagMouseLeave(){    //鼠标离开
      BaiduSearchTag.style.color = "#000000";//字体黑色
      BaiduSearchTag.style.backgroundColor = '#FFFFFFB0'; //背景白色
    }
    
    BaiduSearchTag.onmousedown = BaiduSearchTagMouseDown;
    BaiduSearchTag.onmouseup = BaiduSearchTagMouseUp;
    BaiduSearchTag.onmouseleave = BaiduSearchTagMouseLeave;
    

//     BaiduSearchTag.mouseenter(BaiduSearchTagHover);
    
    //快捷键设置
    var searchbox= document.querySelector('#sb_form_q');
    if(searchbox){
      searchbox.onkeydown = BaiduSearch_KeyUp;//百度搜索快捷键设置
    }
    
    
    var sbox = document.querySelector('#sbox'); //设置搜索框属性
    if(sbox){
      sbox.style.top = "40%"; // 设置位置
      sbox.style.left = "31%";
      sbox.style.height = "2.45em"; // 按钮框高度
    }
  }
  
  function showTime() //定时器函数,用以更新时间
  {
    //创建Date对象
    var today = new Date();
    //分别取出年、月、日、时、分、秒
    var year = today.getFullYear();
    var month = today.getMonth()+1;
    var day = today.getDate();
    var hours = today.getHours();
    var minutes = today.getMinutes();
    var seconds = today.getSeconds();
    //如果是单个数,则前面补0
    month  = month<10  ? "0"+month : month;
    day  = day <10  ? "0"+day : day;
    hours  = hours<10  ? "0"+hours : hours;
    minutes = minutes<10 ? "0"+minutes : minutes;
    seconds = seconds<10 ? "0"+seconds : seconds;

    //构建要输出的字符串
    // var str = year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds;
    var str = "TIME "+hours+":"+minutes+":"+seconds;
    var TimeDiv = document.getElementById("TimeDiv");
    TimeDiv.innerHTML = str;
  }
  window.setTimeout(Function_init,200); // 初始化函数
  window.setInterval(showTime,1000); // 定时更新时间
})();

(async function () {
  // const $ = window.jQuery

  // const mouseObserver = new MouseObserver();

  // monkeyMenu.on('设置', function () {
  //   window.alert('功能开发中,敬请期待...')
  // })
  // monkeyMenu.on('关于', function () {
  //   window.GM_openInTab('https://www.zhihu.com/people/qizhenkang', {
  //     active: true,
  //     insert: true,
  //     setParent: true
  //   });
  // });
})();

QingJ © 2025

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