YouTube Live Chat Downloader

Downloads the current live chat from YouTube for future reading. Please take note that this is in beta stage and more features are going to be added or fixed soon. Press "A" to download the live chats. Do not focus onto the chat input on the bottom before you start typing. There will be a button for this soon.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YouTube Live Chat Downloader
// @namespace    https://youtube.com
// @version      1.1
// @description  Downloads the current live chat from YouTube for future reading. Please take note that this is in beta stage and more features are going to be added or fixed soon. Press "A" to download the live chats. Do not focus onto the chat input on the bottom before you start typing. There will be a button for this soon.
// @author       Sabrina
// @match        https://www.youtube.com/live_chat*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=YouTube.com
// @require      http://code.jquery.com/jquery-3.3.1.min.js
// @require      https://code.jquery.com/ui/1.12.0/jquery-ui.min.js
// @grant        none
// ==/UserScript==

window.chatLogs = "";

$(".style-scope yt-live-chat-item-list-renderer").on('DOMNodeInserted', function(e) {
    if(e.target.id === "content") {
        setTimeout(() => {
            chatLogs += (e.target.outerText.replace(/[\r\n]/g, " - ")) + "<br>";
        }, 1);
    }
});

window.downloadLiveChat = function() {
    const link = document.createElement("a");
    const file = new Blob([chatLogs], { type: 'text/plain' });
    link.href = URL.createObjectURL(file);
    link.download = "ytlivechat"+new Date().getTime()+".html";
    link.click();
    URL.revokeObjectURL(link.href);
}

document.addEventListener("keydown", function(e) {
    if(e.keyCode == 65) {
        downloadLiveChat();
    }
});