YT Tradutor de Comentários

Traduz comentários no Youtube de inglês para português, um quebra-galho enqunto o script oficial não é corrigido. Leia os detalhes.

  1. // ==UserScript==
  2. // @name YT Tradutor de Comentários
  3. // @namespace linkme.bio/jhonpergon/?userscript=translateYT
  4. // @match *://www.youtube.com/*
  5. // @exclude *://www.youtube.com/embed/*
  6. // @version 1.0
  7. // @author Jhon Pérgon
  8.  
  9. // @name:pt YT Tradutor de Comentários
  10.  
  11. // @description Traduz comentários no Youtube de inglês para português, um quebra-galho enqunto o script oficial não é corrigido. Leia os detalhes.
  12. // @description:pt Traduz comentários no Youtube de inglês para português, um quebra-galho enqunto o script oficial não é corrigido. Leia os detalhes.
  13.  
  14. // @icon https://cdn-icons-png.flaticon.com/512/2190/2190552.png
  15. // @license MIT
  16. // @grant none
  17.  
  18. // @compatible chrome
  19. // @compatible firefox
  20. // @compatible opera
  21. // @compatible edge
  22. // @compatible safari
  23. // ==/UserScript==
  24.  
  25. (function() {
  26.  
  27. let getLangs = "en|pt"; //de inglês para português
  28.  
  29. function substituteSubstring(originalString, substringToReplace, newSubstring) {
  30. return originalString.replace(substringToReplace, newSubstring);
  31. }
  32.  
  33. let conteComments = 0;
  34.  
  35. function addTranslate(){
  36. // Adiciona o evento a todas as tags com a classe "script-description description"
  37. document.querySelectorAll('.yt-core-attributed-string.yt-core-attributed-string--white-space-pre-wrap').forEach(item => {
  38.  
  39. if (item.textContent.includes("➜")) {
  40. //return true;
  41. }else{
  42. conteComments++;
  43. item.innerHTML += " ➜ <strong style='color:#7efffb;cursor:pointer'>[traduzir]</strong>";
  44. item.addEventListener('click', function() {
  45. // Captura o texto do elemento clicado
  46. let texto = this.textContent;
  47.  
  48. let originalString = texto;
  49. let substringToReplace = "[traduzir]";
  50. let newSubstring = "<strong style='color:#a0a0ff;cursor:pointer'>[...]</strong>";
  51. let resultx = substituteSubstring(originalString, substringToReplace, "");
  52. item.innerHTML = resultx+newSubstring;
  53. texto = resultx+newSubstring;
  54.  
  55. if(getLangs !== ""){
  56. let textoEnviado = texto;
  57. let apiURL = "https://api.mymemory.translated.net/get";
  58. let params = {
  59. q: textoEnviado,
  60. langpair: getLangs
  61. };
  62.  
  63. let queryString = Object.keys(params)
  64. .map(key => key + '=' + encodeURIComponent(params[key]))
  65. .join('&');
  66.  
  67. let requestUrl = apiURL + '?' + queryString;
  68.  
  69. fetch(requestUrl)
  70. .then(response => response.json())
  71. .then(data => {
  72. if (data && data.responseData && data.responseData.translatedText) {
  73. // console.log("Tradução: ", data.responseData.translatedText);
  74. let textoTraduzido = data.responseData.translatedText
  75. let originalString = textoTraduzido;
  76. let substringToReplace = "<strong style='color:#a0a0ff;cursor:pointer'>[...]</strong>";
  77. let newSubstring = `<strong style='color:#5aff5f;cursor:pointer'>[traduzido]</strong>`;
  78. let resultx = substituteSubstring(originalString, substringToReplace, "");
  79. //console.log(result);
  80. item.innerHTML = resultx+newSubstring;
  81. } else {
  82. this.textContent = "Não foi possível traduzir o texto.";
  83. }
  84. })
  85. .catch(error => {
  86. if(error){
  87. this.textContent = error;
  88. }else{
  89. this.textContent = "[ERRO: Sem conexão com a internet].";
  90. }
  91. });
  92. }
  93.  
  94. });
  95. }
  96. });
  97.  
  98. }
  99.  
  100. setTimeout(function() {
  101. setInterval(addTranslate, 1500);
  102. }, 3500);
  103.  
  104.  
  105. })();

QingJ © 2025

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