Bikemap.net Export GPX and KML routes

Download GPX, KML, TCX and geoJSON files for a route on bikemap.net

  1. // ==UserScript==
  2. // @name Bikemap.net Export GPX and KML routes
  3. // @description Download GPX, KML, TCX and geoJSON files for a route on bikemap.net
  4. // @namespace github.com/cvzi
  5. // @icon https://static.bikemap.net/favicons/apple-touch-icon.png
  6. // @match https://www.bikemap.net/*
  7. // @match https://web.bikemap.net/*
  8. // @connect www.bikemap.net
  9. // @version 1.3.2
  10. // @homepage https://github.com/cvzi/bikemapnet-userscript
  11. // @author cuzi
  12. // @license MIT
  13. // @grant GM.xmlHttpRequest
  14. // @grant GM.registerMenuCommand
  15. // ==/UserScript==
  16.  
  17. /*
  18. MIT License
  19.  
  20. Copyright (c) 2022, cuzi (https://openuserjs.org/users/cuzi)
  21.  
  22. Permission is hereby granted, free of charge, to any person obtaining a copy
  23. of this software and associated documentation files (the "Software"), to deal
  24. in the Software without restriction, including without limitation the rights
  25. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  26. copies of the Software, and to permit persons to whom the Software is
  27. furnished to do so, subject to the following conditions:
  28.  
  29. The above copyright notice and this permission notice shall be included in all
  30. copies or substantial portions of the Software.
  31.  
  32. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  33. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  34. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  35. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  36. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  37. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  38. SOFTWARE.
  39. */
  40.  
  41. /* globals GM */
  42. (function () {
  43. 'use strict'
  44.  
  45. window.setInterval(addDownloadButtons, 3000)
  46.  
  47. function addDownloadButtons () {
  48. if (document.getElementById('script_gpx_button')) {
  49. return
  50. }
  51. if (document.location.href.match(/\/r\/(\d+)/)) {
  52. GM.registerMenuCommand('Download gpx', () => startDownload('gpx'))
  53. GM.registerMenuCommand('Download kml', () => startDownload('kml'))
  54. }
  55.  
  56. const buttonGroup = document.querySelector('[class*=ButtonGroup_root]')
  57.  
  58. const aGPX = document.createElement('a')
  59. aGPX.id = 'script_gpx_button'
  60. aGPX.href = '#'
  61. aGPX.textContent = 'GPX'
  62. aGPX.addEventListener('click', function (ev) {
  63. if (!('ready' in this.dataset)) {
  64. ev.preventDefault()
  65. startDownload('gpx', this)
  66. }
  67. })
  68. aGPX.className = buttonGroup.querySelector('a').className
  69. buttonGroup.appendChild(aGPX)
  70.  
  71. const aKML = document.createElement('a')
  72. aKML.href = '#'
  73. aKML.textContent = 'KML'
  74. aKML.addEventListener('click', function (ev) {
  75. if (!('ready' in this.dataset)) {
  76. ev.preventDefault()
  77. startDownload('kml', this)
  78. }
  79. })
  80. aKML.className = buttonGroup.querySelector('a').className
  81. buttonGroup.appendChild(aKML)
  82. }
  83.  
  84. function downloadUrl (url, title, ext, button) {
  85. if (button) {
  86. button.href = url
  87. button.style.color = 'green'
  88. button.dataset.ready = 1
  89. button.target = '_blank'
  90. window.setTimeout(() => button.click(), 100)
  91. } else {
  92. document.location.href = url
  93. }
  94. }
  95.  
  96. function startDownload (key, button) {
  97. const routeId = parseInt(document.location.href.match(/\/r\/(\d+)/)[1])
  98. GM.xmlHttpRequest({
  99. method: 'GET',
  100. url: `https://www.bikemap.net/api/v5/routes/${routeId}/`,
  101. headers: {
  102. 'x-requested-with': 'XMLHttpRequest'
  103. },
  104. onload: function (resp) {
  105. const routeData = JSON.parse(resp.responseText)
  106.  
  107. if (key in routeData) {
  108. downloadUrl(routeData[key], routeData.title, key, button)
  109. } else {
  110. let msg = 'There was an error. Make sure you are logged in (free bikemape account).'
  111. if ('detail' in routeData) {
  112. msg += '\n\nTechnical details:\n' + routeData.detail
  113. }
  114. window.alert(msg)
  115. }
  116. },
  117. onerror: function (response) {
  118. window.alert('Error:' + response.status)
  119. }
  120. })
  121. }
  122. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址