Skip to content

joshbax189/30x30-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Capra 30x30 sync tool

Disclaimer: I’m not affiliated with Capra. This is a hacky tool for lazy runners, use at your own risk.

This tool lets you copy runs from strava to the Capra 30x30 page. It runs totally on your browser, nothing is sent other than the runs you upload.

Installation

Copy the following to a bookmark.

javascript:(()=>{switch(location.host){case"www.strava.com":globalThis.selectedData={};globalThis.copyData=elt=>{let row=elt.parentElement.parentElement.parentElement;let[s,m,h]=row.querySelector(".col-time").textContent.split(":").reverse();let time=(h||0)*60+1*m;let dist=Number.parseFloat(row.querySelector(".col-dist").textContent.trim().split(10)[0]);let date=new Date(row.querySelector(".col-date").textContent.split(" ")[1].split("/")).toISOString().split("T")[0];let hideDist=row.querySelector(".hide-dist")?.checked;dist=hideDist?0:dist;if(date){if(!date.startsWith("2024-11")){alert("ignored activity "+date);return}let existing=globalThis.selectedData[date];globalThis.selectedData[date]={time:(existing?.time||0)+time,dist:(existing?.dist||0)+dist}}};globalThis.openCapraUrl=()=>{let selected=document.querySelectorAll(".do-sync:checked");if(selected.length==0){alert("No activities selected to upload");return}globalThis.selectedData={};selected.forEach(copyData);const url="https://30x30.capra.run/#"+btoa(JSON.stringify(globalThis.selectedData));window.open(url);document.querySelectorAll(".capra:checked").forEach(x=>x.checked=false)};document.querySelector(".page.container").innerHTML+='<button style="position:fixed;top:5em;right:5em;" onclick="openCapraUrl()">Upload to Capra</button>';document.querySelectorAll("tbody .col-actions").forEach(x=>x.innerHTML+='<label>sync to 30x30<input type="checkbox" class="capra do-sync"/></label>'+'<label>hide dist<input type="checkbox" class="capra hide-dist"/></label>');break;case"30x30.capra.run":globalThis.upload=()=>{const uploadData=JSON.parse(atob(window.location.hash.substr(1)));let i=1;let promises=[];for(let[date,{time,dist}]of Object.entries(uploadData)){promises.push(new Promise(function(resolve,reject){setTimeout(()=>fetch("https://30x30.capra.run/api/exercise",{headers:{accept:"application/json, text/plain, */*","content-type":"application/json"},body:`{\"minutes\":${time},\"km\":${dist||0},\"date\":\"${date}\"}`,method:"POST",mode:"cors",credentials:"include"}).then(res=>{if(res.ok){resolve(date)}else{alert(`There was a problem with ${date}`)}}),i*350)}));i++}Promise.all(promises).then(res=>{alert("updated the following dates: "+res.join())})};if(!location.hash){alert("No data to upload. Return to strava and click link to open a new window.");return}else{const uploadData=JSON.parse(atob(window.location.hash.substr(1)));const dates=Object.keys(uploadData);document.querySelector(".MuiBox-root:first-child .MuiContainer-root").innerHTML+='<button onclick="upload()">Upload to Capra</button>'+`<span>${dates.join()}</span>`}break;default:alert("only works when either on capra or strava websites")}})();

Double-check: Some browsers remove the javascript: from the start of the bookmark when you copy it (as a safety measure). You might need to manually type it into the bookmark URL.

./images/good_bookmark.png bookmark URL must start with javascript:

./images/bad_bookmark.png incorrect example, missing javascript: from start

How to Upload from Strava

Do this each time you want to upload new runs or correct existing data.

A couple of notes before you start

  • multiple Strava activities on the same day are added together
  • Strava activities overwrite Capra activities for the same day
  • it works for any activity type, as long as the distance and time are visible on the strava activities view
  • all other Capra times are not changed

Steps:

  1. Log in to the Capra site using your email link
  2. Visit https://www.strava.com/athlete/training
  3. Click the bookmark once the activities have loaded, you should see a button appear and checkboxes on each activity ./images/strava_button.png
  4. Check all the activities you want to upload. If you want to upload just the time for a certain activity, click both the ‘sync to 30x30’ and ‘hide dist’ checkboxes.
  5. Click the ‘upload to capra’ button
  6. A new page with the Capra 30x30 activities should open (you should still see a ‘sign out’ button)
  7. On the Capra page click the bookmark again, you should see another button appear with a list of the dates that will change ./images/capra_button.png
  8. You should eventually see a popup saying which dates were updated
  9. Close the capra window

How it Works

The bookmark contains Javascript that copies the selected activities from the Strava page, adds it to the Capra URL in the new page that is opened. The second time you click the bookmark it takes the data from the URL and sends it to Capra using your access credentials.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published