Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Iframe title attribute addition via fetch #408

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@
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) {
// eslint-disable-next-line vars-on-top
console.error('Error:', error);

Check warning on line 163 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 +172,23 @@
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';
} 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 +200,8 @@
</iframe>`;

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

Expand Down
Loading