This repository has been archived by the owner on Sep 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
203 lines (171 loc) · 5.32 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
(function() {
var log = function(msg, $card) {
if(console && console['log']) {
var title = $card ? $card.find('.title-text').text().trim() : null;
console.log("[Strava feed filter extension] " + msg, title);
}
};
var isCommute = function($activity) {
return ($activity.find('.activity-map-tag, .workout-type').text().toLowerCase().indexOf('commute') >= 0);
};
var hasPhoto = function($activity) {
if($activity.find('.entry-photo').length > 0) {
return true;
}
else {
return false;
}
};
var isVirtual = function($activity) {
if($activity.find('.icon-virtualride, .icon-workout').length > 0) {
return true;
}
else if($activity.html().indexOf('virtualride') >= 0) {
return true;
}
else if($activity.find('.enhanced-tag').text().indexOf('TrainerRoad') >= 0) {
return true;
}
else if($activity.find('.enhanced-tag').text().indexOf('Peloton') >= 0) {
return true;
}
else if($activity.find('.enhanced-tag').text().indexOf('FitBod') >= 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 isLongCycle = 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'); //log("distance? " + $value.text(), $activity);
if(isLongDistance($value, minMiles)) {
return true;
}
}
}
var $distance = $activity.find('.list-stats li[title="Distance"]');
if(isLongDistance($distance, minMiles)) {
return true;
}
}
return false;
};
var isLongDistance = function($value, minMiles) {
var unit = $value.find('.unit').text().trim().toLowerCase();
var raw = $value.text().toLowerCase();
var miles = parseFloat(raw.substring(0, raw.length - unit.length).trim());
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 () {
if(options.hideVirtual && isVirtual( $(this) )) {
mark( $(this), options.action );
log("Virtual activity hidden", $(this));
}
if(options.hideChallenge && isChallenge( $(this) )) {
mark( $(this), options.action );
log("Challenge activity hidden", $(this));
}
if(options.showPhoto && hasPhoto( $(this) )) {
log("Photo activity, skipping other tests", $(this));
return;
}
if(options.showLongCycle > 0 && isLongCycle( $(this), options.showLongCycle )) {
log("Long cycle activity, skipping other tests", $(this));
return;
}
if(options.hideCommute && isCommute( $(this) )) {
mark( $(this), options.action );
log("Commute activity hidden", $(this));
}
// this doesn't actually work, classes are reset on pagination
if($(this).hasClass('boring')) {
//log("Found boring, skipping", $(this));
//return;
}
mark( $(this), options.action );
log("Default hide activity", $(this));
});
/*var $feed = $('.feed-container > .feed'),
$cards = $feed.children('.feed-entry');
$cards.sort(function(a,b) {
var attr = 'data-updated-at';
var an = a.getAttribute(attr),
bn = b.getAttribute(attr);
if(an < bn) return 1;
if(an > bn) return -1;
else return 0;
});
$cards.detach().appendTo($feed);*/
/*$('.pagination a.load-feed').last().on('click', function() {
setTimeout(filterFeed, 3000);
});*/
};
var autoPaginate = function(remaining) {
if(remaining < 1) return;
log("Fetching next page (" + remaining + " loads remaining)");
$('.feed-pagination a.btn').click();
setTimeout(function() { autoPaginate(remaining-1); }, 5000);
};
var defaultOptions = {
action: 'fade',
hideCommute: true,
hideVirtual: true,
hideChallenge: false,
showPhoto: true,
showLongCycle: 0,
autoPage: 3,
};
var options = defaultOptions;
(function() {
log("Loading options");
chrome.storage.sync.get(defaultOptions, function(items) {
if (items && ! chrome.runtime.error) {
options = items;
filterFeed();
}
else {
filterFeed();
}
options.showLongCycle = parseInt(options.showLongCycle);
log("options: " + JSON.stringify(options));
setInterval(filterFeed, 3000);
setTimeout(function() { autoPaginate(options.autoPage); }, 5000);
});
})();
})();