Skip to content

Commit

Permalink
Test Iframe title attribute addition via fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
vladpananetcetric committed Aug 7, 2024
1 parent 0e4d006 commit eab03ae
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ export function createIcon(name) {
return icon;
}

async function fetchAndSetIframeTitle(urlVendor, iframe) {
try {
const response = await fetch(urlVendor);
const data = await response.json();
iframe.setAttribute('title', data.title);
} catch (error) {
console.error('Error:', error);

Check warning on line 162 in scripts/scripts.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
}
}

function createEmbedIFrame(a, vendor) {
const div = document.createElement('div');
div.classList.add(`${vendor}-base`);
Expand All @@ -161,18 +171,23 @@ function createEmbedIFrame(a, vendor) {
let source;
let className;
let allow;
let urlVendor;

if (vendor === 'youtube') {
source = `https://www.youtube.com/embed/${id}`;
className = 'youtube-player';
allow = 'encrypted-media; accelerometer; gyroscope; picture-in-picture';
urlVendor = `https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${id}&format=json`;
} else if (vendor === 'spotify') {
source = `https://open.spotify.com/embed/episode/${id}`;
className = 'spotify-player';
allow = 'autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture';
urlVendor = `https://open.spotify.com/oembed?url=https://open.spotify.com/episode/78DmMlPuBgkPzziPKx8oko`;

Check failure on line 185 in scripts/scripts.js

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
} else if (vendor === 'wistia') {
source = `https://fast.wistia.net/embed/iframe/${id}`;
className = 'wistia-player';
allow = 'autoplay; clipboard-write; encrypted-media; fullscreen;';
urlVendor = `https://fast.wistia.com/oembed/?url=https://fast.wistia.net/embed/iframe/${id}&format=json`;
}

div.innerHTML = `<iframe data-src="${source}"
Expand All @@ -184,6 +199,8 @@ function createEmbedIFrame(a, vendor) {
</iframe>`;

a.replaceWith(div);
const iframe = div.querySelector('iframe');
fetchAndSetIframeTitle(urlVendor, iframe);
return div;
}

Expand Down

0 comments on commit eab03ae

Please sign in to comment.