xsanda / Strava route planner for all

// ==UserScript==
// @name Strava route planner for all
// @namespace   xsanda
// @description Use the Strava route planner
// @version 0.2.1
// @include https://www.strava.com/routes/new*
// @include https://www.strava.com/routes/*/edit*
// @include https://www.strava.com/athletes/*/training/log
// @include https://www.strava.com/athlete/heatmaps*
// @require https://openuserjs.org/src/libs/xsanda/Run_code_as_client.js
// @updateURL https://openuserjs.org/meta/xsanda/Strava_route_planner_for_all.meta.js
// @downloadURL https://openuserjs.org/install/xsanda/Strava_route_planner_for_all.user.js
// @run-at document-start
// @grant none
// @license MIT
// ==/UserScript==

/* jshint esversion: 6 */
/* globals Waiter */


runAsClient(() => {
  console.log('Trying to enable premium route editor');

  const addSetHandler = (object, property, didSet) => {
    let value = object[property];
    Object.defineProperty(object, property, {
      set: (newValue) => didSet(value = newValue),
      get: () => value,
    });
    if (value) {
      didSet(value);
    }
  }

  addSetHandler(window, '__NEXT_DATA__', data => {
    data.props.currentAthletePreload.is_subscriber = true;
    if (data.props.currentAthletePreload.features) {
      for (const key of Object.keys(data.props.currentAthletePreload.features)) {
        data.props.currentAthletePreload.features[key] = true;
      }
    }
    if (data.props.pageProps.metadata) data.props.pageProps.metadata.is_paywalled = false;
    console.log("Premium route editor enabled");
  });
});