Copy Transcript Text Button for Coursera

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Copy Transcript Text Button for Coursera
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Adds a button to copy transcript text to clipboard on Coursera course video pages
// @author       Your Name
// @match        https://*.coursera.org/learn/*/lecture/*
// @grant        none
// @run-at       document-end
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to copy text to clipboard
    function copyToClipboard(text) {
       text = text.slice(203);
        const textArea = document.createElement('textarea');
        textArea.value = text;
        document.body.appendChild(textArea);
        textArea.select();
        document.execCommand('copy');
        document.body.removeChild(textArea);
    }

    // Function to add the copy button
    function addButton() {
        // Ensure the transcript lighter element exists


        // Create button element
        const button = document.createElement('button');
        button.textContent = 'Copy Transcript Text';
        button.style.position = 'absolute';
        button.style.top = '10px';
        button.style.right = '150px';
        button.style.padding = '10px';
        button.style.backgroundColor = '#007bff';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.style.zIndex = '1000';

        // Add button to the page
        document.body.appendChild(button);

        var transcriptLighter
        // Add click event listener to the button
        button.addEventListener('click', () => {
        if (!transcriptLighter) {
            transcriptLighter = document.querySelector('div[id$="-panel-TRANSCRIPT"]');
        }
            const text = transcriptLighter.textContent.trim();
            if (text) {
                copyToClipboard(text);
            } 
        });
    }

    // Wait until the page is fully loaded
    window.addEventListener('load', () => {
        setTimeout(addButton,2000); // Delay to ensure the transcript is loaded
    });

})();