修正 Udemy 字幕的翻译显示问题

修复Udemy Subtitle Translate Bug,打开Google translate和Viedo transcript即可使用。

  1. // ==UserScript==
  2. // @name Fixing Udemy Subtitle Google Translation Issues
  3. // @name:zh-TW 修正 Udemy 字幕的翻譯顯示問題
  4. // @name:zh-CN 修正 Udemy 字幕的翻译显示问题
  5. // @namespace http://tampermonkey.net/
  6. // @version 1.0.3
  7. // @description Fix Udemy Subtitle Translate Bug, Open the Google translate and Viedo transcript to use.
  8. // @description:zh-tw 修復Udemy Subtitle Translate Bug,打開Google translate和Viedo transcript即可使用。
  9. // @description:zh-cn 修复Udemy Subtitle Translate Bug,打开Google translate和Viedo transcript即可使用。
  10. // @author You
  11. // @match *://www.udemy.com/course/*
  12. // @grant none
  13. // @license MIT
  14. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20.  
  21. var $ = window.jQuery;
  22. if (typeof window.i !== 'undefined') { clearInterval(window.i) } else {
  23. let lastText = ''
  24. function check() {
  25. // let toEl = $('.well--container--2edq4 span');
  26. let toEl = $('div[data-purpose="captions-cue-text"]');
  27. let fromEl = $('p[data-purpose="transcript-cue-active"] span:last')
  28. let currentText = fromEl.html()
  29. let subText = $('span[class^="well--text--"]');
  30.  
  31. let container = $('div[class^="well--container--"]')
  32. if (container !== 'undefined')
  33. {
  34. container.css('font-size','2em')
  35. }
  36.  
  37. if (lastText !== currentText) {
  38. if(subText !== 'undefined')
  39. {
  40. subText.html(currentText)
  41. subText.css('max-width','100%');
  42.  
  43. }
  44. if(toEl !== 'undefined')
  45. {
  46. toEl.html(currentText);
  47. toEl.css('max-width','100%')
  48. toEl.css('white-space','inherit')
  49. toEl.css('text-align','center')
  50. }
  51. }
  52. lastText = fromEl.html()
  53. }
  54. window.i = setInterval(check, 200);
  55. }
  56. })();