谷歌网页翻译

🍓 一个按钮的事,一点都不费事

2022-12-24 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         谷歌网页翻译
// @namespace    https://github.com/mefengl
// @version      2.0.1
// @description  🍓 一个按钮的事,一点都不费事
// @author       mefengl
// @match        http://*/*
// @match        https://*/*
// @exclude      https://edition.cnn.com/
// @exclude      https://www.baidu.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=translate.google.com
// @require      https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  "use strict";
  $(function () {
    // if origin end with '.translate.goog', then return
    if (window.location.origin.endsWith(".translate.goog")) return;

    // if title contains Chinese, then make button less visible
    const hide_right = document.title.match(/[\u4e00-\u9fa5]/)
      ? "-130px"
      : "-120px";
    // create the button
    const $button = $("<button>翻译网页</button>")
      .click(function () {
        window.location.href = `https://translate.google.com/translate?sl=auto&tl=zh-CN&u=${window.location.href}`;
      })
      .css({ position: "fixed", width: "140px", top: "120px", right: hide_right, "z-index": "999999", "background-color": "#4285f4", color: "#fff", opacity: "0.8", border: "none", "border-radius": "4px", padding: "10px 16px", "font-size": "18px", cursor: "pointer", })
      .hover(
        // hover to show, and hide when not hover
        function () { $(this).stop().animate({ right: "-10px", }, 400); },
        function () { $(this).stop().animate({ right: hide_right, }, 400); }
      )
      .appendTo("body");

    // hide button if full screen
    $(document).on("fullscreenchange", function () {
      document.fullscreenElement ? $button.hide() : $button.show();
    });
  });
})();