import * as _ from "lodash" ; import { Loader } from "../modules/loader" ; import { AppResourcesModel } from "./models/app-resources.model" ; import { StartCoreDataModel } from "./models/start-core-data.model" ; import { CoreMessages , UserSettingsModel } from "@elevate/shared/models" ; import { userSettingsData } from "@elevate/shared/data" ; import { BrowserStorage } from "./browser-storage" ; import { BrowserStorageType } from "./models/browser-storage-type.enum" ; export class Content { public static loader : Loader = new Loader ( ) ; protected appResources : AppResourcesModel ; constructor ( appResources ) { this . appResources = appResources ; } public isExtensionRunnableInThisContext ( ) { let isRunnable = true ; if ( window . location . pathname . match ( /^\/routes\/new/ ) || window . location . pathname . match ( /^\/routes\/(\d+)\/edit$/ ) || window . location . pathname . match ( /^\/about/ ) || window . location . pathname . match ( /^\/running-app/ ) || window . location . pathname . match ( /^\/features/ ) || window . location . pathname . match ( /^\/api/ ) || window . location . pathname . match ( /^\/premium/ ) || window . location . pathname . match ( /^\/gopremium/ ) || window . location . pathname . match ( /^\/store/ ) || window . location . pathname . match ( /^\/how-it-works/ ) || window . location . pathname . match ( /^\/careers/ ) ) { isRunnable = false ; } if ( document . body . classList . contains ( "is-home-page" ) || document . body . classList . contains ( "logged-out" ) ) { isRunnable = false ; } return isRunnable ; } public start ( ) { if ( ! this . isExtensionRunnableInThisContext ( ) ) { console . log ( "Skipping Elevate chrome extension execution in this page" ) ; return ; } BrowserStorage . getInstance ( ) . get < any > ( BrowserStorageType . LOCAL ) . then ( result => { let userSettingsModel ; const hasUserSettingsKey = ! _ . isEmpty ( result . userSettings ) ; if ( hasUserSettingsKey ) { userSettingsModel = result . userSettings ; } else { userSettingsModel = userSettingsData ; } const defaultSettings = _ . keys ( userSettingsData ) ; const syncedSettings = _ . keys ( userSettingsModel ) ; if ( _ . difference ( defaultSettings , syncedSettings ) . length !== 0 ) { _ . defaults ( userSettingsModel , userSettingsData ) ; } const startCoreData = { extensionId : chrome . runtime . id , userSettings : userSettingsModel , appResources : this . appResources , } ; Content . loader . injectJS ( "const $ = jQuery;" ) ; Content . loader . require ( [ "core/boot.bundle.js" ] , ( ) => { this . emitStartCoreEvent ( startCoreData ) ; } ) ; } ) ; } protected emitStartCoreEvent ( startCoreData ) { const startCorePluginEvent = new CustomEvent ( "Event" ) ; startCorePluginEvent . initCustomEvent ( CoreMessages . ON_START_CORE_EVENT , true , true , startCoreData ) ; dispatchEvent ( startCorePluginEvent ) ; } } export let appResources = { settingsLink : chrome . extension . getURL ( "/app/index.html" ) , logoElevate : chrome . extension . getURL ( "/core/icons/logo_elevate_no_circle.svg" ) , menuIconBlack : chrome . extension . getURL ( "/core/icons/ic_menu_24px_black.svg" ) , menuIconOrange : chrome . extension . getURL ( "/core/icons/ic_menu_24px_orange.svg" ) , remoteViewIcon : chrome . extension . getURL ( "/core/icons/ic_open_in_new_24px.svg" ) , pollIcon : chrome . extension . getURL ( "/core/icons/ic_poll_24px.svg" ) , helpIcon : chrome . extension . getURL ( "/core/icons/ic_help_black_24px.svg" ) , veloviewerIcon : chrome . extension . getURL ( "/core/icons/veloviewer.ico" ) , raceshapeIcon : chrome . extension . getURL ( "/core/icons/raceshape.ico" ) , veloviewerDashboardIcon : chrome . extension . getURL ( "/core/icons/ic_dashboard_24px.svg" ) , veloviewerChallengesIcon : chrome . extension . getURL ( "/core/icons/ic_landscape_24px.svg" ) , labIcon : chrome . extension . getURL ( "/core/icons/lab.png" ) , settingsIcon : chrome . extension . getURL ( "/core/icons/ic_settings_24px.svg" ) , heartIcon : chrome . extension . getURL ( "/core/icons/ic_favorite_24px.svg" ) , zonesIcon : chrome . extension . getURL ( "/core/icons/ic_format_line_spacing_24px.svg" ) , komMapIcon : chrome . extension . getURL ( "/core/icons/ic_looks_one_24px.svg" ) , heatmapIcon : chrome . extension . getURL ( "/core/icons/ic_whatshot_24px.svg" ) , bugIcon : chrome . extension . getURL ( "/core/icons/ic_bug_report_24px.svg" ) , rateIcon : chrome . extension . getURL ( "/core/icons/ic_star_24px.svg" ) , aboutIcon : chrome . extension . getURL ( "/core/icons/ic_info_outline_24px.svg" ) , peopleIcon : chrome . extension . getURL ( "/core/icons/ic_supervisor_account_black_24px.svg" ) , eyeIcon : chrome . extension . getURL ( "/core/icons/ic_remove_red_eye_24px.svg" ) , bikeIcon : chrome . extension . getURL ( "/core/icons/ic_directions_bike_24px.svg" ) , mapIcon : chrome . extension . getURL ( "/core/icons/ic_map_24px.svg" ) , wheatherIcon : chrome . extension . getURL ( "/core/icons/ic_wb_sunny_24px.svg" ) , twitterIcon : chrome . extension . getURL ( "/core/icons/twitter.svg" ) , systemUpdatesIcon : chrome . extension . getURL ( "/core/icons/ic_system_update_24px.svg" ) , fitnessCenterIcon : chrome . extension . getURL ( "/core/icons/ic_fitness_center_black_24px.svg" ) , timelineIcon : chrome . extension . getURL ( "/core/icons/ic_timeline_black_24px.svg" ) , viewListIcon : chrome . extension . getURL ( "/core/icons/baseline-view_list-24px.svg" ) , dateRange : chrome . extension . getURL ( "/core/icons/ic_date_range_black_24px.svg" ) , athleteIcon : chrome . extension . getURL ( "/core/icons/ic_accessibility_black_24px.svg" ) , donateIcon : chrome . extension . getURL ( "/core/icons/ic_attach_money_24px.svg" ) , shareIcon : chrome . extension . getURL ( "/core/icons/ic_share_24px.svg" ) , trackChangesIcon : chrome . extension . getURL ( "/core/icons/ic_track_changes_24px.svg" ) , trendingUpIcon : chrome . extension . getURL ( "/core/icons/ic_trending_up_black_24px.svg" ) , qrCodeIcon : chrome . extension . getURL ( "/core/icons/qrcode.svg" ) , lightbulbIcon : chrome . extension . getURL ( "/core/icons/fa-lightbulb-o.png" ) , heartBeatIcon : chrome . extension . getURL ( "/core/icons/fa-heartbeat.png" ) , areaChartIcon : chrome . extension . getURL ( "/core/icons/fa-area-chart.png" ) , tachometerIcon : chrome . extension . getURL ( "/core/icons/fa-tachometer.png" ) , boltIcon : chrome . extension . getURL ( "/core/icons/fa-bolt.png" ) , loadingIcon : chrome . extension . getURL ( "/core/icons/loading.gif" ) , circleNotchIcon : chrome . extension . getURL ( "/core/icons/fa-circle-o-notch.png" ) , lineChartIcon : chrome . extension . getURL ( "/core/icons/fa-line-chart.png" ) , logArrowUpIcon : chrome . extension . getURL ( "/core/icons/fa-long-arrow-up.png" ) , cogIcon : chrome . extension . getURL ( "/core/icons/fa-cog.png" ) , logoNoText : chrome . extension . getURL ( "/core/icons/logo_no_text.svg" ) , logoTextOnly : chrome . extension . getURL ( "/core/icons/logo_text_only.svg" ) , extVersion : chrome . runtime . getManifest ( ) . version , extVersionName : chrome . runtime . getManifest ( ) . version_name , extensionId : chrome . runtime . id , } ; const content = new Content ( appResources ) ; content . start ( ) ;