forked from zekefarwell/josm-strava-heatmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
35 lines (29 loc) · 1.15 KB
/
background.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
const url_prefix = "tms:https://heatmap-external-{switch:a,b,c}.strava.com/tiles-auth/";
const url_suffix = "/{zoom}/{x}/{y}.png"
async function getHeatmapUrl(map_color, map_type, tab_url, store_id)
{
let pair = await getCookieValue('CloudFront-Key-Pair-Id', tab_url, store_id);
let policy = await getCookieValue('CloudFront-Policy', tab_url, store_id);
let signature = await getCookieValue('CloudFront-Signature', tab_url, store_id);
let query_string = `?Key-Pair-Id=${pair}&Policy=${policy}&Signature=${signature}`
let heatmap_url = url_prefix + map_type + '/' + map_color + url_suffix + query_string
let error = (pair && policy && signature) ? false : true
return { error, heatmap_url }
}
async function getCookieValue(name, url, store_id)
{
let cookie = await browser.cookies.get({
url: url,
name: name,
storeId: store_id
});
return (cookie) ? cookie.value : false
}
browser.runtime.onMessage.addListener(async function (message, sender, sendResponse) {
return getHeatmapUrl(
message.map_color,
message.map_type,
sender.tab.url,
sender.tab.cookieStoreId
)
});