Copy Transcript Text Button for Coursera

Adds a button to copy transcript text to clipboard on Coursera course video pages

  1. // ==UserScript==
  2. // @name Copy Transcript Text Button for Coursera
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Adds a button to copy transcript text to clipboard on Coursera course video pages
  6. // @author Your Name
  7. // @match https://*.coursera.org/learn/*/lecture/*
  8. // @grant none
  9. // @run-at document-end
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to copy text to clipboard
  17. function copyToClipboard(text) {
  18. text = text.slice(203);
  19. const textArea = document.createElement('textarea');
  20. textArea.value = text;
  21. document.body.appendChild(textArea);
  22. textArea.select();
  23. document.execCommand('copy');
  24. document.body.removeChild(textArea);
  25. }
  26.  
  27. // Function to add the copy button
  28. function addButton() {
  29. // Ensure the transcript lighter element exists
  30.  
  31.  
  32. // Create button element
  33. const button = document.createElement('button');
  34. button.textContent = 'Copy Transcript Text';
  35. button.style.position = 'absolute';
  36. button.style.top = '10px';
  37. button.style.right = '150px';
  38. button.style.padding = '10px';
  39. button.style.backgroundColor = '#007bff';
  40. button.style.color = '#fff';
  41. button.style.border = 'none';
  42. button.style.borderRadius = '5px';
  43. button.style.cursor = 'pointer';
  44. button.style.zIndex = '1000';
  45.  
  46. // Add button to the page
  47. document.body.appendChild(button);
  48.  
  49. var transcriptLighter
  50. // Add click event listener to the button
  51. button.addEventListener('click', () => {
  52. if (!transcriptLighter) {
  53. transcriptLighter = document.querySelector('div[id$="-panel-TRANSCRIPT"]');
  54. }
  55. const text = transcriptLighter.textContent.trim();
  56. if (text) {
  57. copyToClipboard(text);
  58. }
  59. });
  60. }
  61.  
  62. // Wait until the page is fully loaded
  63. window.addEventListener('load', () => {
  64. setTimeout(addButton,2000); // Delay to ensure the transcript is loaded
  65. });
  66.  
  67. })();

QingJ © 2025

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