PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.1.2
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.1.2
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 1 year ago ads.js 1 year ago carousel.js 1 year ago carousel.min.js 2 years ago documents-viewer-script.js 3 years ago front.js 1 year ago glider.js 1 year ago glider.min.js 2 years ago gutneberg-script.js 2 years ago index.html 7 years ago initCarousel.js 2 years ago initplyr.js 2 years ago instafeed.js 2 years ago license.js 2 years ago pdfobject.js 1 year ago plyr.js 1 year 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
270 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-sponsored-id]');
18 let container = document.querySelector('[data-sponsored-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
55 if(!adContainer){
56 return;
57 }
58
59 const adAtts = JSON.parse(atob(adContainer?.getAttribute('data-sponsored-attrs')));
60
61 console.log({adAtts});
62
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 && eplocalize.is_pro_plugin_active) {
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 console.log(isYTChannel);
249
250 onYouTubeIframeAPIReady(yVideo, srcUrl, adVideo, index);
251 }
252 });
253 }
254 }, 100);
255 };
256
257 console.log('ads settings');
258 let ytIndex = 0;
259 adsConainers.forEach((adContainer, epAdIndex) => {
260
261 adContainer.setAttribute('data-ad-index', epAdIndex);
262 adInitialization(adContainer, ytIndex);
263 if (getYTVideoId(adContainer.querySelector('iframe')?.getAttribute('src'))) {
264 ytIndex++;
265 }
266 });
267 }
268 else{
269 jQuery('.sponsored-mask').removeClass('sponsored-mask');
270 }