PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.9.9
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.9.9
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / assets / js / ads.js
embedpress / assets / js Last commit date
vendor 7 years ago admin.js 2 years ago ads.js 2 years ago documents-viewer-script.js 3 years ago front.js 2 years ago index.html 7 years ago initplyr.js 2 years ago pdfobject.min.js 3 years ago plyr.polyfilled.js 3 years ago preview.js 3 years ago settings.js 6 years ago vimeo-player.js 2 years ago ytiframeapi.js 2 years ago
ads.js
255 lines
1 const isPyr = document.querySelector('[data-playerid]')?.getAttribute('data-playerid');
2 if (!isPyr) {
3 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" };
4 if (!YT.loading) {
5 YT.loading = 1; (function () {
6 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) {
7 var n = c.nonce || c.getAttribute("nonce"); if (n) a.setAttribute("nonce",
8 n)
9 } var b = document.getElementsByTagName("script")[0]; b.parentNode.insertBefore(a, b)
10 })()
11 };
12 }
13
14
15
16
17 let adsConainers = document.querySelectorAll('[data-ad-id]');
18 let container = document.querySelector('[data-ad-id]');
19 const player = [];
20 let playerIndex = 0;
21
22
23 adsConainers = Array.from(adsConainers);
24
25 const getYTVideoId = (url) => {
26 // Check if the input is a string
27 if (typeof url !== 'string') {
28 return false;
29 }
30
31 const regex = /(?:youtube\.com\/(?:[^\/]+\/[^\/]+\/|(?:v|e(?:mbed)?)\/|[^#]*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/;
32 const match = url.match(regex);
33
34 if (match && match[1]) {
35 return match[1];
36 }
37 return false;
38 }
39
40 const hashParentClass = (element, className) => {
41 var parent = element.parentNode;
42
43 while (parent && !parent.classList?.contains(className)) {
44 parent = parent.parentNode;
45 }
46
47 return !!parent;
48 }
49
50
51
52 const adInitialization = (adContainer, index) => {
53
54 const adAtts = JSON.parse(atob(adContainer.getAttribute('data-ad-attrs')));
55
56 const blockId = adAtts.clientId;
57 const blockIdMD5 = adContainer.getAttribute('data-ad-id');
58 const adStartAfter = adAtts.adStart * 1000;
59 const adContent = adAtts.adContent;
60 const adVideo = adContainer.querySelector('.ep-ad');
61 const adSource = adAtts.adSource;
62 const adVideos = [];
63 const srcUrl = adAtts.url || adAtts.embedpress_embeded_link;
64 const adSkipButtonAfter = parseInt(adAtts.adSkipButtonAfter);
65
66
67 addWrapperForYoutube(adContainer, srcUrl, adAtts);
68
69 // let adVideo = adContainer.querySelector('#ad-' + blockId + ' .ep-ad');
70 adVideos.push(adVideo);
71
72 const adTemplate = adContainer.querySelector('.main-ad-template');
73 const progressBar = adContainer.querySelector('.progress-bar');
74 const skipButton = adContainer.querySelector('.skip-ad-button');
75 const adRunningTime = adContainer.querySelector('.ad-running-time');
76 var playerId;
77 const adMask = adContainer;
78
79
80 let playbackInitiated = false;
81
82 if (skipButton && adSource !== 'video') {
83 skipButton.style.display = 'inline-block';
84 }
85
86 const hashClass = hashParentClass(adContainer, 'ep-content-protection-enabled');
87
88 if (hashClass) {
89 adContainer.classList.remove('ad-mask');
90 }
91
92 adMask?.addEventListener('click', function () {
93
94 if (adContainer.classList.contains('ad-mask')) {
95 playerId = adContainer.querySelector('[data-playerid]')?.getAttribute('data-playerid');
96
97 if (playerInit.length > 0) {
98 playerInit[playerId]?.play();
99 }
100
101 if (getYTVideoId(srcUrl)) {
102 player[index]?.playVideo();
103 }
104
105 if (!playbackInitiated) {
106 setTimeout(() => {
107 if (adSource !== 'image') {
108 adContainer.querySelector('.ep-embed-content-wraper').classList.add('hidden');
109 }
110 adTemplate?.classList.add('ad-running');
111 if (adVideo && adSource === 'video') {
112 adVideo.muted = false;
113 adVideo.play();
114 }
115 }, adStartAfter);
116
117 playbackInitiated = true;
118 }
119
120 adContainer.classList.remove('ad-mask');
121 }
122
123 });
124
125 adVideo?.addEventListener('timeupdate', () => {
126 const currentTime = adVideo?.currentTime;
127 const videoDuration = adVideo?.duration;
128
129 if (currentTime <= videoDuration) {
130 const remainingTime = Math.max(0, videoDuration - currentTime); // Ensure it's not negative
131 adRunningTime.innerText = Math.floor(remainingTime / 60) + ':' + (Math.floor(remainingTime) % 60).toString().padStart(2, '0');
132 }
133
134 if (!isNaN(currentTime) && !isNaN(videoDuration)) {
135 const progress = (currentTime / videoDuration) * 100;
136 progressBar.style.width = progress + '%';
137
138 if (currentTime >= adSkipButtonAfter) {
139 // Show the skip button after 3 seconds
140 skipButton.style.display = 'inline-block';
141 }
142 }
143 });
144
145
146 // Add a click event listener to the skip button
147 skipButton?.addEventListener('click', () => {
148 adTemplate.remove();
149 if (playerInit.length > 0) {
150 playerInit[playerId]?.play();
151
152 }
153 if (getYTVideoId(srcUrl)) {
154 player[index]?.playVideo();
155 }
156 adContainer.querySelector('.ep-embed-content-wraper').classList.remove('hidden');
157 });
158
159 // Add an event listener to check for video end
160 adVideo?.addEventListener('play', () => {
161 if (playerInit.length > 0) {
162 playerInit[playerId]?.stop();
163 }
164 });
165
166 // Add an event listener to check for video end
167 adVideo?.addEventListener('ended', () => {
168 // Remove the main ad template from the DOM when the video ends
169 adTemplate.remove();
170 adContainer.querySelector('.ep-embed-content-wraper').classList.remove('hidden');
171 });
172
173 playerIndex++;
174
175 }
176
177 const addWrapperForYoutube = (adContainer, srcUrl, adAtts) => {
178 const youtubeIframe = adContainer.querySelector(`.ose-youtube iframe`);
179 if (youtubeIframe && getYTVideoId(srcUrl)) {
180
181 const divWrapper = document.createElement('div');
182 divWrapper.className = 'ad-youtube-video';
183 youtubeIframe.setAttribute('width', adAtts.width);
184 youtubeIframe.setAttribute('height', adAtts.height);
185 youtubeIframe.parentNode.replaceChild(divWrapper, youtubeIframe);
186 divWrapper.appendChild(youtubeIframe);
187 }
188 }
189
190
191
192 function onYouTubeIframeAPIReady(iframe, srcUrl, adVideo, index) {
193 // Find the iframe by its src attribute
194
195 if (iframe && getYTVideoId(srcUrl) !== null) {
196 player[index] = new YT.Player(iframe, {
197 videoId: getYTVideoId(srcUrl),
198
199 events: {
200 'onReady': (event) => onPlayerReady(event, adVideo),
201 }
202 });
203
204 }
205
206 }
207
208 // This function is called when the player is ready
209 function onPlayerReady(event, adVideo) {
210 adVideo?.addEventListener('ended', function () {
211 event.target.playVideo();
212 });
213
214 adVideo?.addEventListener('play', function () {
215 event.target.pauseVideo();
216 });
217 }
218
219 if (adsConainers.length > 0 && eplocalize.is_pro_plugin_active) {
220
221 window.onload = function () {
222 let yVideos = setInterval(() => {
223 var youtubeVideos = document.querySelectorAll('.ose-youtube');
224 if (youtubeVideos.length > 0) {
225 clearInterval(yVideos);
226
227 youtubeVideos.forEach((yVideo, index) => {
228 const srcUrl = yVideo.querySelector('iframe')?.getAttribute('src');
229 const adVideo = yVideo.closest('.ad-mask')?.querySelector('.ep-ad');
230 const isYTChannel = yVideo.closest('.ad-mask')?.querySelector('.ep-youtube-channel');
231 if (adVideo && !isYTChannel) {
232
233 console.log(isYTChannel);
234
235 onYouTubeIframeAPIReady(yVideo, srcUrl, adVideo, index);
236 }
237 });
238 }
239 }, 100);
240 };
241
242 console.log('ads settings');
243 let ytIndex = 0;
244 adsConainers.forEach((adContainer, epAdIndex) => {
245
246 adContainer.setAttribute('data-ad-index', epAdIndex);
247 adInitialization(adContainer, ytIndex);
248 if (getYTVideoId(adContainer.querySelector('iframe')?.getAttribute('src'))) {
249 ytIndex++;
250 }
251 });
252 }
253 else{
254 jQuery('.ad-mask').removeClass('ad-mask');
255 }