Concatenate Transcript

Concatenate Youtube Transcript

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Concatenate Transcript
// @namespace    jwang0614.top/script
// @version      0.1
// @description  Concatenate Youtube Transcript
// @author       Olivia
// @match        https://www.youtube.com/watch?v=*
// @require      http://code.jquery.com/jquery-1.11.1.min.js
// @grant        none
// ==/UserScript==


$(document).ready(function(){
    UI();
})

function UI() {
    console.log("UI");
    var $title_container = $("#title-container");

    var $style = $('<style>'+ '#download_btn{color:green;font-size:20px;margin:10px auto;}' +'</style>');
    var $download_btn = $('<button id="download_btn">Download Transcript</button>');

    $title_container.append($style);
    $title_container.append($download_btn);

    $("#download_btn").click(function(){
        var divs = document.querySelectorAll("ytd-transcript-body-renderer div.ytd-transcript-body-renderer[role='button']");
        var text = "";

        for(var i= 0; i < divs.length; i++){
            text = text + divs[i].innerText + " "
        }


        var filename = $("title").text() + " - Transcript.txt"
        // add // before line 38 if you don't want to save concatenated transcript into a file
        download(text, filename, "text");

        // add // before lines 41-45 if you don't want to save concatenated transcript to clipboard
        navigator.clipboard.writeText(text).then(function() {
            console.log('Async: Copying to clipboard was successful!');
        }, function(err) {
            console.error('Async: Could not copy text: ', err);
        });
    })

}

// https://stackoverflow.com/a/30832210
function download(data, filename, type) {
    var file = new Blob([data], {type: type, charset: "utf-8"});
    if (window.navigator.msSaveOrOpenBlob) { // IE10+
        window.navigator.msSaveOrOpenBlob(file, filename);
    }
    else { // Others
        var a = document.createElement("a"),
                url = URL.createObjectURL(file);
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        setTimeout(function() {
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);
        }, 0);
    }
}