forked from yemble/chrome-strava-filter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
180 lines (156 loc) · 4.67 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
(function() {
var log = function(msg) {
if(console && console['log']) {
console.log("[Strava feed filter extension] " + msg);
}
};
var isCommute = function($activity) {
return ($activity.find('.activity-map-tag, .workout-type').text().toLowerCase().indexOf('commute') >= 0);
};
var isVirtual = function($activity) {
if($activity.find('.icon-virtualride').length > 0) {
return true;
}
else if($activity.html().indexOf('virtualride') > 0) {
return true;
}
// eDad2003 -- filter out Peloton
else if($activity.html().indexOf('Peloton') > 0) {
return true;
}
// eDad2003 -- filter out TrainerRoad
else if($activity.html().indexOf('TrainerRoad') > 0) {
return true;
}
else {
return false;
}
};
var isChallenge = function($activity) {
if($activity.hasClass('challenge') || $activity.find('.challenge-image, .btn-join-challenge').length > 0) {
return true;
}
else {
return false;
}
};
var isShortCycle = function($activity, minMiles) {
if($activity.find('.icon-ride').length > 0) {
var $stats = $activity.find('.list-stats .stat');
for(var i = 0; i < $stats.length; i++) {
var $stat = $( $stats[i] );
if($stat.find('.stat-subtext').text().toLowerCase().indexOf('distance') >= 0) {
var $value = $stat.find('.stat-text');
if(isShortDistance($value, minMiles)) {
return true;
}
}
}
var $distance = $activity.find('.list-stats li[title="Distance"]');
if(isShortDistance($distance, minMiles)) {
return true;
}
}
return false;
};
var isShortWalk = function($activity, minMiles) {
if($activity.find('.icon-walk').length > 0) {
var $stats = $activity.find('.list-stats .stat');
for(var i = 0; i < $stats.length; i++) {
var $stat = $( $stats[i] );
if($stat.find('.stat-subtext').text().toLowerCase().indexOf('distance') >= 0) {
var $value = $stat.find('.stat-text');
if(isShortDistance($value, minMiles)) {
return true;
}
}
}
var $distance = $activity.find('.list-stats li[title="Distance"]');
if(isShortDistance($distance, minMiles)) {
return true;
}
}
return false;
};
var isShortDistance = function($value, minMiles) {
var unit = $value.find('.unit').text().toLowerCase().trim();
var raw = $value.text().toLowerCase();
var miles = parseFloat(raw.substring(0, raw.length - unit.length));
if(unit == 'km') {
miles *= 0.621371
}
if(unit == 'km' || unit == 'mi' || unit.indexOf('mile') == 0) {
if(miles < minMiles) {
return true
}
}
return false;
}
var mark = function($activity, action) {
if(action == 'hide') {
$activity.hide();
}
else {
$activity.css('opacity', '0.15')
}
$activity.addClass('boring');
}
var filterFeed = function() {
// skip own feed
if(document.location.search == '?feed_type=my_activity') {
return;
}
//log("Filtering now");
$('.feed .feed-entry').each(function () {
// this doesn't actually work, classes are reset on pagination
if($(this).hasClass('boring')) {
//log("Found boring, skipping");
return;
}
if(options.hideCommute && isCommute( $(this) )) {
mark( $(this), options.action );
log("Commute activity hidden");
}
if(options.hideVirtual && isVirtual( $(this) )) {
mark( $(this), options.action );
log("Virtual activity hidden");
}
if(options.hideChallenge && isChallenge( $(this) )) {
mark( $(this), options.action );
log("Challenge activity hidden");
}
if(options.hideShortCycle > 0 && isShortCycle( $(this), options.hideShortCycle )) {
mark( $(this), options.action );
log("Short cycle activity hidden");
}
if(options.hideShortWalk > 0 && isShortWalk( $(this), options.hideShortWalk )) {
mark( $(this), options.action );
log("Short walk activity hidden");
}
});
//$('.pagination a.load-feed').last().on('click', function() {
setTimeout(filterFeed, 3000);
//});
};
var defaultOptions = {
action: 'fade',
hideCommute: true,
hideVirtual: true,
hideChallenge: false,
hideShortCycle: 0,
hideShortWalk: 0,
};
var options = defaultOptions;
(function() {
log("Loading options");
chrome.storage.sync.get(defaultOptions, function(items) {
if (items && ! chrome.runtime.error) {
options = items;
filterFeed();
}
else {
filterFeed();
}
});
})();
})();