Google Translate: Filter & Flags

Filters languages and shows country flags on Google Translate

安装此脚本?
作者推荐脚本

您可能也喜欢YouTube Auto-Liker

安装此脚本
  1. // ==UserScript==
  2. // @name Google Translate: Filter & Flags
  3. // @namespace https://github.com/HatScripts/google-translate-filter-and-flags
  4. // @version 1.0.2
  5. // @license MIT
  6. // @description Filters languages and shows country flags on Google Translate
  7. // @author HatScripts
  8. // @icon https://ssl.gstatic.com/translate/favicon.ico
  9. // @match http://translate.google.com/*
  10. // @match https://translate.google.com/*
  11. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  12. // @grant GM_addStyle
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant GM_registerMenuCommand
  16. // @run-at document-idle
  17. // ==/UserScript==
  18.  
  19. /* global GM_config, GM_info, GM_registerMenuCommand */
  20.  
  21. ;(() => {
  22. 'use strict'
  23.  
  24. GM_config.init({
  25. id: 'gtff_config',
  26. title: GM_info.script.name + ' Settings',
  27. fields: {
  28. SHOW_FLAGS: {
  29. label: 'Show flags',
  30. type: 'checkbox',
  31. default: true,
  32. title: 'Show country flags next to languages'
  33. },
  34. FILTER_LANGUAGES: {
  35. label: 'Filter languages',
  36. type: 'checkbox',
  37. default: true,
  38. title: 'Show only the specified languages'
  39. },
  40. LANGUAGES_SHOWN: {
  41. label: 'Languages shown',
  42. type: 'textarea',
  43. default: 'ar,de,el,en,eo,es,fi,fr,it,ja,ko,la,no,pt,ru,sv,zh-CN',
  44. title: 'The languages to show, as ISO 639-1 language codes, separated by commas'
  45. }
  46. }
  47. })
  48.  
  49. GM_registerMenuCommand('Settings', () => {
  50. GM_config.open()
  51. })
  52.  
  53. console.log(GM_info.script.name)
  54.  
  55. const LANG_MAP = {
  56. 'iw': 'he', // Hebrew
  57. 'jw': 'jv', // Javanese
  58. 'mni-Mtei': 'mni', // Meiteilon (Manipuri)
  59. 'zh-CN': 'zh', // Chinese (Simplified)
  60. 'zh-TW': 'zh', // Chinese (Traditional)
  61. }
  62.  
  63. const prefix = '.qSb8Pe'
  64. if (!document.querySelector(prefix)) {
  65. console.error('Couldn\'t find language buttons')
  66. }
  67.  
  68. let css = '/* ' + GM_info.script.name + ' */'
  69.  
  70. if (GM_config.get('FILTER_LANGUAGES')) {
  71. css += prefix + '{ display: none; }'
  72. console.log(GM_config.get('LANGUAGES_SHOWN').split(','))
  73. css += GM_config.get('LANGUAGES_SHOWN').split(',').map(lang => `${prefix}[data-language-code=${lang}]`).join(',')
  74. css += '{ display: inline-flex; }'
  75. css += '.C96yib > .vSUSRc > ' + prefix + ' { display: inline-flex; }'
  76. }
  77.  
  78. if (GM_config.get('SHOW_FLAGS')) {
  79. //css += `${prefix}.RCaXn:not(.KKjvXb) .W5jNxd, ${prefix} .g3XDjb { display: none !important; }`
  80. css += `${prefix} > .l7O9Dc { background-repeat: no-repeat; background-size: contain; background-position-x: 6px; }`
  81. css += `${prefix} > .l7O9Dc > i { display: none !important; }`
  82. document.querySelectorAll(prefix).forEach(wrapper => {
  83. let code1 = wrapper.dataset.languageCode
  84. let code2 = LANG_MAP[code1] || code1
  85. css += `${prefix}[data-language-code=${code1}] > .l7O9Dc {`
  86. css += `background-image: url(https://hatscripts.github.io/circle-flags/flags/language/${code2}.svg) !important;`
  87. css += '}'
  88. })
  89. }
  90.  
  91. GM_addStyle(css)
  92. })()