1// public/frontend/diamond/assets/js/preRollAd.js 2 3class PreRollAd { 4 constructor(contentVideoElement, adData, isMobileDevice) { 5 this.contentVideo = contentVideoElement; 6 this.adData = adData; 7 this.isMobile = isMobileDevice; 8 9 this.adContainer = document.getElementById('adContainer'); 10 this.playPauseBtn = null; 11 this.volumeControl = null; 12 this.adTimer = null; 13 this.skipButton = null; 14 this.manualAdVideoElement = null; 15 this.manualImageLinkElement = null; 16 this.manualAdImageElement = null; 17 this.manualAdCodeElement = null; 18 19 this.adsManager = null; 20 this.adsLoader = null; 21 this.adDisplayContainer = null; 22 this.adInterval = null; 23 this.remainingTime = 0; 24 this.isAdMuted = true; 25 this.isAdPaused = false; 26 this.adPlayed = false; 27 this.skipCountdownDuration = 5; 28 this.imaSdkLoaded = typeof google !== 'undefined' && typeof google.ima !== 'undefined'; 29 30 this._extractAdDetails(); 31 this._initializeDOM(); 32 } 33 34 _extractAdDetails() { 35 this.adType = this.adData.type ? this.adData.type.toString() : null; 36 this.clickUrl = this.adData.url || null; 37 this.impressionUrl = this.adData.static || null; 38 39 this.desktopAsset = null; 40 this.mobileAsset = null; 41 42 switch (this.adType) { 43 case '1': 44 this.desktopAsset = this.adData.image || null; 45 this.mobileAsset = this.adData.image_mobil || null; 46 break; 47 case '2': 48 this.desktopAsset = this.adData.code || null; 49 this.mobileAsset = this.adData.mobil_code || null; 50 break; 51 case '3': 52 this.desktopAsset = this.adData.video || null; 53 this.mobileAsset = this.adData.video_mobil || null; 54 break; 55 case '4': 56 this.desktopAsset = this.adData.code || null; 57 this.mobileAsset = this.adData.mobil_code || null; 58 break; 59 } 60 this.currentAsset = this.isMobile && this.mobileAsset ? this.mobileAsset : this.desktopAsset; 61 } 62 63 _initializeDOM() { 64 if (!this.adContainer) return; 65 this.adContainer.innerHTML = ''; // Her baÅlangıçta adContainer'ı temizle 66 67 if (this.adType === '1') { 68 this.adContainer.innerHTML = ` 69 <a id="manualImageLinkElement" href="#" target="_blank" style="display:block; width:100%; height:100%; cursor:default;"> 70 <img id="manualAdImageElement" src="" alt="Reklam" style="width:100%; height:100%; object-fit:contain; cursor:default;"> 71 </a> 72 <div id="skipButtonImage" style="position:absolute; bottom:10px; right:10px; padding:8px 15px; background:rgba(0,0,0,0.7); color:white; cursor:pointer; display:none; border-radius:4px; z-index:12;">Reklamı Kapat</div> 73 `; 74 this.manualImageLinkElement = document.getElementById('manualImageLinkElement'); 75 this.manualAdImageElement = document.getElementById('manualAdImageElement'); 76 this.skipButton = document.getElementById('skipButtonImage'); 77 } else if (this.adType === '2') { 78 this.adContainer.innerHTML = ` 79 <div id="manualAdCodeElement" style="width:100%; height:100%; overflow:auto;"></div> 80 <div id="skipButtonCode" style="position:absolute; bottom:10px; right:10px; padding:8px 15px; background:rgba(0,0,0,0.7); color:white; cursor:pointer; display:none; border-radius:4px; z-index:12;">Reklamı Kapat</div> 81 `; 82 this.manualAdCodeElement = document.getElementById('manualAdCodeElement'); 83 this.skipButton = document.getElementById('skipButtonCode'); 84 } else if (this.adType === '3' || this.adType === '4') { 85 if(this.adType === '3'){ 86 this.manualAdVideoElement = document.createElement('video'); 87 this.manualAdVideoElement.id = 'manualAdVideoElement'; 88 this.manualAdVideoElement.style.width = '100%'; 89 this.manualAdVideoElement.style.height = '100%'; 90 this.manualAdVideoElement.style.display = 'block'; 91 this.manualAdVideoElement.style.objectFit = 'cover';
92 this.manualAdVideoElement.playsInline = true; 93 this.manualAdVideoElement.setAttribute('webkit-playsinline', ''); 94 if (this.isAdMuted) this.manualAdVideoElement.muted = true; 95 this.adContainer.appendChild(this.manualAdVideoElement); 96 } 97 const controlsHTML = ` 98 <div class="control-group" style="position: absolute; top: 10px; left: 10px; display: flex; gap: 10px; z-index: 12;"> 99 <div id="playPauseBtn" style="padding: 5px 10px; background: rgba(0,0,0,0.7); color: white; cursor: pointer; display:none;">ââ</div> 100 <div id="volumeControl" style="padding: 5px 10px; background: rgba(0,0,0,0.7); color: white; cursor: pointer; display:none;">${this.isAdMuted ? 'ð' : 'ð'}</div> 101 <div id="adTimer" style="padding: 5px 10px; background: rgba(0,0,0,0.7); color: white; display:none;">Reklam 0:00</div> 102 </div> 103 <div id="skipButtonVideoOrVast" style="position: absolute; bottom: 20px; right: 20px; padding: 8px 15px; background: rgba(0,0,0,0.7); color: white; cursor: pointer; display: none; border-radius: 4px; z-index:12;">Reklamı Atla (${this.skipCountdownDuration})</div> 104 `; 105 this.adContainer.insertAdjacentHTML('beforeend', controlsHTML); 106 this.playPauseBtn = document.getElementById('playPauseBtn'); 107 this.volumeControl = document.getElementById('volumeControl'); 108 this.adTimer = document.getElementById('adTimer'); 109 this.skipButton = document.getElementById('skipButtonVideoOrVast'); 110 } 111 112 if (this.playPauseBtn) this.playPauseBtn.addEventListener(this.isMobile ? 'touchend' : 'click', () => this.togglePlayPause()); 113 if (this.volumeControl) this.volumeControl.addEventListener(this.isMobile ? 'touchend' : 'click', () => this.toggleVolume()); 114 115 this.contentVideo.addEventListener('play', (event) => this.handleContentVideoPlay(event), { once: true }); 116 } 117 118 handleContentVideoPlay(event) { 119 if (!this.adPlayed && this.currentAsset) { 120 event.preventDefault(); 121 this.contentVideo.pause(); 122 this.contentVideo.style.display = 'none'; 123 this.adContainer.style.display = 'block'; 124 this.playAd(); 125 } else if (!this.currentAsset) { 126 console.log('PreRoll: No ad asset to play, continuing with content.'); 127 } 128 } 129 130 playAd() { 131 if (this.adPlayed || !this.currentAsset) { 132 if(!this.currentAsset && !this.adPlayed) this.showContentVideo(); 133 return; 134 } 135 this.adPlayed = true; 136 console.log(`PreRoll: Playing Ad Type: ${this.adType}`); 137 138 this.fireImpression(); 139 140 switch (this.adType) { 141 case '1': this.playManualImageAd(); break; 142 case '2': this.playManualCodeAd(); break; 143 case '3': this.playManualVideoAd(); break; 144 case '4': 145 if (this.imaSdkLoaded) { 146 this.initializeIMA(); 147 } else { 148 console.error('PreRoll: Google IMA SDK not loaded. Cannot play VAST ad.'); 149 this.showContentVideo(); 150 } 151 break; 152 default: 153 console.warn('PreRoll: Unsupported ad type.'); 154 this.showContentVideo(); 155 } 156 } 157 158 fireImpression() { 159 if (this.impressionUrl) { 160 try { 161 const timestamp = `_${Date.now()}_`; 162 const fullUrl = this.impressionUrl.includes('_[TIMESTAMP]_') 163 ? this.impressionUrl.replace('_[TIMESTAMP]_', timestamp) 164 : this.impressionUrl; 165 const img = new Image(1, 1); 166 img.src = fullUrl; 167 console.log('PreRoll: Impression Fired:', fullUrl); 168 } catch (error) { 169 console.error('PreRoll: Error firing impression:', error); 170 } 171 } 172 } 173 174 playManualImageAd() { 175 if (this.manualAdImageElement && this.currentAsset) { 176 this.manualAdImageElement.src = this.currentAsset.startsWith('http') ? this.currentAsset : (Habersoft.meta.url + '/' + this.currentAsset.replace(/^\//, '')); 177 if (this.clickUrl) { 178 this.manualImageLinkElement.href = this.clickUrl; 179 this.manualAdImageElement.style.cursor = 'pointer'; 180 this.manualImageLinkElement.style.cursor = 'pointer'; 181 } else { 182 this.manualImageLinkElement.removeAttribute('href'); 183 this.manualImageLinkElement.style.cursor = 'default'; 184 this.manualAdImageElement.style.cursor = 'default'; 185 this.manualImageLinkElement.onclick = (e) => e.preventDefault(); 186 } 187 if (this.skipButton) { 188 this.skipButton.style.cursor = 'pointer'; 189 setTimeout(() => { 190 if (this.adContainer.style.display === 'block') { 191 this.skipButton.style.display = 'block'; 192 this.skipButton.textContent = 'Reklamı Kapat'; 193 this.skipButton.onclick = () => this.skipAd(); 194 } 195 }, this.skipCountdownDuration * 1000); 196 } 197 } else { 198 this.showContentVideo(); 199 } 200 } 201 202 playManualCodeAd() { 203 if (this.manualAdCodeElement && this.currentAsset) { 204 this.manualAdCodeElement.innerHTML = this.currentAsset; 205 Array.from(this.manualAdCodeElement.getElementsByTagName("script")).forEac
205h(oldScript => { 206 const newScript = document.createElement("script"); 207 Array.from(oldScript.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value)); 208 if(oldScript.src) { 209 newScript.src = oldScript.src; 210 if(oldScript.async) newScript.async = oldScript.async; 211 if(oldScript.defer) newScript.defer = oldScript.defer; 212 } else { 213 newScript.appendChild(document.createTextNode(oldScript.innerHTML)); 214 } 215 oldScript.parentNode.replaceChild(newScript, oldScript); 216 }); 217 if (this.skipButton) { 218 this.skipButton.style.cursor = 'pointer'; 219 setTimeout(() => { 220 if (this.adContainer.style.display === 'block') { 221 this.skipButton.style.display = 'block'; 222 this.skipButton.textContent = 'Reklamı Kapat'; 223 this.skipButton.onclick = () => this.skipAd(); 224 } 225 }, this.skipCountdownDuration * 1000); 226 } 227 } else { 228 this.showContentVideo(); 229 } 230 } 231 232 playManualVideoAd() { 233 if (this.manualAdVideoElement && this.currentAsset) { 234 this.manualAdVideoElement.src = this.currentAsset.startsWith('http') ? this.currentAsset : (Habersoft.meta.url + '/' + this.currentAsset.replace(/^\//, '')); 235 this.manualAdVideoElement.load(); 236 this.manualAdVideoElement.play() 237 .then(() => { 238 this.isAdPaused = false; 239 if(this.playPauseBtn) this.playPauseBtn.textContent = 'ââ'; 240 if(this.playPauseBtn) this.playPauseBtn.style.display = 'block'; 241 if(this.volumeControl) this.volumeControl.style.display = 'block'; 242 if(this.adTimer) this.adTimer.style.display = 'block'; 243 244 if (this.manualAdVideoElement.duration && !isNaN(this.manualAdVideoElement.duration)) { 245 this.startAdTimer(this.manualAdVideoElement.duration); 246 this.startSkipCountdown(this.manualAdVideoElement.duration); 247 } else { 248 this.manualAdVideoElement.onloadedmetadata = () => { 249 if (this.manualAdVideoElement.duration && !isNaN(this.manualAdVideoElement.duration)) { 250 this.startAdTimer(this.manualAdVideoElement.duration); 251 this.startSkipCountdown(this.manualAdVideoElement.duration); 252 } else { 253 if(this.adTimer) this.adTimer.style.display = 'none'; 254 if(this.skipButton) this.skipButton.style.display = 'none'; 255 } 256 }; 257 } 258 this.setupManualVideoControls(); 259 }) 260 .catch(e => { 261 console.error('PreRoll: Error playing manual video ad:', e); 262 this.showContentVideo(); 263 }); 264 } else { 265 this.showContentVideo(); 266 } 267 } 268 269 setupManualVideoControls() { 270 this.manualAdVideoElement.onended = () => this.showContentVideo(); 271 this.manualAdVideoElement.style.cursor = this.clickUrl ? 'pointer' : 'default'; 272 this.manualAdVideoElement.onclick = () => { 273 if (this.clickUrl) { 274 window.open(this.clickUrl, '_blank'); 275 } 276 }; 277 if(this.skipButton) this.skipButton.style.cursor = 'pointer'; 278 } 279 280 initializeIMA() { 281 const adContainerForIma = document.getElementById('adContainer'); 282 const containerWidth = adContainerForIma.offsetWidth > 0 ? adContainerForIma.offsetWidth : (this.contentVideo.offsetWidth > 0 ? this.contentVideo.offsetWidth : 760); 283 const containerHeight = adContainerForIma.offsetHeight > 0 ? adContainerForIma.offsetHeight : (containerWidth * (3/4)); 284 285 if(this.playPauseBtn) this.playPauseBtn.style.display = 'block'; 286 if(this.volumeControl) this.volumeControl.style.display = 'block'; 287 if(this.adTimer) this.adTimer.style.display = 'block'; 288 289 this.adDisplayContainer = new google.ima.AdDisplayContainer(this.adContainer, this.contentVideo); 290 this.adsLoader = new google.ima.AdsLoader(this.adDisplayContainer); 291 292 this.adsLoader.addEventListener( 293 google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, 294 (event) => this.onAdsManagerLoaded(event, containerWidth, containerHeight), 295 false 296 ); 297 this.adsLoader.addEventListener( 298 google.ima.AdErrorEvent.Type.AD_ERROR, 299 (event) => this.onAdError(event), 300 false 301 ); 302 303 this.contentVideo.onended = () => { 304 if (this.adsLoader) this.adsLoader.contentComplete(); 305 }; 306 307 const adsRequest = new google.ima.AdsRequest(); 308 const vastUrl = this.currentAsset; 309 const cacheBuster = Date.now(); 310 311 adsRequest.adTagUrl = vastUrl; 312 if (vastUrl.includes('${CACHEBUSTE}')) { 313 adsRequest.adTagUrl = vastUrl.replace('${CACHEBUSTE}', cacheBuster); 314 } 315 316 console.log("PreRoll: Requesting VAST Ad with Tag URL:", adsRequest.adTagUrl); 317 318 adsRequest.linearAdSlotWidth = containerWidth; 319 adsRequest.linearAdSlotHeight = containerHeight; 320 adsRequest.nonLinearAdSlotWidth = containerWidth;
321 adsRequest.nonLinearAdSlotHeight = Math.min(150, containerHeight / 3); 322 323 this.adDisplayContainer.initialize(); 324 this.adsLoader.requestAds(adsRequest); 325 } 326 327 onAdsManagerLoaded(adsManagerLoadedEvent, width, height) { 328 const adsRenderingSettings = new google.ima.AdsRenderingSettings(); 329 adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete = true; 330 331 this.adsManager = adsManagerLoadedEvent.getAdsManager(this.contentVideo, adsRenderingSettings); 332 333 this.adsManager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, (event) => this.onAdError(event)); 334 this.adsManager.addEventListener(google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED, () => this.onContentPauseRequested()); 335 this.adsManager.addEventListener(google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED, () => this.onContentResumeRequested()); 336 337 const adEvents = [ 338 google.ima.AdEvent.Type.ALL_ADS_COMPLETED, google.ima.AdEvent.Type.CLICK, 339 google.ima.AdEvent.Type.COMPLETE, google.ima.AdEvent.Type.LOADED, 340 google.ima.AdEvent.Type.PAUSED, google.ima.AdEvent.Type.RESUMED, 341 google.ima.AdEvent.Type.SKIPPABLE_STATE_CHANGED, google.ima.AdEvent.Type.STARTED, 342 google.ima.AdEvent.Type.USER_CLOSE, 343 ]; 344 adEvents.forEach(eventType => { 345 this.adsManager.addEventListener(eventType, (event) => this.onIMAAdEvent(event)); 346 }); 347 348 try { 349 this.adsManager.init(width, height, google.ima.ViewMode.NORMAL); 350 this.adsManager.setVolume(this.isAdMuted ? 0 : 1); 351 this.adsManager.start(); 352 } catch (adError) { 353 this.onAdError({ getError: () => adError }); 354 } 355 } 356 357 onIMAAdEvent(adEvent) { 358 const ad = adEvent.getAd(); 359 360 switch (adEvent.type) { 361 case google.ima.AdEvent.Type.STARTED: 362 if (ad && ad.isLinear()) { 363 this.isAdPaused = false; 364 if(this.playPauseBtn) this.playPauseBtn.textContent = 'ââ'; 365 this.startAdTimer(ad.getDuration()); 366 } 367 break; 368 case google.ima.AdEvent.Type.SKIPPABLE_STATE_CHANGED: 369 if (this.skipButton) { 370 if (ad && ad.isSkippable()) { 371 this.skipButton.style.display = 'block'; 372 this.skipButton.style.cursor = 'pointer'; 373 this.startSkipCountdown(this.adsManager ? this.adsManager.getRemainingTime() : this.skipCountdownDuration); 374 } else { 375 this.skipButton.style.display = 'none'; 376 } 377 } 378 break; 379 case google.ima.AdEvent.Type.PAUSED: 380 this.isAdPaused = true; 381 if(this.playPauseBtn) this.playPauseBtn.textContent = 'â¶'; 382 clearInterval(this.adInterval); 383 break; 384 case google.ima.AdEvent.Type.RESUMED: 385 this.isAdPaused = false; 386 if(this.playPauseBtn) this.playPauseBtn.textContent = 'ââ'; 387 this.startAdTimer(this.adsManager ? this.adsManager.getRemainingTime() : 0); 388 break; 389 case google.ima.AdEvent.Type.CLICK: 390 break; 391 } 392 } 393 394 onContentPauseRequested() { 395 this.contentVideo.pause(); 396 } 397 398 onContentResumeRequested() { 399 this.showContentVideo(); 400 } 401 402 onAdError(errorEvent) { 403 console.error('PreRoll Ad Error:', errorEvent.getError ? errorEvent.getError() : errorEvent); 404 if (this.adsManager) { 405 this.adsManager.destroy(); 406 this.adsManager = null; 407 } 408 this.showContentVideo(); 409 } 410 411 togglePlayPause() { 412 if (this.adType === '3' && this.manualAdVideoElement) { 413 if (this.manualAdVideoElement.paused) { 414 this.manualAdVideoElement.play(); 415 this.isAdPaused = false; 416 if(this.playPauseBtn) this.playPauseBtn.textContent = 'ââ'; 417 this.startAdTimer(this.manualAdVideoElement.duration - this.manualAdVideoElement.currentTime); 418 } else { 419 this.manualAdVideoElement.pause(); 420 this.isAdPaused = true; 421 if(this.playPauseBtn) this.playPauseBtn.textContent = 'â¶'; 422 clearInterval(this.adInterval); 423 } 424 } else if (this.adType === '4' && this.adsManager) { 425 if (this.isAdPaused) { 426 this.adsManager.resume(); 427 } else { 428 this.adsManager.pause(); 429 } 430 } 431 } 432 433 toggleVolume() { 434 this.isAdMuted = !this.isAdMuted; 435 if (this.adType === '3' && this.manualAdVideoElement) { 436 this.manualAdVideoElement.muted = this.isAdMuted; 437 } else if (this.adType === '4' && this.adsManager) { 438 this.adsManager.setVolume(this.isAdMuted ? 0 : 1); 439 } 440 if(this.volumeControl) this.volumeControl.textContent = this.isAdMuted ? 'ð' : 'ð'; 441 } 442 443 startAdTimer(duration) { 444 if (!this.adTimer || isNaN(duration) || duration <=0) { 445 if(this.adTimer) this.adTimer.style.display = 'none'; 446 return; 447 } 448 clearInterval(this.adInterval); 449 this.remainingTime = Math.floor(duration); 450 if(this.adTimer) this.adTimer.style.display = 'block';
451 this.updateTimerDisplay(); 452 453 this.adInterval = setInterval(() => { 454 if (this.isAdPaused) return; 455 this.remainingTime = Math.max(0, this.remainingTime - 1); 456 this.updateTimerDisplay(); 457 if (this.remainingTime <= 0) { 458 clearInterval(this.adInterval); 459 } 460 }, 1000); 461 } 462 463 updateTimerDisplay() { 464 if (this.adTimer && typeof this.remainingTime === 'number' && this.remainingTime >= 0) { 465 const minutes = Math.floor(this.remainingTime / 60); 466 const seconds = this.remainingTime % 60; 467 this.adTimer.textContent = `Reklam ${minutes}:${seconds.toString().padStart(2, '0')}`; 468 } else if (this.adTimer) { 469 this.adTimer.style.display = 'none'; 470 } 471 } 472 473 startSkipCountdown(adDuration) { 474 if (!this.skipButton) return; 475 476 if (this.adType === '1' || this.adType === '2') return; 477 478 if (!isNaN(adDuration) && adDuration > 0 && adDuration <= this.skipCountdownDuration) { 479 this.skipButton.style.display = 'none'; 480 return; 481 } 482 if (isNaN(adDuration) || adDuration <= 0) { 483 setTimeout(() => { 484 if(this.adContainer.style.display === 'block' && this.contentVideo.style.display === 'none'){ 485 this.skipButton.style.display = 'block'; 486 this.skipButton.textContent = "Åimdi Atla"; 487 this.skipButton.style.cursor = 'pointer'; 488 this.skipButton.onclick = () => this.skipAd(); 489 } 490 }, this.skipCountdownDuration * 1000); 491 return; 492 } 493 494 this.skipButton.style.display = 'block'; 495 this.skipButton.style.cursor = 'pointer'; 496 let countdown = this.skipCountdownDuration; 497 this.skipButton.textContent = `Reklamı Atla (${countdown})`; 498 this.skipButton.onclick = null; 499 500 const skipInterval = setInterval(() => { 501 if (this.isAdPaused) return; 502 countdown--; 503 if (this.skipButton.style.display !== 'block') { 504 clearInterval(skipInterval); 505 return; 506 } 507 if (countdown >= 0) { 508 this.skipButton.textContent = `Reklamı Atla (${countdown})`; 509 } 510 if (countdown <= 0) { 511 clearInterval(skipInterval); 512 this.skipButton.textContent = "Åimdi Atla"; 513 this.skipButton.onclick = () => this.skipAd(); 514 } 515 }, 1000); 516 } 517 518 skipAd() { 519 clearInterval(this.adInterval); 520 if (this.adType === '3' && this.manualAdVideoElement) { 521 this.manualAdVideoElement.pause(); 522 } else if (this.adType === '4' && this.adsManager && this.adsManager.getAdSkippableState && this.adsManager.getAdSkippableState()) { 523 this.adsManager.skip(); 524 } 525 this.showContentVideo(); 526 } 527 528 showContentVideo() { 529 if (this.adContainer) this.adContainer.style.display = 'none'; 530 this.contentVideo.style.display = 'block'; 531 if (this.contentVideo.paused) { // EÄer içerik videosu duraklatılmıÅsa oynat 532 this.contentVideo.play().catch(e => console.error("PreRoll: Error playing content video after ad:", e)); 533 } 534 this.adPlayed = true; 535 } 536} 537 538// Bu kısım Blade dosyasından (preRollContainer.blade.php) taÅındı ve global Habersoft nesnesine baÄımlı hale getirildi. 539// DOMContentLoaded içinde veya sayfa sonunda çaÄrılmalı. 540// Blade tarafında `data-ad-config` ile `adContainer`'a eklenen JSON verisi okunacak. 541function initializeGlobalPreRollAd() { 542 const adContainerElement = document.getElementById('adContainer'); 543 const contentVideoElement = document.getElementById('contentVideo'); 544 545 if (adContainerElement && contentVideoElement && adContainerElement.dataset.adConfig) { 546 try { 547 const adDataFromServer = JSON.parse(adContainerElement.dataset.adConfig); 548 const isMobileForJs = Habersoft && Habersoft.agent && typeof Habersoft.agent.isMobile !== 'undefined' ? Habersoft.agent.isMobile : false; 549 550 551 if (adDataFromServer && adDataFromServer.type && typeof PreRollAd !== 'undefined') { 552 function initializeWhenReady() { 553 if (adDataFromServer.type === '4' && (typeof google === 'undefined' || typeof google.ima === 'undefined')) { 554 console.log('PreRoll: Waiting for IMA SDK to load...'); 555 setTimeout(initializeWhenReady, 200); 556 return; 557 } 558 console.log('PreRoll: Initializing with data:', adDataFromServer); 559 if (!window.currentPreRollAdInstance) { 560 window.currentPreRollAdInstance = new PreRollAd(contentVideoElement, adDataFromServer, isMobileForJs); 561 } else { 562 console.log('PreRoll: Instance already exists.'); 563 } 564 } 565 initializeWhenReady(); 566 } else { 567 if (typeof PreRollAd === 'undefined') { 568 console.error('PreRoll: PreRollAd class is not defined.'); 569 } else { 570 console.log('PreRoll: No valid pre-roll ad data from data-ad-config.'); 571 } 572 } 573 } catch (e) { 574 console.error('PreRoll: Error parsing ad config from data attribute.', e); 575 } 576 } else { 577 if (!adContainerElement) console.log('PreRoll: adContainer element not found.'); 578 else if (!contentVideoElement) console.log('PreRoll: contentVideo element not found.'); 579 else if (!adContainerElement.dataset.adConfig) console.log('PreRoll: data-ad-config attribute not found on adContainer.'); 580 } 581} 582 583// IMA SDK'nın yüklenmesini bekleyip sonra baÅlatıcı fonksiyonu çaÄırabiliriz 584// veya direkt DOMContentLoaded içinde çaÄırabiliriz ve PreRollAd sınıfı içinde SDK'yı kontrol edebiliriz. 585// Mevcut yapıda PreRollAd içinde kontrol ediliyor. 586document.addEventListener('DOMContentLoaded', initializeGlobalPreRollAd);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.