Created
March 13, 2022 16:50
-
-
Save ZaWertun/264ae234023063985e4b7a22f2676741 to your computer and use it in GitHub Desktop.
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
function findChildByClass(el, clazz, deep) { | |
let children = Array.isArray(el) ? el : Array.from(el.childNodes); | |
if (deep === true) { | |
for (let i = 0; i < children.length; ++i) { | |
let res = findChildByClass(children[i], clazz, true); | |
if (res) return res; | |
} | |
} | |
return children.find(i => Array.from(i.classList || []).indexOf(clazz) != -1); | |
} | |
function saveAsFile(data, fileName, mimeType) { | |
let a = document.createElement('a'); | |
document.body.append(a); | |
a.style = 'display: none'; | |
let blob = new Blob([data], {type: mimeType}), | |
href = URL.createObjectURL(blob); | |
a.href = href; | |
a.download = fileName; | |
a.click(); | |
URL.revokeObjectURL(href); | |
a.remove(); | |
} | |
(function () { | |
let collectionName = 'Неизвестная', | |
metadata = document.getElementsByClassName('metadata')[0]; | |
if (metadata) { | |
let el = findChildByClass(metadata, 'title', true); | |
if (el) { | |
collectionName = el.textContent; | |
} | |
} | |
let data = [], | |
contents = document.getElementById('contents'), | |
table = Array.from(contents.childNodes[0].childNodes).find(el => el.id == 'contents'); | |
table.childNodes.forEach((el) => { | |
let columns = findChildByClass(el, 'flex-columns'), | |
childNodes = Array.from(columns.childNodes); | |
let titleColumn = findChildByClass(childNodes, 'title-column'), | |
secondaryColumn = findChildByClass(childNodes, 'secondary-flex-columns'); | |
let title = findChildByClass(titleColumn, 'yt-formatted-string', true), | |
group = findChildByClass(secondaryColumn, 'yt-formatted-string', true); | |
if (title && group) { | |
data.push(title.textContent + ', ' + group.textContent); | |
} | |
}); | |
// Yandex Music: $('.d-icon_heart').click(); | |
console.log(`Collection "${collectionName}", total rows := ${data.length}`); | |
saveAsFile(data.join('\r\n'), collectionName + '.txt', 'text/plain; charset=utf-8'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment