Created
August 12, 2024 03:37
-
-
Save dclamage/faab559fcf6a9dbb1d4c5f118fd8e296 to your computer and use it in GitHub Desktop.
Extract youtube comments from current page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Extract YouTube Comments | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-05-29 | |
// @description Extract YouTube Comments | |
// @author Rangsk | |
// @match https://www.youtube.com/watch* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
window.extractComments = function() { | |
return [...document.querySelectorAll('.ytd-comment-view-model')] | |
.filter(div => div.querySelectorAll('span[role="text"]').length > 0) | |
.filter(div => { | |
const span = div.querySelector('span'); | |
return span && span.innerText[0] === '@'; | |
}) | |
.map(div => [...div.querySelectorAll('span')].filter(span => (span.innerText[0] === '@' || span.getAttribute('role') === 'text' || span.classList.contains('yt-core-attributed-string')) && span.innerText != 'Reply').map(span => span.innerText)).filter((_, index) => index % 2 === 0).map(o => o.join(' - ').replace(/\r?\n|\r/g, ' ')) | |
.join('\n'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment