Google, DeepL, Bing, Papago And Yandex Translate Swap Languages And Copy Translation Hotkeys

Enables Alt + Z to copy translated text and Ctrl + Shift + S to swap languages for Google, DeepL, Bing, Papago And Yandex Translate

  1. // ==UserScript==
  2. // @name Google, DeepL, Bing, Papago And Yandex Translate Swap Languages And Copy Translation Hotkeys
  3. // @author NWP
  4. // @description Enables Alt + Z to copy translated text and Ctrl + Shift + S to swap languages for Google, DeepL, Bing, Papago And Yandex Translate
  5. // @namespace https://gf.qytechs.cn/users/877912
  6. // @version 0.3
  7. // @license MIT
  8. // @match https://translate.google.com/*
  9. // @match https://www.deepl.com/*/translator*
  10. // @match https://www.bing.com/translator*
  11. // @match https://papago.naver.com/*
  12. // @match https://translate.yandex.com/*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. function clickElement(element) {
  20. if (element) {
  21. element.click();
  22. }
  23. }
  24.  
  25. function handleKeydown(event) {
  26. // Alt + Z for copying translated text
  27. if (event.altKey && event.key === 'z') {
  28. const googleCopyButton = document.querySelector('button[jsname="kImuFf"]');
  29. clickElement(googleCopyButton);
  30.  
  31. const deepLCopyButton = document.querySelector('button[data-testid="translator-target-toolbar-copy"]');
  32. clickElement(deepLCopyButton);
  33.  
  34. const bingCopyButton = document.querySelector('div#tta_copyIcon');
  35. clickElement(bingCopyButton);
  36.  
  37. const papagoCopyButton = document.querySelectorAll('button[id][class="btn_copy___3T223"][title][type="button"]')[1];
  38. clickElement(papagoCopyButton);
  39.  
  40. const yandexCopyButton = document.querySelector('#copyButtonDst');
  41. clickElement(yandexCopyButton);
  42. }
  43.  
  44. // Ctrl + Shift + S for swapping languages
  45. if (event.ctrlKey && event.shiftKey && event.key === 'S') {
  46. const deepLSwapButton = document.querySelector('button[data-testid="lmt_language_switch"]');
  47. clickElement(deepLSwapButton);
  48.  
  49. const bingSwapButton = document.querySelector('div#tta_revIcon');
  50. clickElement(bingSwapButton);
  51.  
  52. const papagoSwapButton = document.querySelector('button[id][class="btn_switch___x4Tcl"]');
  53. clickElement(papagoSwapButton);
  54.  
  55. const yandexSwapButton = document.querySelector('button[class="gTx50DUfJa1q57Z9sbM6 t3nFXmxYr19rwmJaBoHg yZ0odbAnIl__RMrmbWuA SNvWOiTv0bJTav0uo4Y6 nit1qvNY5o0LAHqo2TZ2 hf9lG6bClwoi5q7Cs1uQ"]');
  56. clickElement(yandexSwapButton);
  57. }
  58. }
  59.  
  60. document.addEventListener('keydown', handleKeydown, false);
  61. })();

QingJ © 2025

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