Advertisement
Guest User

gc-sensorinfo

a guest
Mar 10th, 2021
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getGCSensors() {
  2.     // get sleep data from garmin connect
  3.     let loc = window.location.href
  4.  
  5.     let connectURL = "https://connect.garmin.com/modern/activity/";
  6.     if (loc.indexOf(connectURL) != 0 || typeof jQuery === "undefined") {
  7.         alert(
  8. `You must be logged into Garmin Connect to run this script.
  9.  
  10. (Your current tab must also be a Garmin Connect activity page with
  11. URL starting with: ${connectURL})`);
  12.         return;
  13.     }
  14.  
  15.     // Garmin Connect uses jQuery, so it's available for this script
  16.     jQuery("#_gc-sensordata_modal").remove();
  17.  
  18.     const activityId = loc.replace(connectURL, "");
  19.  
  20.     let xhr = new XMLHttpRequest();
  21.     xhr.open('GET', `https://connect.garmin.com/modern/proxy/activity-service/activity/${activityId}`);
  22.     xhr.setRequestHeader("NK", "NT")
  23.     xhr.onload = function () {
  24.         let obj = JSON.parse(xhr.response)
  25.         let output = JSON.stringify(obj.metadataDTO.sensors, null, 2);
  26.         addDialog(output)
  27. };
  28.     xhr.send()
  29.  
  30.     function addDialog(output) {
  31.         addCSS();
  32.         jQuery("#_gc-sensordata_modal").remove();
  33.         jQuery('body').append(`
  34.             <div id="_gc-sensordata_modal" class="_gc-sensordata-modalDialog">
  35.                 <div><a href="#" title="Close" id="_gc-sensordata-close" class="_gc-sensordata-close">X</a>
  36.    
  37.                         <h2>Activity Sensors Info</h2>
  38.    
  39.                     <textarea readonly id="_gc-sensordata_textarea" rows="20" style="width:100%" spellcheck="false"
  40.                     >${output}</textarea>
  41.                     <br>
  42.                     <br>
  43.                     <button class="_gc-sensordata-btn" id="_gc-sensordata_copy">Copy to Clipboard</button>
  44.                     <span id="_gc-sensordata-copied" style="display:none">Sensor data copied to clipboard 👍</span>
  45.                 </div>
  46.             </div>
  47.     `);
  48.         jQuery("#_gc-sensordata-close").click(function() {
  49.             jQuery("#_gc-sensordata_modal").remove();
  50.             return false;
  51.         });
  52.         jQuery("#_gc-sensordata_copy").click(function() {
  53.             let el = document.getElementById("_gc-sensordata_textarea");
  54.             el.select();
  55.             document.execCommand('copy');
  56.             jQuery("#_gc-sensordata-copied").show();
  57.             return false;
  58.         });
  59.     }
  60.  
  61.     function addCSS() {
  62.         // based on https://jsfiddle.net/kumarmuthaliar/GG9Sa/1/
  63.         let styles = `
  64.     ._gc-sensordata-modalDialog {
  65.         position: fixed;
  66.         font-family: Arial, Helvetica, sans-serif;
  67.         top: 0;
  68.         right: 0;
  69.         bottom: 0;
  70.         left: 0;
  71.         background: rgba(0, 0, 0, 0.8);
  72.         z-index: 99999;
  73.         // opacity:0;
  74.         -webkit-transition: opacity 400ms ease-in;
  75.         -moz-transition: opacity 400ms ease-in;
  76.         transition: opacity 400ms ease-in;
  77.     }
  78.    
  79.     ._gc-sensordata-modalDialog > div {
  80.         width: 400px;
  81.         position: relative;
  82.         margin: 10% auto;
  83.         padding: 5px 20px 13px 20px;
  84.         border-radius: 10px;
  85.         background: #eee;
  86.         /*background: -moz-linear-gradient(#fff, #999);
  87.         background: -webkit-linear-gradient(#fff, #999);
  88.         background: -o-linear-gradient(#fff, #999);*/
  89.     }
  90.     ._gc-sensordata-close {
  91.         background: #606061;
  92.         color: #FFFFFF;
  93.         line-height: 25px;
  94.         position: absolute;
  95.         right: -12px;
  96.         text-align: center;
  97.         top: -10px;
  98.         width: 24px;
  99.         text-decoration: none;
  100.         font-weight: bold;
  101.         -webkit-border-radius: 12px;
  102.         -moz-border-radius: 12px;
  103.         border-radius: 12px;
  104.         -moz-box-shadow: 1px 1px 3px #000;
  105.         -webkit-box-shadow: 1px 1px 3px #000;
  106.         box-shadow: 1px 1px 3px #000;
  107.     }
  108.     ._gc-sensordata-close:hover {
  109.         background: #00d9ff;
  110.     }
  111.    
  112.     ._gc-sensordata-btn {
  113.         color: #fff;
  114.         background-color: #337ab7;
  115.         border-color: #2e6da4;
  116.    
  117.         display: inline-block;
  118.         margin-bottom: 0;
  119.         font-weight: 400;
  120.         text-align: center;
  121.         white-space: nowrap;
  122.         vertical-align: middle;
  123.         -ms-touch-action: manipulation;
  124.         touch-action: manipulation;
  125.         cursor: pointer;
  126.         background-image: none;
  127.         border: 1px solid transparent;
  128.         border-top-color: transparent;
  129.         border-right-color: transparent;
  130.         border-bottom-color: transparent;
  131.         border-left-color: transparent;
  132.         padding: 6px 12px;
  133.         font-size: 14px;
  134.         line-height: 1.42857143;
  135.         border-radius: 4px;
  136.     }
  137.     `
  138.    
  139.         jQuery("#_gc-sensordata_styles").remove();
  140.         let styleSheet = document.createElement("style")
  141.         styleSheet.type = "text/css"
  142.         styleSheet.id = "_gc-sensordata_styles"
  143.         styleSheet.innerText = styles
  144.         document.head.appendChild(styleSheet);
  145.    
  146.     }    
  147. }
  148.  
  149. getGCSensors();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement