import * as _ from "lodash" ; import { UserSettingsModel } from "@elevate/shared/models" ; import { AbstractModifier } from "./abstract.modifier" ; export class HideFeedModifier extends AbstractModifier { private static VIRTUAL_RIDE = "virtualride" ; private static RIDE = "ride" ; private static RUN = "run" ; protected userSettings : UserSettingsModel ; constructor ( userSettings ) { super ( ) ; this . userSettings = userSettings ; } public modify ( ) { const timeout = 250 ; setInterval ( ( ) => { if ( this . userSettings . feedHideChallenges ) { $ ( ".feed-container" ) . find ( ".challenge" ) . remove ( ) ; } if ( this . userSettings . feedHideCreatedRoutes ) { $ ( "div.feed>.min-view" ) . each ( ( index , element ) => { if ( $ ( "div.feed" ) . find ( "div.entry-container" ) . has ( "a[href*='/routes']" ) . length > 0 ) { $ ( element ) . remove ( ) ; } } ) ; } if ( this . userSettings . feedHidePosts ) { $ ( ".post.feed-entry.card" ) . remove ( ) ; } if ( this . userSettings . feedHideSuggestedAthletes ) { $ ( "#suggested-follows" ) . remove ( ) ; } if ( this . userSettings . feedHideVirtualRides || this . userSettings . feedHideRideActivitiesUnderDistance > 0 || this . userSettings . feedHideRunActivitiesUnderDistance > 0 ) { const minRideDistanceToHide = this . userSettings . feedHideRideActivitiesUnderDistance ; const minRunDistanceToHide = this . userSettings . feedHideRunActivitiesUnderDistance ; $ ( "div.feed>.activity" ) . each ( ( index , element ) => { const activityType = $ ( element ) . find ( "div.entry-icon.media-left" ) . find ( ".app-icon" ) . attr ( "class" ) . replace ( /^.*icon-(?!lg|dark)([^ ]+).*$/ , "$1" ) ; const distanceElement = _ . filter ( $ ( element ) . find ( "ul.list-stats" ) . find ( "[class=unit]" ) , ( item ) => { return ( $ ( item ) . html ( ) . trim ( ) == "km" || $ ( item ) . html ( ) . trim ( ) == "mi" ) ; } ) ; const distance = parseFloat ( $ ( distanceElement ) . parent ( ) . text ( ) . replace ( "," , "." ) ) ; if ( this . userSettings . feedHideVirtualRides && activityType === HideFeedModifier . VIRTUAL_RIDE ) { $ ( element ) . remove ( ) ; } if ( ( minRideDistanceToHide > 0 ) && distance && ( distance < minRideDistanceToHide ) && ( activityType === HideFeedModifier . RIDE || activityType === HideFeedModifier . VIRTUAL_RIDE ) ) { $ ( element ) . remove ( ) ; } if ( ( minRunDistanceToHide > 0 ) && distance && ( distance < minRunDistanceToHide ) && activityType === HideFeedModifier . RUN ) { $ ( element ) . remove ( ) ; } } ) ; } $ ( "div.feed>.time-header" ) . each ( ( index , element ) => { const timeHeaderElement = $ ( element ) ; if ( timeHeaderElement . nextUntil ( ".time-header" ) . not ( "script" ) . length === 0 ) { timeHeaderElement . remove ( ) ; } } ) ; } , timeout ) ; } }