Skip to content

Instantly share code, notes, and snippets.

@nhh
Last active February 15, 2024 09:58
Show Gist options
  • Save nhh/0ab1bbd1988cceb256aa27abdadee3ca to your computer and use it in GitHub Desktop.
Save nhh/0ab1bbd1988cceb256aa27abdadee3ca to your computer and use it in GitHub Desktop.
Spotify web player songtext scraper
function updateStatus(status) {
const options = {
suggestedName: 'Spotify Song Texte',
types: [
{
description: 'Text Files',
accept: {
'text/plain': ['.txt'],
},
},
],
};
const fileHandle = await window.showSaveFilePicker(options);
const writable = await fileHandle.createWritable();
// Write the contents of the file to the stream.
await writable.write("Blubb");
// Close the file and write the contents to disk.
await writable.close();
}
const attrObserver2 = new MutationObserver((mutations) => {
mutations.forEach(mu => {
if (mu.type !== "attributes" && mu.attributeName !== "class") return;
if (mu.target.classList.contains('arY01KDGhWNgzlAHlhpd')) updateStatus(mu.target.innerText)
});
});
let initialSongName = document.querySelector("[data-testid='context-item-link']").innerText
document.querySelectorAll("[data-testid='fullscreen-lyric']").forEach(el => attrObserver2.observe(el, {attributes: true}));
setInterval(() => {
//let list = document.querySelectorAll("[data-testid='fullscreen-lyric']");
//if(list.length !== initialList.length) {
// initialList = list
// initialList.forEach(el => attrObserver2.observe(el, {attributes: true}));
//}
const songname = document.querySelector("[data-testid='context-item-link']").innerText
if(songname !== initialSongName) {
initialSongName = songname
document.querySelectorAll("[data-testid='fullscreen-lyric']").forEach(el => attrObserver2.observe(el, {attributes: true}));
}
}, 250)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment