Concatenate Transcript

Concatenate Youtube Transcript

  1. // ==UserScript==
  2. // @name Concatenate Transcript
  3. // @namespace jwang0614.top/script
  4. // @version 0.1
  5. // @description Concatenate Youtube Transcript
  6. // @author Olivia
  7. // @match https://www.youtube.com/watch?v=*
  8. // @require http://code.jquery.com/jquery-1.11.1.min.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. $(document).ready(function(){
  14. UI();
  15. })
  16.  
  17. function UI() {
  18. console.log("UI");
  19. var $title_container = $("#title-container");
  20.  
  21. var $style = $('<style>'+ '#download_btn{color:green;font-size:20px;margin:10px auto;}' +'</style>');
  22. var $download_btn = $('<button id="download_btn">Download Transcript</button>');
  23.  
  24. $title_container.append($style);
  25. $title_container.append($download_btn);
  26.  
  27. $("#download_btn").click(function(){
  28. var divs = document.querySelectorAll("ytd-transcript-body-renderer div.ytd-transcript-body-renderer[role='button']");
  29. var text = "";
  30.  
  31. for(var i= 0; i < divs.length; i++){
  32. text = text + divs[i].innerText + " "
  33. }
  34.  
  35.  
  36. var filename = $("title").text() + " - Transcript.txt"
  37. // add // before line 38 if you don't want to save concatenated transcript into a file
  38. download(text, filename, "text");
  39.  
  40. // add // before lines 41-45 if you don't want to save concatenated transcript to clipboard
  41. navigator.clipboard.writeText(text).then(function() {
  42. console.log('Async: Copying to clipboard was successful!');
  43. }, function(err) {
  44. console.error('Async: Could not copy text: ', err);
  45. });
  46. })
  47.  
  48. }
  49.  
  50. // https://stackoverflow.com/a/30832210
  51. function download(data, filename, type) {
  52. var file = new Blob([data], {type: type, charset: "utf-8"});
  53. if (window.navigator.msSaveOrOpenBlob) { // IE10+
  54. window.navigator.msSaveOrOpenBlob(file, filename);
  55. }
  56. else { // Others
  57. var a = document.createElement("a"),
  58. url = URL.createObjectURL(file);
  59. a.href = url;
  60. a.download = filename;
  61. document.body.appendChild(a);
  62. a.click();
  63. setTimeout(function() {
  64. document.body.removeChild(a);
  65. window.URL.revokeObjectURL(url);
  66. }, 0);
  67. }
  68. }
  69.  

QingJ © 2025

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