const storage = chrome.storage.local; var settings = null; var eventDataCache = null; var performanceDataCache = null; var selectedPerfId = null; var perfPriceListMap = null; var pageLoaded = false; var eventImageUrl = null; var perfDisplayStyle = null; var allPerformanceDataCache = null; var contextPath = "/utsvInternet"; var showEnlargedImage = function(image){ if(image === 'event'){ $('.image').attr('src', eventImageUrl); } $("#commonImageModal").modal('show'); } var addToCalendar = function() { if(eventDataCache && eventDataCache.eventDate){ let addToCalButton= document.querySelector('add-to-calendar-button') localStorage.getItem('theme-color') == 'black'? addToCalButton.setAttribute('lightMode','dark') : addToCalButton.removeAttribute('lightMode') let options = []; options.push('Google|'+ $.i18n("calendar-google")) options.push('iCal|'+ $.i18n("calendar-ical")) options.push('Outlook.com|'+ $.i18n("calendar-outlook")) addToCalButton.setAttribute('options',JSON.stringify(options)) let customLabels = { 'close': $.i18n("calendar-close"), 'label.addtocalendar': $.i18n("calendar-label-addtocalendar") }; addToCalButton.setAttribute('customLabels',JSON.stringify(customLabels)) let venueNameField = getDataFieldByLang("venueName") addToCalButton.setAttribute('location',eventDataCache.venue[venueNameField]) $("#addToCal").show(); if(performanceDataCache){ if(performanceDataCache.performances && performanceDataCache.performances.length > 0) { let dates = [] performanceDataCache.performances.forEach(perf =>{ let performanceNameField = getDataFieldByLang("performanceName"); let performanceName = perf[performanceNameField]; if(performanceDataCache.performances.length == 1){ addToCalButton.setAttribute('name', performanceName) addToCalButton.setAttribute('startDate', moment(perf.performanceDate).format("YYYY-MM-DD")) }else{ let prefDate = { name: performanceName, startDate: moment(perf.performanceDate).format("YYYY-MM-DD") } dates.push(prefDate) } }) if(performanceDataCache.performances.length > 1) addToCalButton.setAttribute('dates',JSON.stringify(dates)) } } } } var fillEventData = function(data) { console.log("eventData:", data); eventDataCache = data; eventImageUrl = data.eventLargeCoverUrl let reload=false; let eventStatues = {"TOBESOLD" : "event-status-tobesold", "SALE" : "event-status-sale", "SOLDOUT" : "event-status-soldout", "EXPIRED" : "event-status-expired"}; if(data.status=="TOBESOLD") reload=true; if(data.status=="SOLDOUT") reload=true;; if(reload) { let auto_reload_page_interval = 0.0; if(settings) { auto_reload_page_interval = settings.advanced.auto_reload_page_interval; } const rootElement = document.documentElement; rootElement.remove(); if(auto_reload_page_interval == 0) { //console.log('Start to reload now.'); location.reload(); } else { console.log('We are going to reload after few seconeds.'); setTimeout(function () { location.reload(); }, auto_reload_page_interval * 1000); } } } var openWindow = function(url) { let citylineWindow = window.open(url,"_blank ","width=1020,height=600,top=0,left=20,resizable=yes,menubar=no,scrollbars=yes,status=yes"); citylineWindow.focus(); } var fillPerformanceData = function(data) { console.log("eventPerfData:", data); performanceDataCache = data; perfPriceListMap = new Map(); //selectedPerfId = null; let perfHtml = ""; if(data.performances && data.performances.length > 0) { let fillerPerId = []; data.performances.forEach(i => fillerPerId.push(i.performanceId)) data.performances.forEach(function(perf, i) { perfHtml += getPerfHtml(perf) perfPriceListMap.set(perf.performanceId, perf.pricelist); if(perfDisplayStyle === 'DEFAULT'){ if(!selectedPerfId && perf.status != 'SOLDOUT') selectedPerfId = perf.performanceId; }else if(perfDisplayStyle === 'CALENDAR'){ if(!selectedPerfId && perf.status != 'SOLDOUT') selectedPerfId = perf.performanceId; if(!fillerPerId.includes(+selectedPerfId)){ if(perf.status != 'SOLDOUT') selectedPerfId = perf.performanceId; } } /* Google Analytics */ var formatDate = new Date(perf.performanceDate); var item = { id : "[" + eventSynonym + "] " + formatForGoogleAnalytics(formatDate), // 2021/08/14 23:59 (Sat) name : event_en, category : "[" + eventSynonym + "] " + formatForGoogleAnalytics(formatDate), list_position : i }; viewItems.push(item); if (i == 0) { googleAnalyticViewItem(perf.performanceId, formatForGoogleAnalytics(perf.performanceDate)); } }); googleAnalyticViewItemList(); $(".date-box").html(perfHtml); selectPerf(); } else { $(".date-title").addClass("d-none"); } } var getPerfById = function(perfId) { var perfList = performanceDataCache.performances; if(perfList && perfList.length > 0) { return perfList.find(perf => perf.performanceId == perfId) } else { return null; } } var fillPriceList = function(perfId) { let priceList = perfPriceListMap.get(perfId); let ticketPriceHtml = getTicketPriceHtml(priceList); $(".puchase-bottom").html(ticketPriceHtml); } var selectPerf = function() { if(selectedPerfId){ $('button.date-time-position').attr("aria-pressed", false); let selectedElement = $("*[data-perf-id='" + selectedPerfId + "']"); selectedElement.addClass("item-onclick"); selectedElement.attr("aria-pressed", true); fillPriceList(selectedPerfId); var perf = getPerfById(selectedPerfId); if (perf) { var perfDate = new Date(perf.performanceDate); googleAnalyticViewItem(selectedPerfId, formatForGoogleAnalytics(perfDate)); } } } var getTicketPriceHtml = function(priceList){ let ticketPriceHtml = ""; if(priceList){ priceList.sort((a, b) => (a.price > b.price) ? -1 : 1); priceList.forEach(function(pl) { let statusHtml = ""; if(pl.status == 'LIMIT' || pl.status == 'SOLDOUT'){ statusHtml = ''; } ticketPriceHtml += ' '; }); } ticketPriceHtml = '