Skip to content

Instantly share code, notes, and snippets.

@titangene
Last active June 28, 2023 06:59
Show Gist options
  • Save titangene/73e8b0ee351ff367f5d740d9aaaa11bc to your computer and use it in GitHub Desktop.
Save titangene/73e8b0ee351ff367f5d740d9aaaa11bc to your computer and use it in GitHub Desktop.
copy YouTube song title
(() => {
const videoDescriptionSelector = '#description-inline-expander > yt-attributed-string';
const $videoDescription = document.querySelector(videoDescriptionSelector);
const [songTitle, artist] = $videoDescription?.textContent
.split('\n\n')[1]
.split(' · ');
const fullArtist = document.querySelector('#owner #upload-info a').textContent;
const result = `${fullArtist} - ${songTitle}`;
copy(result);
function copy(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('Copy');
textArea.remove();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment