Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var scriptUrl = 'https://www.youtube.com/s/player/21812a9c/www-widgetapi.vflset/www-widgetapi.js';
- try {
- var ttPolicy = window.trustedTypes.createPolicy("youtube-widget-api", {
- createScriptURL: function (x) {
- return x;
- }
- });
- scriptUrl = ttPolicy.createScriptURL(scriptUrl);
- } catch (e) {}
- var YT = YT || {
- loading: 0,
- loaded: 0
- };
- var YTConfig = window.YTConfig || {
- host: "https://www.youtube.com"
- };
- let player;
- let apiReady = false;
- let modalOpened = false; // Added flag to track modal state
- // Load the YouTube API
- function loadYouTubeAPI() {
- if (!YT.loading) {
- YT.loading = 1;
- var a = document.createElement("script");
- a.type = "text/javascript";
- a.id = "www-widgetapi-script";
- a.src = scriptUrl;
- a.async = true;
- var c = document.currentScript;
- if (c) {
- var n = c.nonce || c.getAttribute("nonce");
- if (n) {
- a.setAttribute("nonce", n);
- }
- }
- var b = document.getElementsByTagName("script")[0];
- b.parentNode.insertBefore(a, b);
- }
- }
- function onYouTubeIframeAPIReady() {
- apiReady = true;
- if (modalOpened) {
- ModalFlexAndPlayVideo();
- }
- }
- function resetPlayerAndModal() {
- if (player) {
- player.pauseVideo();
- player.destroy();
- }
- var modalSection = document.querySelector('.fixed-modal-section');
- modalSection.style.display = 'none';
- modalOpened = false;
- }
- function ModalFlexAndPlayVideo() {
- if (apiReady) {
- player = new YT.Player('muteVideoYoutube', {
- events: {
- 'onReady': function (event) {
- event.target.playVideo();
- var modalSection = document.querySelector('.fixed-modal-section');
- modalSection.style.display = 'flex';
- modalOpened = true;
- console.log("Video playing");
- }
- }
- });
- } else {
- console.log("API is not ready yet.");
- loadYouTubeAPI();
- console.log("Loading YouTube API...");
- }
- }
- document.querySelector('.modal-close-btn').addEventListener('click', resetPlayerAndModal);
- document.querySelector('.daria-testimonial-photo-block').addEventListener('click', ModalFlexAndPlayVideo);
- </script>
Advertisement
Add Comment
Please, Sign In to add comment