双搜索引擎

2021/1/4 上午10:33:27

// ==UserScript==
// @name        双搜索引擎
// @namespace   Violentmonkey Scripts
// @include     https://www.google.com*
// @match       https://www.baidu.com/s
// @match       https://www.baidu.com/
// @grant       none
// @version     1.2
// @author      -
// @description 2021/1/4 上午10:33:27
// ==/UserScript==

    if ( /www\.google\.com/.test(window.location.hostname)) {
      const box = document.querySelector("div.RNNXgb[jsname='RNNXgb']");
      const input = document.querySelector("input[aria-label='搜索']");
      const btn = document.createElement('button');
      btn.className = 'Tg7LZd'
      btn.ariaLabel = '百度搜索'
      btn.onclick = () => {
        // localtion.assign(`https://www.baidu.com/s?wd=${input.value}`)
        // window.location.href=`https://www.baidu.com/s?wd=${input.value}`
        window.open(`https://www.baidu.com/s?wd=${input.value}`)
      }
      btn.innerHTML = `
        <div class="FAuhyb">
          <span class="z1asCe MZy1Rb">
            <svg focusable="false" xmlns="http://www.w3.org/2000/svg" fill="#4e6ef2" viewBox="0 0 24 24">
              <path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
            </svg>
          </span>
        </div>
      `
      box.appendChild(btn)
    } else if (window.location.hostname === "www.baidu.com") {
      const su = document.getElementById('su')
      su.style = 'border-radius: 0'
      const input = document.createElement('input')
      const kw = document.getElementById('kw')
      input.style = `
        vertical-align:top;
        cursor: pointer;
        width: 60px;
        height: 100%;
        line-height: 40px;
        line-height: 40px\\9;
        background-color: #4e6ef2;
        border-radius: 0 10px 10px 0;
        font-size: 17px;
        box-shadow: none;
        font-weight: 400;
        border: 0;
        outline: 0;
        letter-spacing: normal;
        color: #ffffff;
      `
      input.type = 'submit'
      input.value = '谷歌'
      input.onclick = () => {
        window.location.href=`https://www.google.com/search?q=${kw.value}`
        // window.open(`https://www.google.com/search?q=${kw.value}`)
      }
      const box = su.parentNode
      box.style = `width: max-content;`
      const form = document.getElementById('form')
      form.style.width = 'max-content'
      
      box.appendChild(input)
    }