PageSourceSearch

https://www.exmoo.com/js/ad-position/ad-position.js?v22.09.22.1

js exmoo.com collected 2026-10-02 05:03:39 UTC 94,767 bytes, 2,080 lines download raw bytes

1/**
2 * 广告位插入
3 */
4
5var hrefUrl = window.location.pathname,
6    screenWidth = $(window).width();
7
8var hrefPath = hrefUrl.split('/')[1],
9    hrefPath2 = hrefUrl.split('/')[2];
10
11/**
12 * 公用 - API请求
13 */
14function $Api(url, data, success) {
15    var host = window.location.host,
16        Api = '';
17    if(host.indexOf('dev') > -1) {
18        Api = 'https://ad-dev-api.uogroup.com/'
19    }else if(host.indexOf('sit') > -1) {
20        Api = 'https://ad-sit-api.uogroup.com/'
21    }else {
22        Api = 'https://ad-api.uogroup.com/'
23    }
24    $.ajax({
25        headers: {
26            'X-device': 'WEB',
27            'X-version': '1.0',
28            'access-token': $.cookie('token') || ''
29        },
30        type: "post",
31        url: Api + url,
32        data: JSON.stringify(data),
33        dataType: "json",
34        contentType: 'application/json;charset=UTF-8',
35        success: function (res) {
36            success(res)
37            if(res.code != 0 && host.indexOf('sit') > -1) {
38                console.log('> [Api] ' + url, '\n> [Warning] ' + res.message)
39            }
40        },
41        error: function(err) {
42            console.log(err);
43        }
44    });
45}
46
47var device, device2, device3;
48var isPcSize = screenWidth >= 1024,
49    isPadSize = screenWidth >= 640 && screenWidth < 1024
50if(isPcSize) {
51    device = 'PC';
52    device2 = 'PC';
53    device3 = 'PC';
54}else if(isPadSize) {
55    device = 'MB'   // old screenWidth>=767时是MB
56    device2 = 'PC' // 文章背景广告使用,它和其它广告规则不同。和其页面展示广告图片比例有关
57    device3 = 'PC';
58}else {
59    device = 'MB'
60    device2 = 'MB'
61    device3 = screenWidth > 480 ? 'PC' : 'MB' // 手机横屏兼容, 组合广告的图片尺寸问题所以用回PC的数据  该不该这么做也要看上级需求 todo 临时
62}
63
64
65var reload = true,                      // 刷新页面
66    windowWidth = $(window).width();    // 初始大小
67$(window).resize(function() {
68    screenWidth = $(window).width();
69    if(isPcSize) {
70        device = 'PC';
71        device2 = 'PC';
72        device3 = 'PC';
73    }else if(isPadSize) {
74        device = 'MB'
75        device2 = 'PC'
76        device3 = 'PC';
77    }else {
78        device = 'MB'
79        device2 = 'MB'
80        device3 = screenWidth > 480 ? 'PC' : 'MB' // 手机横屏兼容, 组合广告的图片尺寸问题所以用回PC的数据  该不该这么做也要看上级需求 todo 临时
81    }
82    
83    // 平板下,在切换横屏的时候能够自动刷新页面
84    // if(windowWidth != screenWidth && screenWidth < 1024) {
85    //     windowWidth = screenWidth
86    //     window.location.reload()
87    // }
88})
89
90$(window).on('orientationchange', function() {
91    window.location.reload()
92});
93
94$(function() {
95
96    // 在栏目页面存在位置ID时,就去获取其数据
97    var B_ADposition = '',  // 弹窗广告
98        C_ADposition = '',  // 上滑广告
99        E_ADposition = '',  // 对联广告
100        D_ADposition = '';  // 组合广告/悬浮广告
101
102    // 首页
103    if(hrefPath == '') {
104        // 已开启的模块执行广告位添加
105        $('.home-section').each(function() {
106            var type = $(this).attr('data-adType');
107            if(type) {
108                indexADpositionFunc(type);
109            }
110        })
111        // 广告数据请求
112        getADcontentFunc('prefix', device + '-A-M', function(res) {
113            if(res.code == 0) {
114                var data = res.data;
115                AdInsertionFunc(data);  // 统一HTML格式插入
116            }
117        })
118
119        // 弹窗广告
120        B_ADposition = `${device}-B-M0-1`
121        C_ADposition = `${device}-C-M0-1`
122
123        // 对联广告
124        coupletADpositionFunc('M', 0)
125        // E_ADposition = `${device}-E-M0`
126
127        // 页顶广告
128        $('#header-container').attr('data-position', `${device}-H-M0-1`);
129    }
130
131    // 即时新闻
132    if(hrefPath == 'hot') {
133        var lineNum;
134        if(isPcSize) {  // screenWidth > 1200 old
135            // PC
136            lineNum = 3;
137        }else if(isPadSize) {
138            // ipad
139            lineNum = 2;
140        }else {
141            // mobile
142            lineNum = 1;
143        }
144
145        var listData = [];  // 网页在直接切换宽度时候,已有数据的时候直接渲染,否则请求新数据
146        function hotADpositionFunc() {
147            var lineDiv = $('.col-lg-4.col-sm-6');
148            var column = device + '-A-L1';
149            $('.article_adposition_box .ad-img-show').remove();
150            lineDiv.each(function(i) {
151                if(i != 0)
152                lineDiv.eq(i * lineNum-1).after(`<div class="ad-img-show" data-position="${column}-${i}" style="width:100%; clear:both;"></div>`)
153            })
154
155            if(listData.length > 0) {
156                AdInsertionFunc(listData);
157            }else {
158                getADcontentFunc('prefix', column + '-', function(res) {
159                    if(res.code == 0) {
160                        var data = res.data;
161                        listData = data;
162                        AdInsertionFunc(data);  // 统一HTML格式插入
163                        firstADshowFunc(column, data)
164                    }
165                })
166            }
167        }
168
169        hotADpositionFunc()
170
171        // 在手机上会有BUG,所以无法做到切换窗口大小就重新去拿值,这个会导致在手机上下滑屏时不停添加新的位置
172        // $(window).resize(function() {
173        //     // hot
174        //     if(isPcSize) {
175        //         // PC
176        //         lineNum = 3;
177        //     }else if(isPadSize) {
178        //         // ipad
179        //         lineNum = 2;
180        //     }else {
181        //         // mobile
182        //         lineNum = 1;
183        //     }
184        //     hotADpositionFunc()
185        // })
186
187
188        // 弹窗广告
189        B_ADposition = `${device}-B-L1-1`
190        C_ADposition = `${device}-C-L1-1`
191
192        // 页顶广告
193        $('#header-container').attr('data-position', `${device}-H-L1-1`);
194        // 对联广告
195        coupletADpositionFunc('L', 1)
196        // E_ADposition = `${device}-E-L1`
197    }
198    if(hrefPath == 'macau' || hrefPath == 'world' || hrefPath == 'china' || hrefPath == 'business' || hrefPath == 'sports' || hrefPath == 'leisure' || hrefPath == 'investment' || (hrefPath == 'supplement' && !hrefPath2) || (hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '9') || (hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '2') || (hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '5') || (hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '3') || (hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '7') || (hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '8')) {
199        var positionId = ''
200        if(hrefPath == 'macau') positionId = 3          // 澳闻 - 今日力报
201        if(hrefPath == 'world') positionId = 4          // 国际 - 今日力报
202        if(hrefPath == 'china') positionId = 5          // 中国 - 今日力报
203        if(hrefPath == 'business') positionId = 6       // 产经 - 今日力报
204        if(hrefPath == 'sports') positionId = 7         // 体育 - 今日力报
205        if(hrefPath == 'leisure') positionId = 8        // 娱乐 - 今日力报
206        if(hrefPath == 'investment') positionId = 9     // 湾区投资 - 今日力报
207        if(hrefPath == 'supplement' && !hrefPath2) positionId = 10                          // 全部 - 生活
208        if(hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '9') positionId = 11     // 游澳假期 - 生活
209        if(hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '2') positionId = 12     // 饮食 - 生活
210        if(hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '5') positionId = 13     // 汽车 - 生活
211        if(hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '3') positionId = 14     // 旅游 - 生活
212        if(hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '7') positionId = 15     // 消费 - 生活
213        if(hrefPath == 'supplement' && !!hrefPath2 && hrefPath2 == '8') positionId = 16     // 专栏 - 生活
214
215        // 生活和其它栏目执行事件不同
216        if(hrefPath == 'supplement') {
217            supplementADpositionFunc(positionId)
218            $(window).resize(function() {
219                supplementADpositionFunc(positionId)
220            })
221        }else {
222            window.onload = articleADpositionFunc(positionId)
223            $(window).resize(function() {
224                articleADpositionFunc(positionId)
225            })
226        }
227        
228
229        // 弹窗广告
230        B_ADposition = `${device}-B-L${positionId}-1`
231        C_ADposition = `${device}-C-L${positionId}-1`
232
233        // 页顶广告
234        $('#header-container').attr('data-position', `${device}-H-L${positionId}-1`);
235        // 对联广告
236        coupletADpositionFunc('L', positionId)
237        // E_ADposition = `${device}-E-L${positionId}`
238        
239    }
240
241    // 内文 两个文章模板
242    if(hrefPath == 'article' || (hrefPath == 'supplement' && hrefPath2 == 'article')) {
243        contentADpositionFunc()
244
245        // 页顶广告
246        $('#header-container').attr('data-position', `${articleColumnFunc(device, 'H')}-1`);
247
248        // 文章底部悬浮广告
249        // articleBottomADFunc();
250
251        // 组合广告
252        // comeboADFunc();
253        D_ADposition = articleColumnFunc(device3, 'D') + '-1';
254
255        // 对联广告
256        // E_ADposition = articleColumnFunc(device, 'E');
257        var articleColumnVar = articleColumnFunc(device, 'E');
258            articleColumnVar = articleColumnVar.substr(3)
259        // 即时
260        if(articleColumnVar == 'E-D1') coupletADpositionFunc('D', 1)
261        // 今日
262        if(articleColumnVar == 'E-D2') coupletADpositionFunc('D', 2)
263        if(articleColumnVar == 'E-D3') coupletADpositionFunc('D', 3)
264        if(articleColumnVar == 'E-D4') coupletADpositionFunc('D', 4)
265        if(articleColumnVar == 'E-D5') coupletADpositionFunc('D', 5)
266        if(articleColumnVar == 'E-D6') coupletADpositionFunc('D', 6)
267        if(articleColumnVar == 'E-D7') coupletADpositionFunc('D', 7)
268        if(articleColumnVar == 'E-D8') coupletADpositionFunc('D', 8)
269        // 生活
270        if(articleColumnVar == 'E-D10') coupletADpositionFunc('D', 10)
271        if(articleColumnVar == 'E-D11') coupletADpositionFunc('D', 11)
272        if(articleColumnVar == 'E-D12') coupletADpositionFunc('D', 12)
273        if(articleColumnVar == 'E-D13') coupletADpositionFunc('D', 13)
274        if(articleColumnVar == 'E-D14') coupletADpositionFunc('D', 14)
275        if(articleColumnVar == 'E-D15') coupletADpositionFunc('D', 15)
276    }
277
278
279    /**
280     * 广告位样式
281     */
282    var style = `
283        <style>
284        /* 广告位 */
285        .ad-jump-click {background: #e9e9e9; position: relative;}
286        .scale50 {transform: scale(.5);}
287        .ad-jump-click:after {
288            content: 'AD Position';
289            position: absolute;
290            top: 50%;
291            left: 50%;
292            font-size: 28px;
293            color: #ddd;
294            white-space: nowrap;
295            transform: translate(-50%, -50%);
296            display: none;
297        }
298        </style>`
299    $('body').append(style);
300
301
302    /**
303     * B_ADposition:弹窗广告
304     * C_ADposition:上滑广告
305     * D_ADposition:组合/悬浮广告
306     * H_ADposition:页顶广告
307     * E_ADposition:对联广告
308     */
309    var H_ADposition = $('#header-container').data('position') || '';
310    var E_AD_1 = E_ADposition ? E_ADposition + '-1' : '',
311        E_AD_2 = E_ADposition ? E_ADposition + '-2' : '';
312    var ADArray = [B_ADposition, C_ADposition, D_ADposition, H_ADposition, E_AD_1, E_AD_2],
313        submitArray = [] // 过滤空的位置
314    for(var i in ADArray) {
315        if(ADArray[i] != '') submitArray.push(ADArray[i])
316    }
317    submitArray.length > 0 && getADcontentFunc('array', submitArray, function(res) {
318        if(res.code == 0) {
319            var data = res.data;
320            for (var k in data) {
321                var adItem = data[k]
322                // 弹窗广告内容获取
323                if(adItem.tagNo == B_ADposition) {
324                    var dialogADhtml = `<div class="dialog_show_ad banner_mask">
325                        <div class="banner_top" style="max-width: ${adItem.adSizes ? adItem.adSizes[0].width + 'px' : 'auto'}">
326                            <span onclick="websiteAdCloseFunc()"><i>+</i>關閉</span>
327                            <div class="banner_top_img ad-img-show" data-position="${B_ADposition}" >
328                            </div>
329                            <p>餘下<font>0</font>秒</p>
330                        </div>
331                    </div>`
332                    
333                    $('#inner-container').prepend(dialogADhtml);
334                    AdInsertionFunc([adItem]);  // 公用广告插入,默认没有为SVG图
335
336                    if(adItem.ads.length == 1) {
337                        var intervalTime = adItem.ads[0].intervalTime / 1000,
338                            keepTime = adItem.ads[0].keepTime / 1000;
339                        // 插入成功后直接将图片替换回其真实图片
340                        $('.dialog_show_ad').find('img').each(function() {
341                            var $img = $(this),
342                                url = $img.attr('data-url'),
343                                id = $img.parent('.ad-jump-click').attr('data-id');
344
345                            var img = new Image();
346                            img.src = url;
347                            img.onload = function() {
348                                $img.attr('src', url).removeClass('scale50');
349                                $img.parent('.ad-jump-click').attr('data-count', '1');
350                                B_websiteADFunc(intervalTime, keepTime) // 图片加载成功后才执行弹窗事件
351                                ADshowCountFunc(id, false, $img.parents('.ad-img-show').data('position') + ' 弹窗AD')
352                            }
353                        })
354                    }else {
355                        // 轮播时 todo 轮播时未考虑轮播时间和弹窗的展示时间问题,弹窗功能暂时没有多张需求先放着吧哈哈
356                        $('.dialog_show_ad').find('img').each(function() {
357                            var $img = $(this),
358                                url = $img.attr('data-url'),
359                                id = $img.parent('.ad-jump-click').attr('data-id'),
360                                hasOwl = $img.parents('.owl-item.active').length;   // 判断当前是否是显示的那一张
361
362                            $img.attr('src', url).removeClass('scale50');
363                            if(hasOwl > 0) {
364                                $img.parent('.ad-jump-click').attr('data-count', '1');
365                                B_websiteADFunc(intervalTime, keepTime) // 图片加载成功后才执行弹窗事件
366                                ADshowCountFunc(id, false, $img.parent('.ad-img-show').data('position') + ' 弹窗AD')
367                            }
368                        })
369                    }
370                    countImg(); // 判断其图片的显示大小
371                }
372
373                // 上滑广告内容获取
374                if(adItem.tagNo == C_ADposition) {
375                    var C_websiteHtml = `
376                        <div class="c_website_banner banner_bg">
377                            <div class="banner">
378                                <div class="banner_img ad-img-show" data-position="${C_ADposition}"></div>
379                                <p>餘下<font>0</font>秒</p>
380                            </div>
381                        </div>
382                    `
383                    $('.column-container').before(C_websiteHtml)
384                    AdInsertionFunc([adItem]);  // 公用广告插入,默认没有为SVG图
385                    $(`.banner_img[data-position="${C_ADposition}"]`).removeAttr('style');
386
387                    var intervalTime = adItem.ads[0].intervalTime / 1000,
388                        keepTime = adItem.ads[0].keepTime / 1000;
389                    if(adItem.ads.length == 1) {
390                        // 插入成功后直接将图片替换回其真实图片
391                        $('.c_website_banner').find('img').each(function() {
392                            var $img = $(this),
393                                url = $img.attr('data-url'),
394                                id = $img.parent('.ad-jump-click').attr('data-id');
395                            var img = new Image();
396                            img.src = url;
397                            img.onload = function() {
398                                $img.attr('src', url).attr('data-count', '1').removeClass('scale50');
399                                C_websiteADFunc(intervalTime, keepTime, id)
400                            }
401                        })
402                    }else {
403                        // 轮播时
404                        $('.c_website_banner').find('img').each(function() {
405                            var $img = $(this),
406                                url = $img.attr('data-url'),
407                                id = $img.parent('.ad-jump-click').attr('data-id'),
408                                hasOwl = $img.parents('.owl-item.active').length;   // 判断当前是否是显示的那一张
409
410                            $img.attr('src', url).removeClass('scale50');
411                            if(hasOwl > 0) {
412                                $img.parent('.ad-jump-click').attr('data-count', '1');
413                                C_websiteADFunc(intervalTime, keepTime, id)
414                            }
415                        })
416                    }
417                }
418
419                // 页顶广告
420                if(adItem.tagNo == H_ADposition) {
421                    $('#header-container').attr('style', `background-image: url(${adItem.ads[0].resources[0].url})`);
422                    $('#header').attr('style', 'background-image: none')
423                    ADshowCountFunc(adItem.ads[0].adId, false, H_ADposition + ' 页顶AD')
424                }
425
426                // 对联广告
427                if(adItem.tagNo == D_ADposition) {
428                    var adsItem = adItem.ads[0];
429                    var maxImg, minImg
430                    // 等於2為組合廣告,等於1為懸浮廣告
431                    if(adsItem.resources.length == 2) {
432                        if(adsItem.resources[1].height > adsItem.resources[0].height) {
433                            maxImg = adsItem.resources[1].url
434                            minImg = adsItem.resources[0].url
435                        }else {
436                            maxImg = adsItem.resources[0].url
437                            minImg = adsItem.resources[1].url
438                        }
439                    }else {
440                        // maxImg = ''0
441                        // minImg = adsItem.resources[0].url
442                        
443                        // 单张的话执行悬浮的广告方案 articleBottomADFunc()方法已废弃,组合和悬浮功能合并
444                        // ps: 需求不要关闭按钮
445                        var newsHTML = `<div class="bottomAD">
446                            <div class="bottomAD_box">
447                                <div class="img_box">
448                                    <a class="ad-img-show" data-position="${D_ADposition}"></a>
449                                    <div class="close_AD hide" onclick="$('.bottomAD').remove();"></div>
450                                </div>
451                            </div>
452                        </div>`;
453                        $('body').append(newsHTML);
454                        AdInsertionFunc(data)
455                        try {
456                            var thatImg = data[0].ads[0].resources[0]
457                            var imgWidth = thatImg.width,
458                                imgHeight = thatImg.height
459                            var setHeight = imgHeight * $('body').width() / imgWidth
460                            setHeight = setHeight.toFixed(0)
461                            $('.img_box .ad-img-show').height(setHeight);
462                        }catch(e) {
463                            $('.bottomAD').remove();
464                            console.log('> error 底部悬浮data数据有误');
465                            return
466                        }
467
468                        var $img = $('.bottomAD').find('img'),
469                            url = $img.data('url')
470                        var img = new Image();
471                        img.src = url;
472                        img.onload = function() {
473                            $img.parents('.ad-jump-click').attr('data-count', '1');
474                            $img.attr('src', url).removeClass('scale50');
475                            // 展示后统计次数
476                            ADshowCountFunc($img.parents('.ad-jump-click').data('id'), false, '悬浮AD')
477                        }
478                        return
479                    }
480
481                    var comboADImg = maxImg,
482                        comboADBottomImg = minImg,
483                        keepTime = adsItem.keepTime / 1000
484                        intervalTime = adsItem.intervalTime / 1000,
485                        id = adsItem.adId,
486                        clickContent = JSON.stringify(adsItem.clickContent),
487                        style = adsItem.adStyle;
488
489                    var comboADHtml = `
490                        <div class="comboAD-box">
491                            <div class="comboAD-img">
492                                <img src="${comboADImg}" onclick='adJumpClickFunc(${id}, ${clickContent}, ${style})' />
493                            </div>
494                        </div>
495                        <div class="comboAD-bottom">
496                            <div class="comboAD-bottom-img">
497                                <img src="${comboADBottomImg}" onclick='adJumpClickFunc(${id}, ${clickContent}, ${style})' />
498                                <div class="comboAD-btn comboAD-close ${!comboADImg && 'hide'}"></div>
499                                <div class="comboAD-btn comboAD-open ${!comboADImg && 'hide'}"></div>
500                            </div>
501                        </div>
502                    `;
503                    $('body').append(comboADHtml);
504                    ADshowCountFunc(id);
505
506                    var firstShow = true
507                    $(window).scroll(function() {
508                        var sTop = 0;
509                        if (document.documentElement && document.documentElement.scrollTop) {
510                            sTop = document.documentElement.scrollTop;
511                        }else if (document.body) {
512                            sTop = document.body.scrollTop;
513                        }
514                        if(sTop > 300 && firstShow) {
515                            firstShow = false
516                            // 当前cookie中保留上次剩余时间时,先用完再显示
517                            // 解决上次剩余几秒时,这次进来刚显示完后又突然读完上次时间再次显示,会显示很快
518                            if(!!getCookie('comboADTime') && getCookie('comboADTime') != intervalTime) { 
519                                var sec = parseInt(getCookie('comboADTime'));          
520                                var secTime = setInterval(() => {
521                                    sec --;
522                                    if(sec <= 0) clearInterval(secTime);
523                                    setCookie('comboADTime', sec);
524                                    console.log(`剩余${sec}s加载组合广告`);
525                                }, 1000);
526                                setTimeout(() => {
527                                    showADfunc();
528                                    setCookie('comboADTime', intervalTime);
529                                }, getCookie('comboADTime')*1000);
530                            }else {
531                                showADfunc();
532                            }
533                        }
534                    })
535                
536                    var img1 = false,
537                        img2 = false,
538                        t = true;
539                    var returnTime,
540                        timeout;
541                
542                    $('.comboAD-img img').load(function() {
543                        img1 = true
544                    })
545                    $('.comboAD-bottom-img img').load(function() {
546                        img2 = true
547                    })
548                
549                    // 展示大圖
550                    function showADfunc() {
551                        // 每秒時間,獲取兩張AD是否加載完成
552                        var time = setInterval(() => {
553                            if(img1 && img2 && t) {
554                                t = false;
555                                $('.comboAD-box').fadeIn(100);
556                                $('.comboAD-bottom').fadeOut();
557                                $('#footer').css('margin-bottom', 0);
558                                ADShowPosition();   // 重置其顯示位置
559                                clearInterval(time);    // 正常顯示後,可清除當前的計時器
560                                var showTime = setTimeout(() => {
561                                    t = true;
562                                    $('.comboAD-box').fadeOut();
563                                    $('.comboAD-bottom').fadeIn();
564                                    $('#footer').css('margin-bottom', $('.comboAD-bottom').height());
565                                    returnShowADfunc();
566                
567                                    var imgHeight = $('.comboAD-bottom-img').height();
568                                    $('#footer.margin100').css('margin-bottom', imgHeight);
569                                    $('#back-to-top').css('bottom', imgHeight + 30);  // 置顶按钮位置上移
570                
571                                    clearTimeout(showTime);
572                                }, keepTime*1000);
573                            }
574                        }, 1000);
575                    }
576                    
577                    // AD position 
578                    function ADShowPosition() {
579                        if(screenWidth > 640) {
580                            var top = $('#header').height() + 100
581                            // css top有个需求,需要不能挡住栏目
582                            $('.comboAD-box').css({'top': $('#header').height(), 'height': getClientHeight()-top});
583                        }else {
584                            $('.comboAD-box').css({'top': '50%', 'transform': 'translateY(-50%)'});
585                        }
586                    }
587                
588                    // 間隔時間
589                    function returnShowADfunc() {
590                        var comboTime = intervalTime; // 初始
591                        // 當cookie中存在時間則取來使用
592                        if(!!getCookie('comboADTime')) {
593                            comboTime = getCookie('comboADTime');
594                        }
595                        clearInterval(returnTime);  // 調用前先清除上一次的計時
596                        returnTime = setInterval(() => {
597                            comboTime --;
598                            setCookie('comboADTime', comboTime);
599                            // console.log('即将显示组合广告', comboTime + 's');
600                            
601                            if(comboTime <= 0) {
602                                setCookie('comboADTime', intervalTime);  // 當0s後重新賦值最新的時間
603                                clearInterval(returnTime);
604                            }
605                        }, 1000);
606                        // timeout = setTimeout(() => {
607                        //     // showADfunc()  不需要重新放大 001
608                        // }, comboTime*1000);
609                    }
610                    
611                    // 改變屏幕時重新計算展示圖大小
612                    $(window).resize(function() {
613                        ADShowPosition();
614                
615                        // if(screenWidth > 640) {
616                        //     var comboADImg = newsAD_IMG,
617                        //         comboADBottomImg = newsAD_Resizable_IMG;
618                        // }else {
619                        //     var comboADImg = newsAD_IMG_Mb,
620                        //     comboADBottomImg = newsAD_Resizable_IMG_Mb;
621                        // }
622                        
623                        var imgHeight = $('.comboAD-bottom-img').height();
624                        $('#footer').css('margin-bottom', imgHeight);
625                    })
626                
627                    // close AD
628                    $('.comboAD-close').on('click', function() {
629                        $('.comboAD-bottom').hide();
630                        $('#footer').css('margin-bottom', '0');
631                    })
632                
633                    // open AD
634                    $('.comboAD-open').on('click', function() {
635                        setCookie('comboADTime', intervalTime);  // 展開AD後重新計算其間距時間
636                
637                        $('.comboAD-box').fadeIn(100);
638                        $('.comboAD-bottom').fadeOut();
639                        $('#footer').css('margin-bottom', '0');
640                        ADShowPosition();   // 重置其顯示位置
641                        var openTime = setTimeout(() => {
642                            $('.comboAD-box').fadeOut();
643                            $('.comboAD-bottom').fadeIn();
644                            $('#footer').css('margin-bottom', $('.comboAD-bottom').height());
645                            returnShowADfunc();
646                            clearTimeout(openTime);
647                        }, keepTime*1000);
648                    })
649                }
650
651                // 对联广告
652                if(adItem.tagNo == E_AD_1 || adItem.tagNo == E_AD_2) {
653                    // todo 暂时不移过来
654                }
655            }
656        }
657    })
658
659})
660
661
662/**
663 * 公用 - 页面滚动监听 广告懒加载
664 */
665$(window).scroll(function() {
666    var viewHeight = getClientHeight(),
667        scrollTop = $(window).scrollTop();
668    
669    $('.ad-img-show').each(function() {
670        var that = $(this),
671            top = parseInt(that.offset().top);
672        that.attr('top', top);
673
674        // 存在广告数据的 除去广告位为空的
675        if(that.html()) {
676            var $hasOwl = that.find('.owl-carousel'); // 当前图片是否轮播,存在个数就是有
677            if($hasOwl.length > 0) {
678                // 轮播 - 可视的轮播模块执行程序,再判断可见item
679                if(viewHeight + scrollTop > top) {  // todo 页面滚动过头的也要判断
680                    $hasOwl.find('.owl-item').each(function() {
681                        var $item = $(this);
682                        var imgUrl = $item.find('img').attr('data-url'),
683                            $adJumpClick = $item.find('.ad-jump-click'),
684                            id = $adJumpClick.attr('data-id');
685                        var currentClass = $item.hasClass('active');    // 当前选中的item
686
687                        // 当前轮播下图片所有可见
688                        var img = new Image();
689                        img.src = imgUrl;
690                        img.onload = function() {
691                            $item.find('img').attr('src', imgUrl).removeClass('scale50');
692                            currentClass && $adJumpClick.attr('data-count') == '0' && ADshowCountFunc(id, false, that.data('position') + ' scroll')   // 如果当前是 选中 的轮播,则统计次数
693                            // 当下可见item计数
694                            if(currentClass) {
695                                $adJumpClick.attr('data-count', 1);
696                                $item.siblings().find(`.ad-jump-click[data-id="${id}"]`).attr('data-count', 1); // 由于轮播插件的原因,相同ID的也设置为1不被重复统计
697                            }
698                        }
699                    })
700                }
701            }else {
702                if(that.find('.ad-jump-click').attr('data-style') == '2') {
703                    // 判断第三方广告的 data-style为2
704                    that.find('.ad-jump-click[data-style="2"]').each(function() {
705                        var $adJumpClick = $(this),
706                            id = $adJumpClick.attr('data-id');
707                        if($adJumpClick.attr('data-count') == '0' && viewHeight + scrollTop > top) {
708                            $adJumpClick.attr('data-count', '1')
709                            ADshowCountFunc(id, false, that.data('position') + ' GoogleAD')
710                        }
711                    })
712                }else {
713                    // 单张图片时,正常计数
714                    // 为1后不可再被计数
715                    // 图片能被加载时再执行相关事件
716                    var $img = $(this).find('img'),
717                        $adJumpClick = that.find('.ad-jump-click');
718                    if($adJumpClick.attr('data-count') == '0' && viewHeight + scrollTop > top) {
719                        $adJumpClick.attr('data-count', 1);
720                        var imgUrl = $img.data('url');
721                        var img = new Image();
722                        img.src = imgUrl;
723                        img.onload = function() {
724                            $img.attr('src', imgUrl).removeClass('scale50');
725                            ADshowCountFunc($adJumpClick.data('id'), false, that.data('position') + ' scroll')
726                        }
727                    }
728                }
729            }
730        }
731    })
732})
733
734/**
735 * 公用 - 点击统计事件/跳转
736 */
737$(document).on('click', '.ad-jump-click', function() {
738    var that = $(this);
739    var id = that.data('id'),
740        data = that.data('clickcontent');
741
742    // 通过scale50类名判断图片为可见状态,且是自销广告时可有点击统计和事件
743    if(!that.find('img').hasClass('scale50') && that.attr('data-style') == 1) {
744        ADshowCountFunc(id, true, that.parents('.ad-img-show').data('position'))
745
746        // 跳转执行条件
747        if(data.clickType == 1) {
748            window.open(data.url);
749        }else if(data.clickType == 6) {
750            if(data.category == 'subscribe') {
751                window.location.href = '/subscribe/subscribe_index'
752            }else if(data.category == 'hotarticle') {
753                window.location.href = '/hot'
754            }else if(data.category == 'article') {
755                window.location.href = '/macau'
756            }else {
757                window.location.href = '/' + data.category
758            }
759        }else if(data.clickType == 5){
760            if(data.articleType == 'supplement') {
761                window.open(`/${data.articleType}/article/${data.articleId}.html`);
762            }else {
763                window.open(`/article/${data.articleId}.html`);
764            }
765        }else if(data.clickType == 2) {
766            if(IsPC()) {
767                alert(callText + ":" + data.phone);
768            }else {
769                window.location.href = 'tel:' + data.phone;
770            }
771        }else if(data.clickType == 3) {
772            window.location.href = 'mailto:' + data.email;
773        }else {
774            var link = `https://wa.me/${data.phone}?text=${data.whatsApp}`
775            window.open(link);
776        }
777    }
778    // 第三方广告时,仅统计次数
779    if(that.attr('data-style') == 2) {
780        ADshowCountFunc(id, true, that.data('position'))
781    }
782})
783
784/**
785 * 文章背景广告专用的点击统计事件 / 组合广告
786 * @param {*} id 
787 * @param {*} data 
788 * @param {*} style 
789 */
790function adJumpClickFunc(id, data, style) {
791    if(style == 1) {
792        ADshowCountFunc(id, true, '背景/组合AD')
793        // 跳转执行条件
794        if(data.clickType == 1) {
795            window.open(data.url);
796        }else if(data.clickType == 6) {
797            if(data.category == 'subscribe') {
798                window.location.href = '/subscribe/subscribe_index'
799            }else if(data.category == 'hotarticle') {
800                window.location.href = '/hot'
801            }else if(data.category == 'article') {
802                window.location.href = '/macau'
803            }else {
804                window.location.href = '/' + data.category
805            }
806        }else if(data.clickType == 5){
807            if(data.articleType == 'supplement') {
808                window.open(`/${data.articleType}/article/${data.articleId}.html`);
809            }else {
810                window.open(`/article/${data.articleId}.html`);
811            }
812        }else if(data.clickType == 2) {
813            if(IsPC()) {
814                alert(callText + ":" + data.phone);
815            }else {
816                window.location.href = 'tel:' + data.phone;
817            }
818        }else if(data.clickType == 3) {
819            window.location.href = 'mailto:' + data.email;
820        }else {
821            var link = `https://wa.me/${data.phone}?text=${data.whatsApp}`
822            window.open(link);
823        }
824    }
825}
826
827/**
828 * 生活频道广告模块添加
829 * -A-L “信息流-列表頁”
830 */
831var supplementListData = [];
832function supplementADpositionFunc(col) {
833    var lineNum = screenWidth >= 992 ? 2 : 1;    
834    var column = device + '-A-L' + col;
835    var lineDiv = $('.supplement-span-col');
836    $('.article_adposition_box .ad-img-show').remove(); // 添加前清空原有可能存在的广告位置,再追加新的
837    lineDiv.each(function(i) {
838        if(i != 0)
839        lineDiv.eq(i * lineNum-1).after(`<div class="col-md-6 ad-img-show" data-position="${column}-${i}" style="width:100%; clear:both;"></div>`)
840    })
841    if(supplementListData.length > 0) {
842        AdInsertionFunc(supplementListData);
843    }else {
844        getADcontentFunc('prefix', column + '-', function(res) {
845            if(res.code == 0) {
846                var data = res.data;
847                supplementListData = data;
848                AdInsertionFunc(data);
849                firstADshowFunc(column, data)
850            }
851        })
852    }
853}
854
855/**
856 * 今日力报广告模块添加
857 * 结合API请求获取资源后再插入相应位置,并设占高
858 * -A-L “信息流-列表頁”
859 */
860function articleADpositionFunc(col) {
861    var column = device + '-A-L' + col;
862    // 获取本页广告位置
863    getADcontentFunc('prefix', column + '-', function(res) {
864        if(res.code == 0) {
865            var data = res.data;
866            $('.article_adposition_box .ad-img-show').remove();
867            if(screenWidth >= 768) {
868                // 添加编号
869                var r_len = $('#column-right .article_adposition').length,
870                    l_len = $('#column-left .article_adposition').length;
871                $('.article_adposition_box #column-right').prepend(`<div class="ad-img-show" data-position="${column}-1"></div>`)
872                $('.article_adposition_box #column-right').find('.article_adposition').each(function(n) {
873                    var that = $(this),
874                        position = `${(parseInt(n+1) * 2) + 1}`;
875                    // 判断在多少时重复
876                    if(n > 3) {
877                        position = `${(parseInt(n-4) * 2) + 1}`;
878                        return false;   // return后,会在广告数到10的时候停止新的广告位插入,需要重新计数的话把此行注释。
879                    }
880
881                    // 列表个数,决定加载多少个广告位置
882                    if(l_len >= r_len) {
883                        that.after(`<div class="ad-img-show" data-position="${column}-${position}"></div>`)
884                    }else {
885                        // 右侧多于左侧时,减一个
886                        if(n < r_len - 1) {
887                            that.after(`<div class="ad-img-show" data-position="${column}-${position}"></div>`)
888                        }
889                    }
890                })
891
892                $('.article_adposition_box #column-left').find('.article_adposition').each(function(n) {
893                    var that = $(this),
894                        position = `${(parseInt(n) * 2) + 2}`;
895                    if(n > 4) {
896                        position = `${(parseInt(n-5) * 2) + 2}`;   // 重复时重新计数
897                    }
898
899                    // 右侧列表存在新闻时,否则直接插入一个2的广告位很奇怪
900                    if(r_len > 0 && n < 5) {
901                        that.after(`<div class="ad-img-show" data-position="${column}-${position}"></div>`)
902                    }
903                })
904            }else {
905                $('.article_adposition').each(function(i) {
906                    var that = $(this);
907                    that.attr('data-index', parseInt(i) + 1);
908                    that.after(`<div class="ad-img-show" data-position="${column}-${parseInt(i) + 1}"></div>`)
909                })
910            }
911            AdInsertionFunc(data);
912            firstADshowFunc(column, data)
913        }
914    })
915}
916
917/**
918 * 第一个位置的广告自动加载出来
919 * @param {string} column 位置编号 例 PC-A-L1
920 * @param {Array} data 当前编号下的所有位置数据
921 */
922function firstADshowFunc(column, data) {
923    for(var i in data) {
924        var item = data[i]
925        if(item.tagNo == `${column}-1`) {
926            var that = $(`.ad-img-show[data-position="${column}-1"]`);
927            var $hasOwl = that.find('.owl-carousel'); // 当前图片是否轮播,存在个数就是有
928            if($hasOwl.length > 0) {
929                // 轮播 - 可视的轮播模块执行程序,再判断可见item
930                $hasOwl.find('.owl-item').each(function() {
931                    var $item = $(this);
932                    var imgUrl = $item.find('img').attr('data-url'),
933                        $adJumpClick = $item.find('.ad-jump-click'),
934                        id = $adJumpClick.attr('data-id');
935                    var currentClass = $item.hasClass('active');    // 当前选中的item
936
937                    // 当前轮播下图片所有可见
938                    var img = new Image();
939                    img.src = imgUrl;
940                    img.onload = function() {
941                        $item.find('img').attr('src', imgUrl).removeClass('scale50');
942                        currentClass && $adJumpClick.attr('data-count') == '0' && ADshowCountFunc(id, false, that.data('position') + ' 首图加载')   // 如果当前是 选中 的轮播,则统计次数
943                        // 当下可见item计数
944                        if(currentClass) {
945                            $adJumpClick.attr('data-count', 1);
946                            $item.siblings().find(`.ad-jump-click[data-id="${id}"]`).attr('data-count', 1); // 由于轮播插件的原因,相同ID的也设置为1不被重复统计
947                        }
948                    }
949                })
950            }else {
951                // 单张图片时,正常计数
952                // 为1后不可再被计数
953                // 图片能被加载时再执行相关事件
954                // PS: 和scroll事件下大致相同,区别在$img上对象不同和if条件  470row
955                var $img = that.find('img'),
956                    $adJumpClick = that.find('.ad-jump-click');
957                if($adJumpClick.attr('data-count') == '0') {
958                    $adJumpClick.attr('data-count', 1);
959                    var imgUrl = $img.data('url');
960                    var img = new Image();
961                    img.src = imgUrl;
962                    img.onload = function() {
963                        $img.attr('src', imgUrl).removeClass('scale50');
964                        ADshowCountFunc($adJumpClick.data('id'), false, that.data('position') + ' scroll')
965                    }
966                }
967            }
968        }
969    }
970}
971
972/**
973 * 公用 - 广告插入指定位置,统一所有广告图片插入的元素格式
974 * 文章背景广告除外
975 * @param {Array} data 广告数据
976 * @param {Array} count 计数,解决对联广告左右滑入时,会被重复计数问题
977 */
978function AdInsertionFunc(data, count = 0) {
979    // 遍历所有数据
980    for(var k in data) {
981        var item = data[k];
982        var ads = item.ads || [];
983        var pos = item.tagNo;
984
985        // 图片元素,单图片或是个轮播图,丢进对应的${pos}位置中
986        var imgHtml = '';
987        if(ads.length > 1) {
988            // 轮播
989            var moreHtml = '';
990            for(var j in ads) {
991                var adsItem = ads[j];
992                if(adsItem.adStyle == 1) {
993                    moreHtml += `<div class="ad-jump-click"
994                        data-id="${adsItem.adId}"
995                        data-style="${adsItem.adStyle}"
996                        data-clickContent='${JSON.stringify(adsItem.clickContent)}'
997                        data-count="${count}">
998                        <img
999                            class="scale50"
1000                            data-url="${adsItem.resources ? adsItem.resources[0].url : ''}"
1001                            data-width="${adsItem.resources ? adsItem.resources[0].width : ''}"
1002                            data-height="${adsItem.resources ? adsItem.resources[0].height : ''}"
1003                            src="/img/svgLoading.svg"
1004                            data-keeptime="${adsItem.keepTime}"
1005                            data-intervaltime="${adsItem.intervalTime}"
1006                        />
1007                    </div>`;
1008                    
1009                }else {
1010                    // 第三方是唯一,不可多个
1011                    if (!moreHtml) {
1012                        moreHtml = `<div class="ad-jump-click" data-id="${adsItem.adId}" data-style="${adsItem.adStyle}" data-count="0">
1013                            ${adsItem.codeContent}
1014                        </div>`;
1015                    }
1016                }
1017            }
1018            imgHtml = `<div class="owl-carousel" id="owl-carousel-${pos}" data-ad>
1019                        ${moreHtml}
1020                    </div>`;                    
1021        }else {
1022            // 单张  adStyle: 1自销广告 / 2第三方广告
1023            if(ads[0].adStyle == 1) {
1024                imgHtml = `<div class="ad-jump-click"
1025                        data-id="${ads[0].adId}"
1026                        data-style="${ads[0].adStyle}"
1027                        data-clickContent='${JSON.stringify(ads[0].clickContent)}'
1028                        data-count="${count}">
1029                    <img
1030                        class="scale50"
1031                        data-url="${ads[0].resources[0] ? ads[0].resources[0].url : ''}"
1032                        data-width="${ads[0].resources[0] ? ads[0].resources[0].width : ''}"
1033                        data-height="${ads[0].resources[0] ? ads[0].resources[0].height : ''}"
1034                        src="/img/svgLoading.svg"
1035                        width="100%"
1036                        data-keeptime="${ads[0].keepTime}"
1037                        data-intervaltime="${ads[0].intervalTime}"
1038                    />
1039                </div>`;
1040            }else {
1041                // google代码等
1042                imgHtml = `<div class="ad-jump-click" data-id="${ads[0].adI
1042d}" data-style="${ads[0].adStyle}" data-count="0">
1043                    ${ads[0].codeContent}
1044                </div>`;
1045            }
1046        }
1047
1048        var that = $(`.ad-img-show[data-position="${pos}"]`);
1049        that.append(imgHtml).not('.banner_top_img').css('margin-bottom', '20px');   // 彈窗廣告(.banner_top_img)的不需要下邊距
1050    }
1051
1052    // 给多图添加轮播功能  -  会影响首页新闻轮播图的高度 !!
1053    $('.owl-carousel[data-ad]').each(function(i) {
1054        var id = $(this).attr('id');
1055        var newId = id + '-' + i;
1056        $(this).attr('id', newId);
1057
1058        $(`#${newId}`).owlCarousel({
1059            autoplay: true,
1060            autoplayTimeout: 5000,
1061            autoplayHoverPause: false,
1062            items: 1,
1063            loop: true,
1064            mouseDrag: !isIE(),
1065            margin: 10,
1066            nav: false,
1067        });
1068    })
1069}
1070
1071/**
1072 * 首页广告模块添加
1073 */
1074function indexADpositionFunc(type) {
1075    $(`.home-section[data-adType="${type}"]`).find('.adposition').each(function(i) {
1076        var that = $(this),
1077            num = parseInt(i) + 1,
1078            position, forLen;
1079
1080        // 每组子数量 - 澳闻模块5个一组,其它为3个一组
1081        if(type == '1') {
1082            forLen = 5;
1083        }else {
1084            forLen = 3;
1085        }
1086
1087        // 组个数 - 判断出有几组,新的一组从1开始计数
1088        var x = Math.ceil(num / forLen);
1089        if(x == 1) {
1090            position = `A-M${type}-${num}`
1091        }else {
1092            position = `A-M${type}-${num - (forLen * (x - 1))}`
1093        }
1094
1095        that.after(`<div class="ad-img-show" data-position="${device}-${position}"></div>`)
1096    })
1097}
1098
1099/**
1100 * 公用 - 获取广告内容
1101 * @param {*} type 如果 type=array , 此值是一个数组,元素是广告位的标识码, 如果type=prefix 则tagNo是一个字符串, 代表了某个页面或某个分类的广告位标识的前缀
1102 * @param {Array, string} tagNo 位置编号
1103 * @param {*} success 回调事件
1104 */
1105function getADcontentFunc(type, tagNo, success) {
1106    $Api('bin/v1/getAdContent', {type, tagNo}, function(res) {
1107        success(res);
1108    })
1109}
1110
1111/**
1112 * 公用 - 展示、点击计数统计
1113 * @param {*} id 广告id
1114 * @param {*} type 点击/展示
1115 * @param {*} tagNo 位置编号,可选填。调试作用
1116 */
1117function ADshowCountFunc(id, type, tagNo = '') {
1118    var changeType = type ? 'click' : 'show';
1119    $Api('bin/v1/changeNum', {
1120        changeType,
1121        adIds: [id]
1122    }, function(res) {
1123        var host = window.location.host;
1124        if(host.indexOf('dev') > -1 || host.indexOf('sit') > -1) {
1125            // !type && console.log(`> 展示图片 ${tagNo}:${id}`);
1126            // type && console.log(`> 点击图片 ${tagNo}:${id}`);
1127        }
1128    })
1129}
1130
1131/**
1132 * 弹窗广告的功能JS -B
1133 * B_websiteADFunc(spacingTime, adTimes), B_showDisplayFunc(adTimes), websiteAdCloseFunc(), getClientHeight(), countImg()
1134 */
1135var ad_time,
1136    spacing_time;
1137function B_websiteADFunc(spacingTime, adTimes){
1138    ad_time = parseFloat(adTimes);
1139    spacing_time = parseFloat(spacingTime) + ad_time;
1140
1141    B_showDisplayFunc(ad_time)
1142    if(ad_time > 0) {
1143        var timecount = setInterval(function() {
1144            if(ad_time == 0) {
1145                // console.log('AD关闭了');
1146                clearInterval(timecount);
1147                websiteAdCloseFunc();
1148            }else {
1149                ad_time --
1150                // console.log('ad_time', ad_time);
1151            }
1152            B_showDisplayFunc(ad_time)
1153        }, 1000)
1154
1155        var sp = setInterval(function() {
1156            if(spacing_time == 1) {
1157                clearInterval(sp);
1158                B_websiteADFunc(spacingTime, adTimes);
1159                // console.log('spacing_time return');
1160            }else {
1161                spacing_time --;
1162                // console.log('spacing_time', spacing_time);
1163            }
1164        }, 1000)
1165    }
1166}
1167
1168function B_showDisplayFunc(adTimes){
1169    var obj = $('.dialog_show_ad');
1170    obj.addClass("banner_show");
1171
1172    if (adTimes == 0){
1173        obj.removeClass("banner_show");
1174    }else{
1175        obj.find("font").html(adTimes);
1176    }
1177}
1178
1179// website ad 廣告关闭
1180function websiteAdCloseFunc() {
1181    $('.dialog_show_ad').removeClass("banner_show");
1182    spacing_time = spacing_time - ad_time;
1183    ad_time = 0;    // 不清0,在点击关闭弹窗时会有BUG
1184}
1185
1186// 获取可视窗高度
1187function getClientHeight() {
1188    var clientHeight = 0;
1189    if(document.body.clientHeight&&document.documentElement.clientHeight){
1190        clientHeight = (document.body.clientHeight<document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
1191    }else{
1192        clientHeight = (document.body.clientHeight>document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
1193    }
1194    return clientHeight;
1195}
1196
1197// 弹窗广告的显示图片的大小判断
1198function countImg() {
1199    // 判斷當前彈出廣告大小是否超出屏幕高度
1200    var natImg = $('.banner_top_img').find('img');
1201    var height = 0;
1202    natImg.each(function() {
1203        $(this).load(function() {
1204            if($(this).height() > height) {
1205                height = $(this).height();
1206            }
1207            var b = natImg.width() / height;   // 宽高比
1208            var z = getClientHeight() * b - 110;
1209            if($(window).width() > z) {
1210                $('.banner_top').width(z);
1211            }else {
1212                $('.banner_top').width('85%');
1213            }
1214        })
1215    })
1216
1217}
1218
1219// 拉动屏幕宽度的时候重新计算弹窗广告图片的大小
1220$(window).resize(function() {
1221    if(getClientHeight() < 200) return false;
1222    countImg();
1223})
1224
1225/**
1226 * 滑动广告 -C
1227 * @param {*} spacingTime  廣告出現的間隔時間
1228 * @param {*} adTimes  廣告展示時間
1229 * @param {*} id 
1230 */
1231function C_websiteADFunc(spacingTime, adTimes, id){
1232    // 配置的时间
1233    var spacingTime = parseInt(spacingTime);
1234    var adTimes = parseInt(adTimes);
1235
1236    // 上次保存剩余的时间
1237    var showTime = parseInt($.cookie("C_showTime")) || 0;
1238    var hideTime = parseInt($.cookie("C_hideTime")) || 0;
1239
1240    // 如果显示时间已经为0,重设间隔显示时间的cookie,否则继续计数
1241    if(hideTime > 0 && showTime > 0) {
1242        C_showDisplayFunc(showTime, id); // 继续上次剩余的时间
1243        var totalTime = hideTime + showTime; // 合计时间
1244        setInterval(() => {
1245            if(totalTime == 0) {
1246                totalTime = adTimes + spacingTime; // 重置时间
1247                $.cookie("C_hideTime", totalTime, { expires: 7 }); // cookie记录时间
1248                C_showDisplayFunc(adTimes, id); // 使用新设置的时间
1249            }else {
1250                totalTime --;
1251                $.cookie("C_hideTime", totalTime, { expires: 7 });
1252            }
1253        }, 1000);
1254    }else if(hideTime > 0 && showTime == 0) {
1255        setInterval(() => {
1256            if(hideTime == 0) {
1257                hideTime = adTimes + spacingTime;
1258                $.cookie("C_hideTime", hideTime, { expires: 7 });
1259                C_showDisplayFunc(adTimes, id);
1260            }else {
1261                hideTime --;
1262                $.cookie("C_hideTime", hideTime, { expires: 7 });
1263            }
1264        }, 1000);
1265    }else{
1266        // 完全初始,第一次出现上滑广告的用户执行以下
1267        // 显示时间已经清0后,使用新的时间进行计数
1268        C_showDisplayFunc(adTimes, id)
1269        var totalTime = adTimes + spacingTime;
1270        setInterval(() => {
1271            if(totalTime == 0) {
1272                totalTime = adTimes + spacingTime;
1273                $.cookie("C_hideTime", totalTime, { expires: 7 });
1274                C_showDisplayFunc(adTimes, id);
1275            }else {
1276                totalTime --;
1277                $.cookie("C_hideTime", totalTime, { expires: 7 });
1278            }
1279        }, 1000);
1280    }
1281
1282}
1283// 上滑广告显示时间计时
1284var C_showCount = true;
1285function C_showDisplayFunc(adTimes, id){
1286    var obj = $('.c_website_banner');
1287    var objWidth = parseInt(obj.find('img').data('width')),
1288        objHeight = obj.find('img').data('height')
1289    var height = obj.find('.ad-jump-click').width() * objHeight / objWidth
1290    height = height.toFixed(0)
1291
1292    if ($('#header-menu-column-item-root').hasClass('header-menu-item-link-active')) $('#header-menu-column-sub').css({'top':'calc(100% + '+ height +'px)', 'transition':'all 0.6s ease'});
1293    obj.find('.banner').height(height);
1294    obj.find('font').html(adTimes);
1295
1296    // 展示次数统计
1297    if(C_showCount) {
1298        ADshowCountFunc(id, false, `上滑AD`);
1299        C_showCount = false; // 页面刷新后,只会执行一次展示统计
1300    }
1301
1302    var C_showADTime = setInterval(function(){
1303        adTimes --;
1304        obj.find("font").html(adTimes);
1305        if (adTimes == 0){
1306            clearInterval(C_showADTime);
1307            if ($('#header-menu-column-item-root').hasClass("header-menu-item-link-active")) $('#header-menu-column-sub').css("top","calc(100%)");
1308            obj.find('.banner').height(0);
1309            $.cookie("C_showTime", 0, { expires: 7 });
1310        }else{
1311            $.cookie("C_showTime", adTimes, { expires: 7 });
1312        }
1313    }, 1000);
1314}
1315
1316/**
1317 * 公共 - 对联广告 -E
1318 * @param {*} t 
1319 * @param {*} col 
1320 */
1321function coupletADpositionFunc(t, col) {
1322    var column = device + '-E-' + t + col;
1323    getADcontentFunc('prefix', column + '-', function(res) {
1324        if(res.code == 0) {
1325            var data = res.data;
1326            var mol;    // 区分左右两侧显示,还是左右滑入显示
1327            if(screenWidth > 1815) {
1328                mol = 1
1329                // 左右两侧显示
1330                var left_html = `<div class="couplet-ad couplet-left ad-img-show" data-position="${column}-1"></div>`
1331                var right_html = `<div class="couplet-ad couplet-right ad-img-show" data-position="${column}-2"></div>`
1332                $('#inner-container').prepend(left_html, right_html);
1333
1334                var coupletStyle = `<style>
1335                    .couplet-ad {position: fixed; left: 50%; top: 214px; z-index: 1999; width: 300px; height: auto;}
1336                    .couplet-left {margin-left: -${$('.container').width() / 2 + 320}px;}
1337                    .couplet-right {margin-left: ${$('.container').width() / 2 + 20}px;}
1338                </style>`
1339                $('body').append(coupletStyle)
1340                AdInsertionFunc(data);
1341            }else {
1342                mol = 2
1343                // 左右滑动进入
1344                var left_html = `<div class="couplet-ad couplet-left">
1345                    <div class="ad-img-show" data-position="${column}-1"></div>
1346                </div>`
1347                var right_html = `<div class="couplet-ad couplet-right">
1348                    <div class="ad-img-show" data-position="${column}-2"></div>
1349                </div>`
1350                $('#inner-container').prepend(left_html, right_html);
1351
1352                var coupletStyle = `<style>
1353                    .couplet-ad {position: fixed; top: 0; z-index: 2000; width: 100%; height: 100%; background: rgba(0,0,0,.5)}
1354                    .couplet-ad .ad-img-show {position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);}
1355                    .couplet-left {left: -100%; transition: all 0.5s}
1356                    .couplet-left.on {left: 0;}
1357
1358                    .couplet-right {right: -100%; transition: all 0.5s}
1359                    .couplet-right.on {right: 0;}
1360                </style>`
1361                $('body').append(coupletStyle)
1362                AdInsertionFunc(data, 1);
1363            }
1364            
1365            // 遍历获取它们的图片显示时间和间隔时间 PS:间隔时间没用上
1366            var keepTime_1 = $(`.couplet-left img`).data('keeptime') || 0,
1367                intervalTime_1 = $(`.couplet-left img`).data('intervaltime') || 0,
1368                keepTime_2 = $(`.couplet-right img`).data('keeptime') || 0,
1369                intervalTime_2 = $(`.couplet-right img`).data('intervaltime') || 0;
1370            console.log('keepTime_1/2', keepTime_1, keepTime_2);
1371                
1372            $('.couplet-ad').each(function(i) {
1373                var $img = $(this).find('img'),
1374                    url = $img.attr('data-url'),
1375                    id = $img.parent('.ad-jump-click').attr('data-id');
1376                
1377                // 当页面可直接展示对联广告不需要弹出显示时,直接展示并计数
1378                if(mol == 1 && url) {
1379                    var img = new Image();
1380                    img.src = url;
1381                    
1382                    img.onload = function() {
1383                        $img.attr('src', url).removeClass('scale50');
1384                        $img.parent('.ad-jump-click').attr('data-count', '1');
1385                        // 展示后统计次数
1386                        ADshowCountFunc(id, false, $img.parents('.ad-img-show').data('position') + ' 对联AD')
1387                    }
1388                }
1389
1390                // if(i == 0) {
1391                //     // left
1392                //     keepTime_1 = $img.attr('data-keeptime');
1393                //     intervalTime_1 = $img.attr('data-intervaltime');
1394                // }else {
1395                //     // right
1396                //     keepTime_2 = $img.attr('data-keeptime');
1397                //     intervalTime_2 = $img.attr('data-intervaltime');
1398                // }
1399            })
1400            console.log('mol', mol);
1401            if(mol == 2) {
1402                var hasLeftImg = $(`.couplet-ad .ad-img-show[data-position="${column}-1"]`).find('img').length > 0 ? true : false,
1403                    hasRightImg = $(`.couplet-ad .ad-img-show[data-position="${column}-2"]`).find('img').length > 0 ? true : false;
1404                
1405                if(hasLeftImg) {
1406                    console.log('hasLeftImg');
1407                    img_1 = new Image();
1408                    img_1.src = $('.couplet-left img').attr('data-url');
1409                    img_1.onload = function() {
1410                        $('.couplet-left img').attr('src', img_1.src).removeClass('scale50');
1411                        $('.couplet-left').addClass('on');
1412                        ADshowCountFunc($('.couplet-left .ad-jump-click').attr('data-id'), false, $('.couplet-left .ad-img-show').data('position') + ' 对联AD');
1413                        setTimeout(() => {
1414                            $('.couplet-left').removeClass('on');
1415                        }, keepTime_1);
1416                    }
1417                }
1418                if(hasRightImg) {
1419                    console.log('hasRightImg');
1420                    // 右边对联滑动出来时需要先判断左边是否存在广告,进行延迟展示
1421                    img_2 = new Image();
1422                    img_2.src = $('.couplet-right img').attr('data-url');
1423                    img_2.onload = function() {
1424                        $('.couplet-right img').attr('src', img_2.src).removeClass('scale50');
1425                        // 如果1位置有图片延迟执行,反之直接执行
1426                        setTimeout(() => {
1427                            $('.couplet-left').removeClass('on');
1428                            $('.couplet-right').addClass('on');
1429                            ADshowCountFunc($('.couplet-right .ad-jump-click').attr('data-id'), false, $('.couplet-right .ad-img-show').data('position') + ' 对联AD');
1430                            setTimeout(() => {
1431                                $('.couplet-right').removeClass('on');
1432                            }, keepTime_2);
1433                        }, keepTime_1);                        
1434                    }
1435                }
1436            }
1437            
1438            // todo 这里有BUG,没有考虑到可能只有两个位置并不会同时有数据 在导致页面请求undefined地址 201127
1439            // if(mol == 2) {
1440            //     // 获取左侧的是否加载完
1441            //     var img_1 = new Image();
1442            //     img_1.src = $('.couplet-left img').attr('data-url');
1443                
1444            //     $('.couplet-left img').parent('.ad-img-show').attr('data-count', '1');
1445            //     $('.couplet-right img').parent('.ad-img-show').attr('data-count', '1');
1446            //     img_1.onload = function() {
1447            //         $('.couplet-left img').attr('src', img_1.src).removeClass('scale50');
1448
1449            //         // 临时处理了 有1没有2位置的场景 line1156同问题
1450            //         if (!$('.couplet-right img').attr('data-url')) {
1451            //             console.log(1);
1452            //             $('.couplet-left').addClass('on');
1453            //             setTimeout(() => {
1454            //                 $('.couplet-right').removeClass('on');
1455            //             }, keepTime_1);
1456            //         }else {
1457            //             console.log(2);
1458            //             // 右边的图片也加载完毕
1459            //             var img_2 = new Image();
1460            //             img_2.src = $('.couplet-right img').attr('data-url');
1461            //             console.log('img_2.src', img_2.src);
1462            //             img_2.onload = function() {
1463            //                 $('.couplet-right img').attr('src', img_2.src).removeClass('scale50');
1464            //                 $('.couplet-left').addClass('on');
1465            //                 ADshowCountFunc($('.couplet-left .ad-jump-click').attr('data-id'), false, $('.couplet-left .ad-img-show').data('position') + ' 对联AD');
1466            //                 setTimeout(() => {
1467            //                     $('.couplet-left').removeClass('on');
1468            //                     $('.couplet-right').addClass('on');
1469            //                     ADshowCountFunc($('.couplet-right .ad-jump-click').attr('data-id'), false, $('.couplet-right .ad-img-show').data('position') + ' 对联AD');
1470            //                     setTimeout(() => {
1471            //                         $('.couplet-right').removeClass('on');
1472            //                     }, keepTime_2);
1473            //                 }, keepTime_1);
1474            //             }
1475            //         }
1476            //     }
1477            // }
1478        }
1479    })
1480}
1481
1482/**
1483 * 公共 - 内容页背景广告/文章内容底部广告 -D
1484 */
1485function contentADpositionFunc() {
1486    var articleType = $('.articleContent').data('type');
1487    if(!articleType) return;  // 不存在时停止执行
1488
1489    var column = articleColumnFunc(device2, 'A');
1490
1491    // 文章页面兼容处理
1492    // 兼容各別頁面,在P標籤外存在其他標籤,會導致無法正確獲取位置
1493    var $strong = $('.article-content>strong');
1494    if($strong.length > 0) {
1495        // 防止有多個strong在不同位置
1496        $strong.each(function() {
1497            var $strong_p = $(this).children('p');
1498            $strong_p.css('font-weight', '600');
1499            $(this).after($strong_p);   // 將裏面的內容移到其後
1500            $(this).remove();   // 移動後刪除這個空的
1501        })
1502    }
1503    var $em = $('.article-content>em');
1504    if($em.length > 0) {
1505        // 防止有多個em在不同位置
1506        $em.each(function() {
1507            var $em_p = $(this).children('p');
1508            $em_p.css('font-style', 'italic');
1509            $(this).after($em_p);   // 將裏面的內容移到其後
1510            $(this).remove();   // 移動後刪除這個空的
1511        })
1512    }
1513    var $del = $('.article-content>del');
1514    if($del.length > 0) {
1515        // 防止有多個del在不同位置
1516        $del.each(function() {
1517            var $del_p = $(this).children('p');
1518            $del_p.css('text-decoration', 'line-through');
1519            $(this).after($del_p);   // 將裏面的內容移到其後
1520            $(this).remove();   // 移動後刪除這個空的
1521        })
1522    }
1523    
1524    // 后台用模糊搜索,当前是d1内容,刚好d11有数据,会把那个也搜出来所以要加个'-'截住它
1525    getADcontentFunc('prefix', column + '-', function(res) {
1526        if(res.code == 0) {
1527            var data = res.data;
1528
1529            // 自定义新的广告填充位置,替换AdInsertionFunc(data) 
1530            var hasBackgroundAD = false;
1531            var imgUrl = '',
1532                clickContent = '',
1533                id = '',
1534                adStyle = '';
1535            for(var k in data) {
1536                var item = data[k];
1537                // 固定背景广告
1538                if(item.tagNo == column + '-1') {
1539                    imgUrl = item.ads[0].resources[0].url;
1540                    clickContent = JSON.stringify(item.ads[0].clickContent);
1541                    id = item.ads[0].adId;
1542                    adStyle = item.ads[0].adStyle;
1543                    hasBackgroundAD = true;
1544                }
1545                // 文章内容底部广告
1546                if(item.tagNo == column + '-2') {
1547                    var articleBottomAD = `<div class="ad-img-show" data-position="${column + '-2'}"></div>`
1548                    $('.article-content').append(articleBottomAD)
1549                    AdInsertionFunc([item]);
1550                }
1551            }
1552            
1553            // 存在文章背景广告数据才执行
1554            if(hasBackgroundAD) {
1555                // 广告位置插入  这里的data-position实际作用只是参考位置
1556                var agent = navigator.userAgent;
1557                if(screenWidth > 480) {
1558                    if(agent.indexOf('WOW64') > -1) {
1559                        // 电脑版微信打开时
1560                        var newWidth = $('.article-content').width(),
1561                            mLeft = $('.article-content').offset().left;
1562                        var newsHTML = `<div class="newsAD">
1563                                <div class="ad_tips_top"><span>[贊助] 內文未完請向下滾動</span></div>
1564                                <div class="newsAD_clip"
1565                                    onclick='adJumpClickFunc(${id}, ${clickContent}, ${adStyle})'
1566                                    data-count="0"
1567                                    style="background: url(${imgUrl}) no-repeat ${mLeft}px center; background-size: ${newWidth}px auto; background-attachment:fixed;"
1568                                    data-position="${column}-1"
1569                                ></div>
1570                                <div class="ad_tips_bottom"></div>
1571                            </div>`;
1572                        $(window).resize(function() {
1573                            newWidth = $('.article-content').width();
1574                            mLeft = $('.article-content').offset().left;
1575                            $('.newsAD_clip').css({'background-position': mLeft + 'px center', 'background-size': newWidth + 'px auto'});
1576                        })
1577                    }else {
1578                        var newsHTML = `<div class="newsAD">
1579                                <div class="ad_tips_top"><span>[贊助] 內文未完請向下滾動</span></div>
1580                                <div class="newsAD_clip">
1581                                    <div class="newsAD_box">
1582                                        <div class="newsAD_main" onclick='adJumpClickFunc(${id}, ${clickContent}, ${adStyle})' data-count="0">
1583                                            <a data-position="${column}-1">
1584                                                <img class="PCshow" src="${imgUrl}" data-position="${column}-1">
1585                                            </a>
1586                                        </div>
1587                                    </div>
1588                                </div>
1589                                <div class="ad_tips_bottom"></div>
1590                            </div>`;
1591                    }
1592                }else {
1593                    var newsHTML = `<div class="newsAD">
1594                                        <div class="ad_tips_top"><span>[贊助] 內文未完請向下滾動</span></div>
1595                                        <a onclick='adJumpClickFunc(${id}, ${clickContent}, ${adStyle})' data-count="0"></a>
1596                                        <div class="ad_tips_bottom"></div>
1597                                    </div>`;
1598                    var imgAD = `<img class="imgAD" src="${imgUrl}" data-position="${column}-1">`
1599                }
1600
1601                // 判断文章是否超过3行
1602                var $p = $('.article-content > *');
1603                $('#article-img-set img, .article-content img').addClass('news-img');
1604                $('.news-img').error(function () {   //加载图片 出现404状态时触发
1605                    $(this).attr("src", "/img/noImg.png");  //将加载不到的图片 的src属性 修改成默认 图片 ,注意:默认图片必须保证存在,否则 会一直 调用 此函数
1606                });
1607                if($p.length >= 3){
1608                    // PC显示下的广告图插入位置
1609                    if(screenWidth > 480) {
1610
1611                        // 判断图片加载的函数
1612                        var mulitImg = [],
1613                            img = [];
1614                        $('.news-img').each(function (i) {
1615                            mulitImg[i] = $(this).attr('src');
1616                        });
1617
1618                        $p.each(function() {
1619                            var that = $(this);
1620                            if(that.html() == '') {
1621                                that.remove();
1621  // 文章最后会有一个空白的p标签,不清除会影响插入位置
1622                            }
1623                        })
1624                        $.each(mulitImg,function(i){
1625                            img[i] = new Image();
1626                            img[i].src = mulitImg[i];
1627                            img[i].onload = function() {
1628                                if(i == mulitImg.length-1) {
1629                                    setTimeout(() => {
1630                                        $p.each(function(i) {
1631                                            var that = $(this);
1632                                            var top = that.offset().top;
1633                                            var stopEach = false;
1634                                            // 当前的P必须高于屏幕高度 且 要在大于2个P时插入
1635                                            if(top > document.documentElement.clientHeight && i >= 2) {
1636                                                stopEach = true;
1637                                                if(that.find('img').length > 0){
1638                                                    if(i == $('.article-content p').length - 1) {
1639                                                        that.after(newsHTML);   // 已是最后一个p时还包含图片,不需要延后再插入了
1640                                                        // console.log('已是最后一个p时还包含图片,不需要延后再插入了');
1641                                                    }else {
1642                                                        that.next().after(newsHTML);
1643                                                        // console.log('延后一个P插入广告');
1644                                                    }
1645                                                }else{
1646                                                    that.after(newsHTML);
1647                                                }
1648                                                return false;
1649                                            }
1650                                            if(stopEach) return false;
1651                                        })
1652                                        // 结束循环时未有插入的,直接插入最后一个p
1653                                        if($('.newsAD').length == 0) {
1654                                            $p.eq(-1).after(newsHTML);
1655                                        }
1656                                    }, 500);
1657                                }
1658                            }
1659                        })
1660
1661                    }else {
1662                        // mobile
1663                        if($p.eq(2).find('img').length>0){
1664                            if($p.length==3){
1665                                $p.eq(-1).after(newsHTML);
1666                            }else{
1667                                $p.eq(3).after(newsHTML);
1668                            }
1669                        }else{
1670                            $p.eq(2).after(newsHTML);
1671                        }
1672                            
1673                        if($('.newsAD').length > 0) {
1674                            $('#inner-container').append(imgAD);    // 圖片
1675                            $('#article-container .gutter-20 .col-sm-8').prepend('<div class="section_bgf"></div>')
1676                            $('.article-sub-title, .article-main-title, .article-action').appendTo($('.section_bgf'));
1677
1678                            $('.article-content > *:not(".newsAD")').css('background', '#f1f1f1');
1679                            $('.article-content p, .article-content h1, .article-content h2, .article-content h3, .article-content h4, .article-content h5').css({'margin': '0','padding-bottom': '10px'});
1680                            // 得注釋吧,文章編輯時可能會出現沒有標籤的段落,沒辦法集中放在一個元素中 210225
1681                            // var index = $('.newsAD').index();
1682                            // $('.article-content').prepend('<div class="part1"></div>');
1683                            // $p.eq(index).after('<div class="part2"></div>');
1684
1685                            // $p.each(function(i) {
1686                            //     if(i < index) {
1687                            //         $(this).appendTo($('.part1'));
1688                            //     }else {
1689                            //         $(this).appendTo($('.part2'));
1690                            //     }
1691                            // })
1692                            articleBgSet()
1693                        }
1694                    }
1695                }else{
1696                    $p.eq(-1).after(newsHTML);
1697                    if(screenWidth <= 480) {
1698                        // 当页面没有超过3个P,且又是手机时,需要插入广告图片
1699                        $('#inner-container').append(imgAD);    // 圖片
1700                        $('#article-container .gutter-20 .col-sm-8').prepend('<div class="section_bgf"></div>')
1701                        $('.article-sub-title, .article-main-title, .article-action').appendTo($('.section_bgf'));
1702
1703                        $('#article-container p').css('background', '#f1f1f1');
1704                        // 得注釋吧,文章編輯時可能會出現沒有標籤的段落,沒辦法集中放在一個元素中 210225
1705                        // var index = $('.newsAD').index();
1706                        // $('.article-content').prepend('<div class="part1"></div>');
1707                        // $p.eq(index).after('<div class="part2"></div>');
1708                        // $p.each(function(i) {
1709                        //     if(i < index) {
1710                        //         $(this).appendTo($('.part1'));
1711                        //     }else {
1712                        //         $(this).appendTo($('.part2'));
1713                        //     }
1714                        // })
1715                        articleBgSet
1716                    }
1717                }
1718
1719                // 給廣告位上下兩個段落內容添加底色,解決部分沒有標籤文字無底色問題
1720                function articleBgSet() {
1721                    var $ad = $('.newsAD')
1722                    if($ad.length > 0) {
1723                        var top = $ad.position().top,
1724                            bottom = top + $ad.height(),
1725                            articleHeight = $('.article-content').height() - bottom;
1726                        $('.article-content').append('<div class="part1"></div><div class="part2"></div>');
1727                        $('.part1').height(top);
1728                        $('.part2').css({'top': bottom, 'height': articleHeight})
1729                    }
1730                }
1731
1732                var showOne = true
1733                $(window).scroll(function() {
1734                    if($('.newsAD').length > 0) {
1735                        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop,
1736                            height = document.documentElement.clientHeight;
1737                        // console.log(scrollTop, height, $('.newsAD').offset().top);
1738                        var newsAdHeight = $('.newsAD').height() || 0;
1739                        var newsADTop_offset = $('.newsAD').offset().top || 0;
1740                        
1741                        if(screenWidth > 480) {
1742                            if(scrollTop > newsADTop_offset-500) {
1743                                if(showOne) ADshowCountFunc(id);
1744                                showOne = false;
1745                            }
1746                        }else {
1747                            var adTop = $('.imgAD').length > 0 ? $('.imgAD').offset().top : 0;
1748                            if(scrollTop > newsADTop_offset - height && adTop-newsAdHeight < newsADTop_offset) {
1749                                $('.imgAD').css('opacity', '1');
1750                            }else {
1751                                $('.imgAD').css('opacity', '0');
1752                            }
1753                            // 看到大半张图片时才算被展示,统计才计数
1754                            if(scrollTop > newsADTop_offset-200) {
1755                                if(showOne) ADshowCountFunc(id);
1756                                showOne = false;
1757                            }
1758                
1759                            if($('.fix_icon_url').length > 0) {
1760                                var fixTop = $('.fix_icon_url').offset().top;
1761                                var fixPosTop = $('.fix_icon_url').position().top;
1762                                if(fixTop+62 > newsADTop_offset && fixTop < newsADTop_offset+newsAdHeight) {
1763                                    $('.fix_icon_url a').hide();
1764                                }else {
1765                                    $('.fix_icon_url a').show();
1766                                }
1767                            }
1768                        }
1769                        
1770                    }
1771                })
1772
1773                $(window).resize(function() {
1774                    if(screenWidth > 767) {
1775                        $('.articleContent').next('.imgAD').hide();
1776                    }else {
1777                        $('.articleContent').next('.imgAD').show();
1778                    }
1779                })
1780            }
1781        }
1782    })
1783}
1784
1785/**
1786 * 公共 - 获取当前文章详情页的广告位置
1787 * PS: 内容背景广告用的是device2,规则和其它不同
1788 */
1789function articleColumnFunc(device, type) {
1790    var col = '-', // 默認啥也不要
1791        articleType = $('.articleContent').data('type'),
1792        articleColumn = $('.articleContent').data('column');
1793    
1794    if(articleType == 'article') {
1795        // 今日力报
1796        if(articleColumn == 'macau') col = 2
1797        if(articleColumn == 'world') col = 3
1798        if(articleColumn == 'china') col = 4
1799        if(articleColumn == 'business') col = 5
1800        if(articleColumn == 'sports') col = 6
1801        if(articleColumn == 'leisure') col = 7
1802        if(articleColumn == 'investment') col = 8
1803    }else if(articleType == 'supplement') {
1804        // 生活
1805        if(articleColumn == '9') col = 10   // 游澳假期
1806        if(articleColumn == '2') col = 11   // 饮食
1807        if(articleColumn == '5') col = 12   // 汽车
1808        if(articleColumn == '3') col = 13   // 旅游
1809        if(articleColumn == '7') col = 14   // 消费
1810        if(articleColumn == '8') col = 15   // 专栏
1811    }else if(articleType == 'hotarticle') {
1812    	col = 1
1813    }
1814    return `${device}-${type}-D${col}`
1815}
1816
1817/**
1818 * 文章详情页 - 文章底部悬浮广告 -F
1819 */
1820function articleBottomADFunc(){
1821    var column = articleColumnFunc(device, 'F') + '-1';
1822    getADcontentFunc('prefix', column, function(res) {
1823        if(res.code == 0) {
1824            var data = res.data;
1825            var newsHTML = `<div class="bottomAD">
1826                <div class="bottomAD_box">
1827                    <div class="img_box">
1828                        <a class="ad-img-show" data-position="${column}"></a>
1829                        <div class="close_AD" onclick="$('.bottomAD').remove();"></div>
1830                    </div>
1831                </div>
1832            </div>`;
1833            $('body').append(newsHTML);
1834            AdInsertionFunc(data)
1835            var $img = $('.bottomAD').find('img'),
1836                url = $img.data('url')
1837            var img = new Image();
1838            img.src = url;
1839            img.onload = function() {
1840                $img.attr('src', url).attr('data-count', '1').removeClass('scale50');
1841                // 展示后统计次数
1842                ADshowCountFunc($img.data('id'))
1843            }
1844        }
1845    })
1846}
1847
1848/**
1849 * 文章详情页 - 组合广告 -D
1850 */
1851function comeboADFunc() {
1852    var column = articleColumnFunc(device3, 'D') + '-1';
1853    getADcontentFunc('prefix', column, function(res) {
1854        if(res.code == 0) {
1855            var data = res.data;
1856            var adsItem = data[0].ads[0];
1857            
1858            var maxImg, minImg
1859            // 等於2為組合廣告,等於1為懸浮廣告
1860            if(adsItem.resources.length == 2) {
1861                if(adsItem.resources[1].height > adsItem.resources[0].height) {
1862                    maxImg = adsItem.resources[1].url
1863                    minImg = adsItem.resources[0].url
1864                }else {
1865                    maxImg = adsItem.resources[0].url
1866                    minImg = adsItem.resources[1].url
1867                }
1868            }else {
1869                // maxImg = ''0
1870                // minImg = adsItem.resources[0].url
1871                
1872                // 单张的话执行悬浮的广告方案 articleBottomADFunc()方法已废弃,组合和悬浮功能合并
1873                // ps: 需求不要关闭按钮
1874                var newsHTML = `<div class="bottomAD">
1875                    <div class="bottomAD_box">
1876                        <div class="img_box">
1877                            <a class="ad-img-show" data-position="${column}"></a>
1878                            <div class="close_AD hide" onclick="$('.bottomAD').remove();"></div>
1879                        </div>
1880                    </div>
1881                </div>`;
1882                $('body').append(newsHTML);
1883                AdInsertionFunc(data)
1884                try {
1885                    var thatImg = data[0].ads[0].resources[0]
1886                    var imgWidth = thatImg.width,
1887                        imgHeight = thatImg.height
1888                    var setHeight = imgHeight * $('body').width() / imgWidth
1889                    setHeight = setHeight.toFixed(0)
1890                    $('.img_box .ad-img-show').height(setHeight);
1891                }catch(e) {
1892                    $('.bottomAD').remove();
1893                    console.log('> error 底部悬浮data数据有误');
1894                    return
1895                }
1896
1897                var $img = $('.bottomAD').find('img'),
1898                    url = $img.data('url')
1899                var img = new Image();
1900                img.src = url;
1901                img.onload = function() {
1902                    $img.parents('.ad-jump-click').attr('data-count', '1');
1903                    $img.attr('src', url).removeClass('scale50');
1904                    // 展示后统计次数
1905                    ADshowCountFunc($img.parents('.ad-jump-click').data('id'), false, '悬浮AD')
1906                }
1907                return
1908            }
1909
1910            var comboADImg = maxImg,
1911                comboADBottomImg = minImg,
1912                keepTime = adsItem.keepTime / 1000
1913                intervalTime = adsItem.intervalTime / 1000,
1914                id = adsItem.adId,
1915                clickContent = JSON.stringify(adsItem.clickContent),
1916                style = adsItem.adStyle;
1917
1918            var comboADHtml = `
1919                <div class="comboAD-box">
1920                    <div class="comboAD-img">
1921                        <img src="${comboADImg}" onclick='adJumpClickFunc(${id}, ${clickContent}, ${style})' />
1922                    </div>
1923                </div>
1924                <div class="comboAD-bottom">
1925                    <div class="comboAD-bottom-img">
1926                        <img src="${comboADBottomImg}" onclick='adJumpClickFunc(${id}, ${clickContent}, ${style})' />
1927                        <div class="comboAD-btn comboAD-close ${!comboADImg && 'hide'}"></div>
1928                        <div class="comboAD-btn comboAD-open ${!comboADImg && 'hide'}"></div>
1929                    </div>
1930                </div>
1931            `;
1932            $('body').append(comboADHtml);
1933            ADshowCountFunc(id);
1934
1935            var firstShow = true
1936            $(window).scroll(function() {
1937                var sTop = 0;
1938                if (document.documentElement && document.documentElement.scrollTop) {
1939                    sTop = document.documentElement.scrollTop;
1940                }else if (document.body) {
1941                    sTop = document.body.scrollTop;
1942                }
1943                if(sTop > 300 && firstShow) {
1944                    firstShow = false
1945                    // 当前cookie中保留上次剩余时间时,很用完再显示
1946                    // 解决上次剩余几秒时,这次进来刚显示完后又突然读完上次时间再次显示,会显示很快
1947                    if(!!getCookie('comboADTime') && getCookie('comboADTime') != intervalTime) { 
1948                        var sec = parseInt(getCookie('comboADTime'));          
1949                        var secTime = setInterval(() => {
1950                            sec --;
1951                            if(sec <= 0) clearInterval(secTime);
1952                            console.log(`剩余${sec}s加载组合广告`);
1953                        }, 1000);
1954                        setTimeout(() => {
1955                            showADfunc();
1956                            setCookie('comboADTime', intervalTime);
1957                        }, getCookie('comboADTime')*1000);
1958                    }else {
1959                        showADfunc();
1960                    }
1961                }
1962            })
1963        
1964            var img1 = false,
1965                img2 = false,
1966                t = true;
1967            var returnTime,
1968                timeout;
1969        
1970            $('.comboAD-img img').load(function() {
1971                img1 = true
1972            })
1973            $('.comboAD-bottom-img img').load(function() {
1974                img2 = true
1975            })
1976        
1977            // 展示大圖
1978            function showADfunc() {
1979                // 每秒時間,獲取兩張AD是否加載完成
1980                var time = setInterval(() => {
1981                    if(img1 && img2 && t) {
1982                        t = false;
1983                        $('.comboAD-box').fadeIn(100);
1984                        $('.comboAD-bottom').fadeOut();
1985                        $('#footer').css('margin-bottom', 0);
1986                        ADShowPosition();   // 重置其顯示位置
1987                        clearInterval(time);    // 正常顯示後,可清除當前的計時器
1988                        var showTime = setTimeout(() => {
1989                            t = true;
1990                            $('.comboAD-box').fadeOut();
1991                            $('.comboAD-bottom').fadeIn();
1992                            $('#footer').css('margin-bottom', $('.comboAD-bottom').height());
1993                            returnShowADfunc();
1994        
1995                            var imgHeight = $('.comboAD-bottom-img').height();
1996                            $('#footer.margin100').css('margin-bottom', imgHeight);
1997                            $('#back-to-top').css('bottom', imgHeight + 30);  // 置顶按钮位置上移
1998        
1999                            clearTimeout(showTime);
2000                        }, keepTime*1000);
2001                    }
2002                }, 1000);
2003            }
2004            
2005            // AD position 
2006            function ADShowPosition() {
2007                if(screenWidth > 640) {
2008                    var top = $('#header').height() + 100
2009                    // css top有个需求,需要不能挡住栏目
2010                    $('.comboAD-box').css({'top': $('#header').height(), 'height': getClientHeight()-top});
2011                }else {
2012                    $('.comboAD-box').css({'top': '50%', 'transform': 'translateY(-50%)'});
2013                }
2014            }
2015        
2016            // 間隔時間
2017            function returnShowADfunc() {
2018                var comboTime = intervalTime; // 初始
2019                // 當cookie中存在時間則取來使用
2020                if(!!getCookie('comboADTime')) {
2021                    comboTime = getCookie('comboADTime');
2022                }
2023                clearInterval(returnTime);  // 調用前先清除上一次的計時
2024                returnTime = setInterval(() => {
2025                    comboTime --;
2026                    setCookie('comboADTime', comboTime);
2027                    // console.log('即将显示组合广告', comboTime + 's');
2028                    
2029                    if(comboTime <= 0) {
2030                        setCookie('comboADTime', intervalTime);  // 當0s後重新賦值最新的時間
2031                        clearInterval(returnTime);
2032                    }
2033                }, 1000);
2034                // timeout = setTimeout(() => {
2035                //     // showADfunc()  不需要重新放大 001
2036                // }, comboTime*1000);
2037            }
2038            
2039            // 改變屏幕時重新計算展示圖大小
2040            $(window).resize(function() {
2041                ADShowPosition();
2042        
2043                // if(screenWidth > 640) {
2044                //     var comboADImg = newsAD_IMG,
2045                //         comboADBottomImg = newsAD_Resizable_IMG;
2046                // }else {
2047                //     var comboADImg = newsAD_IMG_Mb,
2048                //     comboADBottomImg = newsAD_Resizable_IMG_Mb;
2049                // }
2050                
2051                var imgHeight = $('.comboAD-bottom-img').height();
2052                $('#footer').css('margin-bottom', imgHeight);
2053            })
2054        
2055            // close AD
2056            $('.comboAD-close').on('click', function() {
2057                $('.comboAD-bottom').hide();
2058                $('#footer').css('margin-bottom', '0');
2059            })
2060        
2061            // open AD
2062            $('.comboAD-open').on('click', function() {
2063                setCookie('comboADTime', intervalTime);  // 展開AD後重新計算其間距時間
2064        
2065                $('.comboAD-box').fadeIn(100);
2066                $('.comboAD-bottom').fadeOut();
2067                $('#footer').css('margin-bottom', '0');
2068                ADShowPosition();   // 重置其顯示位置
2069                var openTime = setTimeout(() => {
2070                    $('.comboAD-box').fadeOut();
2071                    $('.comboAD-bottom').fadeIn();
2072                    $('#footer').css('margin-bottom', $('.comboAD-bottom').height());
2073                    returnShowADfunc();
2074                    clearTimeout(openTime);
2075                }, keepTime*1000);
2076            })
2077
2078        }
2079    })
2080}

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.