chunks
9 months ago
vendor
8 months ago
admin.build.js
9 months ago
admin.js
9 months ago
analytics-tracker.js
9 months ago
analytics.build.js
8 months ago
blocks.build.js
8 months ago
carousel.js
1 year ago
documents-viewer-script.js
3 years ago
front.js
9 months ago
frontend.build.js
9 months ago
gallery-justify.js
9 months ago
gutneberg-script.js
1 year ago
index.html
7 years ago
initCarousel.js
2 years ago
initplyr.js
8 months ago
instafeed.js
9 months ago
license.js
9 months ago
preview.js
8 months ago
settings.js
9 months ago
sponsored.js
9 months ago
sponsored.js
267 lines
| 1 | 'use strict'; |
| 2 | |
| 3 | |
| 4 | const isPyr = document.querySelector('[data-playerid]')?.getAttribute('data-playerid'); |
| 5 | if (!isPyr) { |
| 6 | var scriptUrl = 'https:\/\/www.youtube.com\/s\/player\/9d15588c\/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; if (!window["YT"]) YT = { loading: 0, loaded: 0 }; var YTConfig; if (!window["YTConfig"]) YTConfig = { "host": "https://www.youtube.com" }; |
| 7 | if (!YT.loading) { |
| 8 | YT.loading = 1; (function () { |
| 9 | var l = []; YT.ready = function (f) { if (YT.loaded) f(); else l.push(f) }; window.onYTReady = function () { YT.loaded = 1; var i = 0; for (; i < l.length; i++)try { l[i]() } catch (e) { } }; YT.setConfig = function (c) { var k; for (k in c) if (c.hasOwnProperty(k)) YTConfig[k] = c[k] }; 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) { |
| 10 | var n = c.nonce || c.getAttribute("nonce"); if (n) a.setAttribute("nonce", |
| 11 | n) |
| 12 | } var b = document.getElementsByTagName("script")[0]; b.parentNode.insertBefore(a, b) |
| 13 | })() |
| 14 | }; |
| 15 | } |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | let adsConainers = document.querySelectorAll('[data-sponsored-id]'); |
| 21 | let container = document.querySelector('[data-sponsored-id]'); |
| 22 | const player = []; |
| 23 | let playerIndex = 0; |
| 24 | |
| 25 | |
| 26 | adsConainers = Array.from(adsConainers); |
| 27 | |
| 28 | const getYTVideoId = (url) => { |
| 29 | // Check if the input is a string |
| 30 | if (typeof url !== 'string') { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | const regex = /(?:youtube\.com\/(?:[^\/]+\/[^\/]+\/|(?:v|e(?:mbed)?)\/|[^#]*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/; |
| 35 | const match = url.match(regex); |
| 36 | |
| 37 | if (match && match[1]) { |
| 38 | return match[1]; |
| 39 | } |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | const hashParentClass = (element, className) => { |
| 44 | var parent = element.parentNode; |
| 45 | |
| 46 | while (parent && !parent.classList?.contains(className)) { |
| 47 | parent = parent.parentNode; |
| 48 | } |
| 49 | |
| 50 | return !!parent; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | |
| 55 | const adInitialization = (adContainer, index) => { |
| 56 | |
| 57 | |
| 58 | if(!adContainer){ |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | const adAtts = JSON.parse(atob(adContainer?.getAttribute('data-sponsored-attrs'))); |
| 63 | |
| 64 | const blockId = adAtts.clientId; |
| 65 | const blockIdMD5 = adContainer.getAttribute('data-sponsored-id'); |
| 66 | const adStartAfter = adAtts.adStart * 1000; |
| 67 | const adContent = adAtts.adContent; |
| 68 | const adVideo = adContainer.querySelector('.ep-ad'); |
| 69 | const adSource = adAtts.adSource; |
| 70 | const adVideos = []; |
| 71 | const srcUrl = adAtts.url || adAtts.embedpress_embeded_link; |
| 72 | const adSkipButtonAfter = parseInt(adAtts.adSkipButtonAfter); |
| 73 | |
| 74 | |
| 75 | addWrapperForYoutube(adContainer, srcUrl, adAtts); |
| 76 | |
| 77 | // let adVideo = adContainer.querySelector('#ad-' + blockId + ' .ep-ad'); |
| 78 | adVideos.push(adVideo); |
| 79 | |
| 80 | const adTemplate = adContainer.querySelector('.main-ad-template'); |
| 81 | const progressBar = adContainer.querySelector('.progress-bar'); |
| 82 | const skipButton = adContainer.querySelector('.skip-ad-button'); |
| 83 | const adRunningTime = adContainer.querySelector('.sponsored-running-time'); |
| 84 | var playerId; |
| 85 | const adMask = adContainer; |
| 86 | |
| 87 | |
| 88 | let playbackInitiated = false; |
| 89 | |
| 90 | if (skipButton && adSource !== 'video') { |
| 91 | skipButton.style.display = 'inline-block'; |
| 92 | } |
| 93 | |
| 94 | const hashClass = hashParentClass(adContainer, 'ep-content-protection-enabled'); |
| 95 | |
| 96 | if (hashClass) { |
| 97 | adContainer.classList.remove('sponsored-mask'); |
| 98 | } |
| 99 | |
| 100 | adMask?.addEventListener('click', function () { |
| 101 | |
| 102 | if (adContainer.classList.contains('sponsored-mask')) { |
| 103 | playerId = adContainer.querySelector('[data-playerid]')?.getAttribute('data-playerid'); |
| 104 | |
| 105 | if (typeof playerInit !== 'undefined' && playerInit.length > 0) { |
| 106 | playerInit[playerId]?.play(); |
| 107 | } |
| 108 | |
| 109 | if (getYTVideoId(srcUrl)) { |
| 110 | player[index]?.playVideo(); |
| 111 | } |
| 112 | |
| 113 | if (!playbackInitiated) { |
| 114 | setTimeout(() => { |
| 115 | if (adSource !== 'image') { |
| 116 | adContainer.querySelector('.ep-embed-content-wraper').classList.add('hidden'); |
| 117 | } |
| 118 | adTemplate?.classList.add('sponsored-running'); |
| 119 | if (adVideo && adSource === 'video') { |
| 120 | adVideo.muted = false; |
| 121 | adVideo.play(); |
| 122 | } |
| 123 | }, adStartAfter); |
| 124 | |
| 125 | playbackInitiated = true; |
| 126 | } |
| 127 | |
| 128 | adContainer.classList.remove('sponsored-mask'); |
| 129 | } |
| 130 | |
| 131 | }); |
| 132 | |
| 133 | adVideo?.addEventListener('timeupdate', () => { |
| 134 | const currentTime = adVideo?.currentTime; |
| 135 | const videoDuration = adVideo?.duration; |
| 136 | |
| 137 | if (currentTime <= videoDuration) { |
| 138 | const remainingTime = Math.max(0, videoDuration - currentTime); // Ensure it's not negative |
| 139 | adRunningTime.innerText = Math.floor(remainingTime / 60) + ':' + (Math.floor(remainingTime) % 60).toString().padStart(2, '0'); |
| 140 | } |
| 141 | |
| 142 | if (!isNaN(currentTime) && !isNaN(videoDuration)) { |
| 143 | const progress = (currentTime / videoDuration) * 100; |
| 144 | progressBar.style.width = progress + '%'; |
| 145 | |
| 146 | if (currentTime >= adSkipButtonAfter) { |
| 147 | // Show the skip button after 3 seconds |
| 148 | skipButton.style.display = 'inline-block'; |
| 149 | } |
| 150 | } |
| 151 | }); |
| 152 | |
| 153 | |
| 154 | // Add a click event listener to the skip button |
| 155 | skipButton?.addEventListener('click', () => { |
| 156 | adTemplate.remove(); |
| 157 | if (typeof playerInit !== 'undefined' && playerInit.length > 0) { |
| 158 | playerInit[playerId]?.play(); |
| 159 | |
| 160 | } |
| 161 | if (getYTVideoId(srcUrl)) { |
| 162 | player[index]?.playVideo(); |
| 163 | } |
| 164 | adContainer.querySelector('.ep-embed-content-wraper').classList.remove('hidden'); |
| 165 | }); |
| 166 | |
| 167 | // Add an event listener to check for video end |
| 168 | adVideo?.addEventListener('play', () => { |
| 169 | if (playerInit && playerInit?.length > 0) { |
| 170 | playerInit[playerId]?.stop(); |
| 171 | } |
| 172 | }); |
| 173 | |
| 174 | // Add an event listener to check for video end |
| 175 | adVideo?.addEventListener('ended', () => { |
| 176 | // Remove the main ad template from the DOM when the video ends |
| 177 | adTemplate.remove(); |
| 178 | adContainer.querySelector('.ep-embed-content-wraper').classList.remove('hidden'); |
| 179 | }); |
| 180 | |
| 181 | playerIndex++; |
| 182 | |
| 183 | } |
| 184 | |
| 185 | const isYoutubeChannel = (srcUrl) => { |
| 186 | const youtubeChannelRegex = /^(https?:\/\/)?(www\.)?youtube\.com\/(channel|user)\/[A-Za-z0-9_-]+\/?$/; |
| 187 | return youtubeChannelRegex.test(srcUrl); |
| 188 | }; |
| 189 | |
| 190 | const addWrapperForYoutube = (adContainer, srcUrl, adAtts) => { |
| 191 | |
| 192 | const youtubeIframe = adContainer.querySelector(`.ose-youtube iframe`); |
| 193 | |
| 194 | if (youtubeIframe && getYTVideoId(srcUrl)) { |
| 195 | |
| 196 | const divWrapper = document.createElement('div'); |
| 197 | divWrapper.className = 'ad-youtube-video'; |
| 198 | youtubeIframe.setAttribute('width', adAtts.width); |
| 199 | youtubeIframe.setAttribute('height', adAtts.height); |
| 200 | youtubeIframe.parentNode.replaceChild(divWrapper, youtubeIframe); |
| 201 | divWrapper.appendChild(youtubeIframe); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | |
| 206 | |
| 207 | function onYouTubeIframeAPIReady(iframe, srcUrl, adVideo, index) { |
| 208 | // Find the iframe by its src attribute |
| 209 | |
| 210 | if (iframe && getYTVideoId(srcUrl) !== null) { |
| 211 | player[index] = new YT.Player(iframe, { |
| 212 | videoId: getYTVideoId(srcUrl), |
| 213 | |
| 214 | events: { |
| 215 | 'onReady': (event) => onPlayerReady(event, adVideo), |
| 216 | } |
| 217 | }); |
| 218 | |
| 219 | } |
| 220 | |
| 221 | } |
| 222 | |
| 223 | // This function is called when the player is ready |
| 224 | function onPlayerReady(event, adVideo) { |
| 225 | adVideo?.addEventListener('ended', function () { |
| 226 | event.target.playVideo(); |
| 227 | }); |
| 228 | |
| 229 | adVideo?.addEventListener('play', function () { |
| 230 | event.target.pauseVideo(); |
| 231 | }); |
| 232 | } |
| 233 | |
| 234 | if (adsConainers.length > 0 && embedpressFrontendData.isProPluginActive) { |
| 235 | |
| 236 | window.onload = function () { |
| 237 | let yVideos = setInterval(() => { |
| 238 | var youtubeVideos = document.querySelectorAll('.ose-youtube'); |
| 239 | if (youtubeVideos.length > 0) { |
| 240 | clearInterval(yVideos); |
| 241 | |
| 242 | youtubeVideos.forEach((yVideo, index) => { |
| 243 | const srcUrl = yVideo.querySelector('iframe')?.getAttribute('src'); |
| 244 | const adVideo = yVideo.closest('.sponsored-mask')?.querySelector('.ep-ad'); |
| 245 | const isYTChannel = yVideo.closest('.sponsored-mask')?.querySelector('.ep-youtube-channel'); |
| 246 | if (adVideo && !isYTChannel) { |
| 247 | |
| 248 | onYouTubeIframeAPIReady(yVideo, srcUrl, adVideo, index); |
| 249 | } |
| 250 | }); |
| 251 | } |
| 252 | }, 100); |
| 253 | }; |
| 254 | |
| 255 | let ytIndex = 0; |
| 256 | adsConainers.forEach((adContainer, epAdIndex) => { |
| 257 | |
| 258 | adContainer.setAttribute('data-ad-index', epAdIndex); |
| 259 | adInitialization(adContainer, ytIndex); |
| 260 | if (getYTVideoId(adContainer.querySelector('iframe')?.getAttribute('src'))) { |
| 261 | ytIndex++; |
| 262 | } |
| 263 | }); |
| 264 | } |
| 265 | else{ |
| 266 | jQuery('.sponsored-mask').removeClass('sponsored-mask'); |
| 267 | } |