Google Translate Keyboard Shortcut

Press ctrl-s to swap active languages

目前为 2016-08-02 提交的版本。查看 最新版本

/**
 * The MIT License (MIT)
 * 
 * Copyright (c) 2016 Paweł Golonko
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
// ==UserScript==
// @name         Google Translate Keyboard Shortcut
// @description  Press ctrl-s to swap active languages
// @version      1.0
// @author       greenek
// @copyright    2016, Paweł Golonko (http://greenek.com)
// @license      MIT; https://opensource.org/licenses/MIT
// @match        http*://translate.google.com/
// @namespace https://gf.qytechs.cn/users/58270
// ==/UserScript==

(function() {
  'use strict';

  // Init mouse events
  var mouseEvents = ['mouseover', 'mousedown', 'mouseup', 'mouseout'].map(function(n) {
    var e = document.createEvent('MouseEvents');
    e.initEvent(n, true, false);

    return e;
  });

  // Get swap button element
  var swapBtn = document.getElementById('gt-swap');

  /**
   * Emulate click event to call swap function.
   */
  var emulateClick = function(el) {
    var dispatch = el.dispatchEvent.bind(el);
    mouseEvents.forEach(dispatch);
  };

  /**
   * Set listeners for shortcut event.
   */
  document.onkeydown = function(e) {
    if (e.which === 83 && e.ctrlKey) {
      e.preventDefault();
      emulateClick(swapBtn);
    }
  };
})();

QingJ © 2025

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