= 0) { in_table = true; } // 如果包含以下標籤、段落內文不夠長(計算中文20個字)、是最後一個段落,則不插入廣告(為了避免與IR2相連)跳過此段落 if (in_table || news.indexOf('= 0 || news.indexOf('= 0 || news.indexOf('= 0 || news.indexOf('= 0 || news.indexOf('= 0 || news.indexOf('<↓') >= 0 || stripTags(news).trim().length < 20 || (index + 1) >= (paragraphs.length - 1)) { return; } // 如果不在指定的段落則不插入廣告 fit_count++; // 適合的位置數+1 if (fit_count != $position) { return; } // 在適合的段落後方插入廣告 // 廣告前加入「請繼續往下閱讀...」 news += ''; news += '請繼續往下閱讀...'; // 插入廣告 news += $ad; // 廣告後墊檔區塊 news += ''); return article; } // 格式化內文 function stripTags(input, allowed) { allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase () let tags = /?([a-z][a-z0-9]*)b[^>]*>/gi, commentsAndPhpTags = /|(?:php)?[sS]*??>/gi; return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1) { return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''; }); } // 打大數據 function hitBigData(data) { let domain = location.hostname; //ent.ltn.com.tw let type = "ent"; let a_group = data['A_Group']; let a_no = data['A_No']; getScrNews(domain, type, a_group, a_no); } function appendContent(data) { let news = data['A_Html']; article.find('h2').text(data['LTNA_Title']); article.find('.time').text(data['A_ViewTime']); article.find('.text').html(news); } function appendSocialText(data) { // APP廣告文字 article.find('.text').append($(data['cacheApptext'])); } function creatTodayNewsElements(todayNews) { if (todayNews.recommendations.length > 0) { headlineDiv = document.createElement('div'); headlineDiv.setAttribute('class', "headline"); boldText = document.createElement('b'); boldText.textContent = '今日熱門'; headlineDiv.append(boldText); divTodayNewsWrap = document.createElement('section'); divTodayNewsWrap.setAttribute('class', 'news_wrap top_news'); divTodayNewsWrap.append(headlineDiv); divTodayNewsWrap.append(appendTodayNews(todayNews)); waitAjax.before(divTodayNewsWrap); processResizeImages('.resize_imgs_ltn'); } } function dfpSetting(dfpInfo, page) { dfpDefineSlot(dfpInfo['slot'], dfpInfo['size'], dfpInfo['div'] + '_' + (page + 1)); displayDFP(dfpInfo['div'] + '_' + (page + 1), checkDevice); } async function doDeviceAppend(data, page) { // 處理麵包屑 let breadcrumbs = creatCrumbsElements(data); switch (checkDevice) { case 'pc': // 廣告塞K2 K2adOutside = creatDfpElement('K2', dfp['K2'].class, dfp, page, checkDevice); // 按頁面順序塞入列表並顯示 waitAjax.before(breadcrumbs); waitAjax.before(article); article.fadeIn(1000); //相關新聞 appendArticleContent(data); // k2 廣告 waitAjax.before(K2adOutside); // 今日熱門 await fetchHotNews(data['crumbs'][1]['ch'], 10, "hotnews_bottom", creatTodayNewsElements); dfpSetting(dfp['K2'], page); break; case 'm': // 廣告塞IR1 let IR1adOutside = creatDfpElement('IR1', dfp['IR1'].class, dfp, page, checkDevice); IR1adOutside = IR1adOutside.innerHTML; data['A_Html'] = insertADtoArticle(data['A_Html'], IR1adOutside, 2); // 廣告塞ATF ATFadOutside = creatDfpElement('B1-ATF', dfp['B1-ATF'].class, dfp, page, checkDevice); // 廣告塞B2 B2adOutside = creatDfpElement('B2', dfp['B2'].class, dfp, page, checkDevice); // 按頁面順序塞入列表並顯示 waitAjax.before(ATFadOutside); waitAjax.before(breadcrumbs); waitAjax.before(article); article.fadeIn(1000); //相關新聞 appendArticleContent(data); //B2廣告 waitAjax.before(B2adOutside); // 今日熱門 await fetchHotNews(data['crumbs'][1]['ch'], 10, "hotnews_bottom", creatTodayNewsElements); dfpSetting(dfp['B1-ATF'], page); dfpSetting(dfp['B2'], page); dfpSetting(dfp['IR1'], page); break; default: break; } } function appendArticleContent(data) { // 內文 appendContent(data); // 社群 registeredSocialShare(data); // 社群 appendSocialText(data); //pc Fb youtube嵌入影音高度調整 $(function() { //pc Fb youtube嵌入影音高度調整 video_resize_pc('.text'); }); $(window).on('load', function() { //pc 表格顯示調整 rwd_table_resize('.text'); // pc fb post調整 rwd_fbpost_resize('.text'); }); // 關鍵字 // if (data['keywords'].length > 0) { // appendKeywordsToArticle(data); // } // 相關文章 appendRelationsToArticle(data); waitAjax.before(relatedSection) } //轉換時間 function formatTimeString(datatime) { // 將時間字串轉換為年、月、日 let year = datatime.substring(0, 4); let month = datatime.substring(4, 6); let day = datatime.substring(6, 8); // 构建新的格式化日期字符串 return `${year}/${month}/${day}/`; } //添加點圖放大className function beforeClickEntImageLarge() { let articleImages = document.getElementsByClassName('imagePopup'); for (let $i = 0; $i < articleImages.length; $i++) { // 取圖片父親節點 let imageParent = articleImages[$i].parentNode; // 取圖說 let imageParentSibling = imageParent.nextSibling; // 如果imageParentSibling不存在,跳過 if (!imageParentSibling) { continue; } let imgtext = imageParentSibling.textContent; // 用a標籤去包 let imageOutside = document.createElement('a'); imageOutside.setAttribute('class', 'image-popup-vertical-fit'); imageOutside.setAttribute('title', imgtext); imageOutside.setAttribute('href', articleImages[$i].dataset.src); imageOutside.append(articleImages[$i]); imageParent.append(imageOutside); } } //圖片大小調整 function processResizeImages(containerSelector) { $(containerSelector).find('img').each(function() { resize_imgs($(this)); }).on('load', function() { // 同時有 lazyload 效果時再處理一次 resize_imgs($(this)); }); lazyImg = $('img.lazy_imgs_ltn'); lazyload(lazyImg); }