Skip to content

Commit 0255f3b

Browse files
committed
feat: checked elemento in dom for copy description
1 parent 00608fb commit 0255f3b

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

youtube_script_new_ui.js

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,47 +2720,52 @@
27202720
}
27212721

27222722
function downloadDescriptionVideo() {
2723-
if($e('#button_copy_description')) return;
2723+
if ($e('#button_copy_description')) return;
2724+
2725+
const containerDescription = $e('#bottom-row.style-scope.ytd-watch-metadata');
2726+
if (!containerDescription) {
2727+
console.warn('No se encontró el contenedor de descripción. No se insertará el botón.');
2728+
return;
2729+
}
2730+
27242731
const buttomHTML = `
2725-
<div id="button_copy_description" style="display: flex; justify-content: end; align-items: center;margin-top: 10px;" >
2726-
<button id="copy-description" class="botones_div" type="button" style="cursor: pointer;">
2727-
<i style="font-size: 20px;" class="fa-solid fa-copy"></i>
2728-
</button>
2729-
</div>
2730-
`;
2731-
const containerDescription = $e('#bottom-row.style-scope.ytd-watch-metadata');
2732-
containerDescription.insertAdjacentHTML('beforebegin', buttomHTML);
2733-
$id('copy-description').addEventListener('click', () => {
2734-
const ldJson = [...document.querySelectorAll('script[type="application/ld+json"]')];
2735-
for (let script of ldJson) {
2736-
try {
2737-
const data = JSON.parse(script.innerText);
2738-
2739-
if (data['@type'] === 'VideoObject') {
2740-
const description =
2741-
`📅 Date published: ${data.uploadDate || 'No available'}\n` +
2742-
`Author: ${data.author || 'No available'}\n` +
2743-
`🎬 Name video: ${data.name || 'No available'}\n` +
2744-
`🖼️ Thumbnail: ${Array.isArray(data.thumbnailUrl) ? data.thumbnailUrl.join(', ') : data.thumbnailUrl || 'No available'}\n` +
2745-
`📝 description: ${data.description || 'No available'}\n\n\n` +
2746-
`🎭 Category: ${data.genre || 'No available'}\n`;
2747-
2748-
navigator.clipboard.writeText(`${description}`)
2732+
<div id="button_copy_description" style="display: flex; justify-content: end; align-items: center;margin-top: 10px;" >
2733+
<button id="copy-description" class="botones_div" type="button" style="cursor: pointer;">
2734+
<i style="font-size: 20px;" class="fa-solid fa-copy"></i>
2735+
</button>
2736+
</div>
2737+
`;
2738+
2739+
containerDescription.insertAdjacentHTML('beforebegin', buttomHTML);
2740+
2741+
$id('copy-description').addEventListener('click', () => {
2742+
const ldJson = [...document.querySelectorAll('script[type="application/ld+json"]')];
2743+
for (let script of ldJson) {
2744+
try {
2745+
const data = JSON.parse(script.innerText);
2746+
if (data['@type'] === 'VideoObject') {
2747+
const description =
2748+
`📅 Date published: ${data.uploadDate || 'No disponible'}\n` +
2749+
`Author: ${data.author || 'No disponible'}\n` +
2750+
`🎬 Name video: ${data.name || 'No disponible'}\n` +
2751+
`🖼️ Thumbnail: ${Array.isArray(data.thumbnailUrl) ? data.thumbnailUrl.join(', ') : data.thumbnailUrl || 'No disponible'}\n` +
2752+
`📝 Description: ${data.description || 'No disponible'}\n\n\n` +
2753+
`🎭 Category: ${data.genre || 'No disponible'}\n`;
2754+
2755+
navigator.clipboard.writeText(description);
2756+
}
2757+
} catch (e) {
2758+
Notify('error', 'Error parsing JSON-LD');
2759+
} finally {
2760+
Notify('success', 'Descripción copiada');
27492761
}
2750-
} catch (e) {
2751-
Notify('error', 'Error data JSON');
2752-
} finally {
2753-
Notify('success', 'Description video copied');
27542762
}
2755-
}
2756-
});
2757-
2763+
});
27582764
}
2759-
2765+
27602766
downloadDescriptionVideo();
27612767

27622768

2763-
27642769
async function traductor() {
27652770
const texto = $m('#content-text');
27662771
if ($e('.buttons-tranlate')) return;

0 commit comments

Comments
 (0)