PageSourceSearch

https://madamefigaro.jp/wp-content/themes/madamefigaro-jp/assets/js/pager-ad-loader.js?ver=1.0.153

js madamefigaro.jp collected 2026-09-24 19:19:21 UTC 3,578 bytes, 117 lines download raw bytes

1/**
2 * Pager Ad Loader
3 * ページャーブロック表示時に広告を動的読み込み
4 *
5 * @package madameFIGARO.jp
6 * @since 1.0.0
7 */
8(function() {
9    'use strict';
10
11    // 既に読み込まれた広告を管理
12    const loadedAds = new Set();
13
14    /**
15     * Billboard-2nd広告の表示処理
16     */
17    function displayBillboard2nd() {
18        if (typeof googletag === 'undefined') {
19            console.warn('googletag is not defined');
20            return;
21        }
22
23        googletag.cmd.push(function() {
24            console.log('Display Billboard-2nd and Showcase-2nd');
25            googletag.display('div-gpt-ad-billboard-a-2nd');
26            googletag.display('div-gpt-ad-showcase-2nd');
27        });
28    }
29
30    /**
31     * IntersectionObserver設定
32     */
33    const observerOptions = {
34        root: null,
35        rootMargin: '200px',  // 200px手前で読み込み開始
36        threshold: 0
37    };
38
39    const observer = new IntersectionObserver(function(entries) {
40        entries.forEach(function(entry) {
41            if (!entry.isIntersecting) {
42                return;
43            }
44
45            const pager = entry.target;
46            const adType = pager.dataset.showAd;
47            const postId = parseInt(pager.dataset.postId, 10);
48            const position = parseInt(pager.dataset.pagerPosition, 10);
49            const adKey = adType + '-' + postId + '-' + position;
50
51            // 既に読み込み済みならスキップ
52            if (loadedAds.has(adKey)) {
53                return;
54            }
55
56            console.log('Pager ad triggered:', adType, 'postID:', postId, 'position:', position);
57
58            // 広告表示処理
59            if (adType === 'billboard-2nd') {
60                displayBillboard2nd();
61            } else if (adType === 'infinity-page') {
62                // dynamic_whatpagerAD() を呼び出し
63                if (typeof dynamic_whatpagerAD === 'function') {
64                    dynamic_whatpagerAD(postId, position);
65                } else {
66                    console.error('dynamic_whatpagerAD function not found');
67                }
68            }
69
70            // 読み込み済みとしてマーク
71            loadedAds.add(adKey);
72
73            // 監視解除
74            observer.unobserve(pager);
75        });
76    }, observerOptions);
77
78    /**
79     * 初期化関数
80     */
81    function init() {
82        // data-show-ad属性を持つページャーブロックを全て監視
83        const pagers = document.querySelectorAll('.whatpager-pager[data-show-ad]');
84
85        console.log('Pager ad loader initialized. Found', pagers.length, 'ad pagers');
86
87        pagers.forEach(function(pager) {
88            observer.observe(pager);
89        });
90    }
91
92    /**
93     * 指定要素内のページャーブロックを監視対象に追加
94     * (無限スクロール等で動的に追加された記事用)
95     *
96     * @param {HTMLElement} container - 検索対象のコンテナ要素
97     */
98    function observePagers(container) {
99        if (!container) return;
100        var pagers = container.querySelectorAll('.whatpager-pager[data-show-ad]');
101        pagers.forEach(function(pager) {
102            observer.observe(pager);
103        });
104    }
105
106    // グローバルに公開(無限スクロールから呼び出し用)
107    window.figaroPagerAdLoader = {
108        observePagers: observePagers
109    };
110
111    // DOM読み込み後に初期化
112    if (document.readyState === 'loading') {
113        document.addEventListener('DOMContentLoaded', init);
114    } else {
115        init();
116    }
117})();

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.