PageSourceSearch

https://news.infoseek.co.jp/common/js/article/interstitial_ads-1.1.js

js infoseek.co.jp collected 2026-09-24 08:30:05 UTC 12,443 bytes, 357 lines download raw bytes

1const COOKIE_VALUE = 'true';
2const MISSION_STATUS = {
3    DMISSION_1: 'DMISSION_1',
4    DMISSION_2: 'DMISSION_2',
5    DMISSION_3: 'DMISSION_3',
6    DMISSION_ACHIEVED: 'DMISSION_ACHIEVED',
7    NON_MISSION: 'NON_MISSION',
8};
9const AD_TYPE = {
10    RUNA: 'RUNA',
11    EXTERNAL: 'EXTERNAL',
12};
13const AGREEMENT_DAYS_KEY = {
14    DMISSION_1: 'ad1_mission_agreed_days_before',
15    DMISSION_2: 'ad2_mission_agreed_days_before',
16    DMISSION_3: 'ad3_mission_agreed_days_before',
17};
18INTERSTITIAL_ADS_CONDITION = {
19    DMISSION_1: {
20        COOKIE_NAME: 'ARTICLE_DETAIL_INTERSTITIAL_AD_1_DISMISSED',
21        FREQUENCY_TYPE_KEY: 'mission_unachieved_show_again_after_minutes',
22        AD_TAG_KEY: {
23            RUNA: 'runa_1',
24            EXTERNAL: 'external_1',
25        },
26    },
27    DMISSION_2: {
28        COOKIE_NAME: 'ARTICLE_DETAIL_INTERSTITIAL_AD_2_DISMISSED',
29        FREQUENCY_TYPE_KEY: 'mission_unachieved_show_again_after_minutes',
30        AD_TAG_KEY: {
31            RUNA: 'runa_2',
32            EXTERNAL: 'external_2',
33        },
34    },
35    DMISSION_3: {
36        COOKIE_NAME: 'ARTICLE_DETAIL_INTERSTITIAL_AD_3_DISMISSED',
37        FREQUENCY_TYPE_KEY: 'mission_unachieved_show_again_after_minutes',
38        AD_TAG_KEY: {
39            RUNA: 'runa_3',
40            EXTERNAL: 'external_3',
41        },
42    },
43    DMISSION_ACHIEVED: {
44        COOKIE_NAME: 'ARTICLE_DETAIL_INTERSTITIAL_AD_ACHIEVED_DISMISSED',
45        FREQUENCY_TYPE_KEY: 'mission_achieved_show_again_after_minutes',
46        AD_TAG_KEY: {
47            RUNA: 'runa_achieved',
48            EXTERNAL: 'external_achieved',
49        },
50    },
51    NON_MISSION: {
52        COOKIE_NAME: 'ARTICLE_DETAIL_INTERSTITIAL_AD_NON_MISSION_DISMISSED',
53        FREQUENCY_TYPE_KEY: 'non_mission_show_again_after_minutes',
54        AD_TAG_KEY: {
55            RUNA: 'runa_non_mission',
56            EXTERNAL: 'external_non_mission',
57        },
58    },
59};
60
61let missionStatus = null;
62let referrer = document.referrer;
63let isFirstAd = true;
64
65/**
66 * Display interstitial ad for daily mission user
67 *
68 * @param numDoneRepetitions number of repetitions completed
69 * @param numToComplete number of repetitions required to complete the daily mission
70 * @param agreedDateTime date & time when user agreed to the daily mission
71 * @param missionProgressAdvancement daily mission progress advancement
72 */
73function displayInterstitialAdForDailyMissionUser(numDoneRepetitions, numToComplete, agreedDateTime, missionProgressAdvancement) {
74    let isOfferwallInactive = true;
75
76    if (numDoneRepetitions === 1) {
77        if (isDateBeforeRequiredDays(agreedDateTime, AGREEMENT_DAYS_KEY.DMISSION_1)) {
78            missionStatus = MISSION_STATUS.DMISSION_1;
79        }
80    } else if (numToComplete % 2 === 0 && (numToComplete / numDoneRepetitions) === 2) {
81        if (isDateBeforeRequiredDays(agreedDateTime, AGREEMENT_DAYS_KEY.DMISSION_2)) {
82            missionStatus = MISSION_STATUS.DMISSION_2;
83        }
84    } else if (numToComplete % 2 !== 0 && Math.round(numToComplete / 2) === numDoneRepetitions) {
85        if (isDateBeforeRequiredDays(agreedDateTime, AGREEMENT_DAYS_KEY.DMISSION_2)) {
86            missionStatus = MISSION_STATUS.DMISSION_2;
87        }
88    } else if ((numToComplete - numDoneRepetitions) === 1) {
89        if (isDateBeforeRequiredDays(agreedDateTime, AGREEMENT_DAYS_KEY.DMISSION_3)) {
90            missionStatus = MISSION_STATUS.DMISSION_3;
91        }
92    } else if (missionProgressAdvancement === 'COMPLETED' || missionProgressAdvancement === 'POINTS_REQUESTED') {
93        missionStatus = MISSION_STATUS.DMISSION_ACHIEVED;
94    } else {
95        isOfferwallInactive = false;
96    }
97
98    // Block Offerwall if the current daily mission repetition count doesn't match to the condition
99    if (isOfferwallInactive) {
100        blockOfferwall();
101    }
102
103    // Do not display ads if the current daily mission repetition count
104    // and daily mission agreement day don't match to the condition
105    if (missionStatus == null) {
106        return;
107    }
108
109    // If referrer is invalid or if interstitial settings fail to get
110    if (!isValidReferrer(referrer) || interstitialAdsConditions == null || interstitialAdTagIds == null) {
111        return;
112    }
113
114    displayInterstitialAd(AD_TYPE.EXTERNAL);
115}
116
117/**
118 * Display interstitial ad for non-daily mission user
119 */
120function displayInterstitialAdForNonDailyMissionUser() {
121    // Always block Offerwall for Non daily mission user
122    blockOfferwall();
123
124    // If referrer is invalid or if interstitial settings fail to get
125    if (!isValidReferrer(referrer) || interstitialAdsConditions == null || interstitialAdTagIds == null) {
126        return;
127    }
128
129    missionStatus = MISSION_STATUS.NON_MISSION;
130    displayInterstitialAd(AD_TYPE.RUNA);
131}
132
133/**
134 * Display interstitial ad according to ad type
135 *
136 * @param adType ad type
137 */
138function displayInterstitialAd(adType) {
139    const currentMissionStatus = INTERSTITIAL_ADS_CONDITION[missionStatus];
140    const frequencyTypeKey = currentMissionStatus.FREQUENCY_TYPE_KEY;
141    const frequencyMinutes = interstitialAdsConditions[frequencyTypeKey];
142    const cookieName = currentMissionStatus.COOKIE_NAME;
143    const tagKey = currentMissionStatus.AD_TAG_KEY[adType];
144    const tagId = interstitialAdTagIds[tagKey];
145
146    // If advertisement tag settings fail to get
147    if (!tagId) {
148        return;
149    }
150
151    if (isFirstAd) {
152        // Do nothing if frequency minutes setting fail to get, or it is not a number
153        if (!frequencyMinutes || isNaN(frequencyMinutes)) {
154            return;
155        }
156        // Do nothing if the cookie hasn't expired yet
157        if (Cookies.get(cookieName) === COOKIE_VALUE) {
158            return;
159        }
160    }
161
162    switch (adType) {
163        case AD_TYPE.RUNA:
164            displayRunaInterstitialAd(cookieName, tagId, frequencyMinutes);
165            break;
166        case AD_TYPE.EXTERNAL:
167            displayExternalInterstitialAd(cookieName, tagId, frequencyMinutes);
168            break;
169    }
170}
171
172/**
173 * Display RUNA interstitial ad
174 *
175 * @param cookieName frequency control cookie name
176 * @param tagId advertisement tag ID
177 * @param frequencyMinutes frequency minutes
178 */
179function displayRunaInterstitialAd(cookieName, tagId, frequencyMinutes) {
180    if (!tagId.includes('-')) {
181        return;
182    }
183
184    // Add RUNA ad elements to HTML body
185    addRunaAdElements(tagId);
186
187    $('.interstitialClickAdRUNA')[0].addEventListener('slotResponseReceived', function (e) {
188        // If an ad was found, show it and set the frequency control cookie
189        // If not, do recovery
190        if (e && e.detail && e.detail.adReturned) {
191            // Disable scrolling while ads are displayed
192            document.body.style.overflow = 'hidden';
193            $('#interstitial_ad_modal').addClass('is-visible');
194            setCookie(cookieName, frequencyMinutes);
195
196            // When an ad is closed, trigger an event to start the mission
197            $('#interstitial_close_button').on('click', function (event) {
198                // Enable scrolling after closing ads
199                document.body.style.overflow = 'auto';
200                $('#interstitial_ad_modal').remove();
201                window.dispatchEvent(new CustomEvent('CloseInterstitialModal'));
202            });
203        } else {
204            $('#interstitial_ad_modal').remove();
205            // If non daily mission user, display external company ad instead
206            // If not, trigger an event to start the mission
207            if (missionStatus === MISSION_STATUS.NON_MISSION) {
208                isFirstAd = false;
209                displayInterstitialAd(AD_TYPE.EXTERNAL);
210            } else {
211                window.dispatchEvent(new CustomEvent('StartMissionStatusBar'));
212            }
213        }
214    });
215}
216
217/**
218 * Display external company interstitial ad
219 *
220 * @param cookieName frequency control cookie name
221 * @param tagId advertisement tag ID
222 * @param frequencyMinutes frequency minutes
223 */
224function displayExternalInterstitialAd(cookieName, tagId, frequencyMinutes) {
225    // Set a listener to detect if an ad in stock or not
226    window.top.addEventListener('message', function (ev) {
227        // If an ad was found, show it and set the frequency control cookie
228        // If not, do recovery
229        if (ev.data.type === 'gnadfill') {
230            setCookie(cookieName, frequencyMinutes);
231            setExternalAdRemovalObserver();
232        } else if (ev.data.type === 'gnnoad') {
233            // If daily mission user, display RUNA ad instead
234            if (missionStatus !== MISSION_STATUS.NON_MISSION) {
235                isFirstAd = false;
236                displayInterstitialAd(AD_TYPE.RUNA);
237            }
238        }
239    });
240
241    // Add script element to the body
242    $('<script>', {
243        src: `https://works.gsspcln.jp/w/m150154/${tagId}.js`,
244        async: true,
245    }).appendTo('body');
246}
247
248/**
249 * Check if the daily mission agreement date is the required days before
250 *
251 * @param agreedDateTime date & time when user agreed to the daily mission
252 * @param agreementDaysKey required agreement day condition key
253 * @returns {boolean}
254 */
255function isDateBeforeRequiredDays(agreedDateTime, agreementDaysKey) {
256    const agreedDaysBefore = interstitialAdsConditions[agreementDaysKey];
257
258    // If agreement days setting fail to get or 0 days
259    if (!agreedDaysBefore || agreedDaysBefore === 0) {
260        return true;
261    }
262
263    let requiredDate = new Date();
264    requiredDate.setDate(requiredDate.getDate() - agreedDaysBefore);
265    let agreementDate = new Date(agreedDateTime);
266    return agreementDate < requiredDate;
267}
268
269/**
270 * Block offerwall
271 */
272function blockOfferwall() {
273    window.googletag = window.googletag || {cmd: []};
274    googletag.cmd.push(function () {
275        googletag.pubads().setTargeting('OW_IS', ['0']);
276    });
277}
278
279/**
280 * Add RUNA ad elements to HTML body
281 *
282 * @param tagId advertisement tag ID
283 */
284function addRunaAdElements(tagId) {
285    const firstHalfOfTag = tagId.split('-')[0];
286    const divToAppendAdTag = $('#interstitial_ad_content');
287
288    // Add div element under the target div
289    $('<div>', {
290        id: `rdn-adspot-${tagId}`,
291        class: 'interstitialClickAdRUNA',
292    }).appendTo(divToAppendAdTag);
293
294    // Add script element under the target div
295    $('<script>', {
296        text: `
297                var rdntag = rdntag || {};
298                rdntag.cmd = rdntag.cmd || [];
299                rdntag.cmd.push(function() {
300                    rdntag.defineAd("${firstHalfOfTag}", "rdn-adspot-${tagId}").setRz(Cookies.get("Rz") || "");
301                    rdntag.display("rdn-adspot-${tagId}");
302                });
303            `,
304    }).appendTo(divToAppendAdTag);
305
306    // Add script to the body
307    $('<script>', {
308        type: 'text/javascript',
309        src: 'https://s-cdn.rmp.rakuten.co.jp/js/aa.js',
310    }).appendTo('body');
311}
312
313/**
314 * Set the frequency control cookie
315 *
316 * @param cookieName frequency control cookie name
317 * @param frequencyMinutes frequency minutes
318 */
319function setCookie(cookieName, frequencyMinutes) {
320    if (frequencyMinutes === 0) {
321        return;
322    }
323    const expirationTime = new Date(Date.now() + (frequencyMinutes * 60 * 1000));
324    Cookies.set(cookieName, COOKIE_VALUE, {
325        expires: expirationTime, sameSite: 'Lax', domain: window.location.hostname, secure: location.protocol === 'https:',
326    });
327}
328
329/**
330 * Set the observer to detect when external company interstitial ad is closed
331 */
332function setExternalAdRemovalObserver() {
333    const targetNode = document.body;
334    const config = {
335        childList: true,
336    };
337
338    // MutationObserver settings
339    const observer = new MutationObserver((mutationsList, observer) => {
340        mutationsList.forEach((mutation) => {
341            mutation.removedNodes.forEach((removedNode) => {
342                // Stop observer and trigger an event to start the mission if the element with ID gn_interstitial_iframe_content is removed
343                if ($(removedNode).is('#gn_interstitial_iframe_content')) {
344                    observer.disconnect();
345                    window.dispatchEvent(new CustomEvent('CloseInterstitialModal'));
346                }
347            });
348        });
349    });
350
351    // Start monitoring
352    observer.observe(targetNode, config);
353}
354
355window.globalDatabaseFunction = {};
356window.globalDatabaseFunction.displayInterstitialAdForDailyMissionUser = displayInterstitialAdForDailyMissionUser;
357window.globalDatabaseFunction.displayInterstitialAdForNonDailyMissionUser = displayInterstitialAdForNonDailyMissionUser;

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.