Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getGCSensors() {
- // get sleep data from garmin connect
- let loc = window.location.href
- let connectURL = "https://connect.garmin.com/modern/activity/";
- if (loc.indexOf(connectURL) != 0 || typeof jQuery === "undefined") {
- alert(
- `You must be logged into Garmin Connect to run this script.
- (Your current tab must also be a Garmin Connect activity page with
- URL starting with: ${connectURL})`);
- return;
- }
- // Garmin Connect uses jQuery, so it's available for this script
- jQuery("#_gc-sensordata_modal").remove();
- const activityId = loc.replace(connectURL, "");
- let xhr = new XMLHttpRequest();
- xhr.open('GET', `https://connect.garmin.com/modern/proxy/activity-service/activity/${activityId}`);
- xhr.setRequestHeader("NK", "NT")
- xhr.onload = function () {
- let obj = JSON.parse(xhr.response)
- let output = JSON.stringify(obj.metadataDTO.sensors, null, 2);
- addDialog(output)
- };
- xhr.send()
- function addDialog(output) {
- addCSS();
- jQuery("#_gc-sensordata_modal").remove();
- jQuery('body').append(`
- <div id="_gc-sensordata_modal" class="_gc-sensordata-modalDialog">
- <div><a href="#" title="Close" id="_gc-sensordata-close" class="_gc-sensordata-close">X</a>
- <h2>Activity Sensors Info</h2>
- <textarea readonly id="_gc-sensordata_textarea" rows="20" style="width:100%" spellcheck="false"
- >${output}</textarea>
- <br>
- <br>
- <button class="_gc-sensordata-btn" id="_gc-sensordata_copy">Copy to Clipboard</button>
- <span id="_gc-sensordata-copied" style="display:none">Sensor data copied to clipboard 👍</span>
- </div>
- </div>
- `);
- jQuery("#_gc-sensordata-close").click(function() {
- jQuery("#_gc-sensordata_modal").remove();
- return false;
- });
- jQuery("#_gc-sensordata_copy").click(function() {
- let el = document.getElementById("_gc-sensordata_textarea");
- el.select();
- document.execCommand('copy');
- jQuery("#_gc-sensordata-copied").show();
- return false;
- });
- }
- function addCSS() {
- // based on https://jsfiddle.net/kumarmuthaliar/GG9Sa/1/
- let styles = `
- ._gc-sensordata-modalDialog {
- position: fixed;
- font-family: Arial, Helvetica, sans-serif;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- background: rgba(0, 0, 0, 0.8);
- z-index: 99999;
- // opacity:0;
- -webkit-transition: opacity 400ms ease-in;
- -moz-transition: opacity 400ms ease-in;
- transition: opacity 400ms ease-in;
- }
- ._gc-sensordata-modalDialog > div {
- width: 400px;
- position: relative;
- margin: 10% auto;
- padding: 5px 20px 13px 20px;
- border-radius: 10px;
- background: #eee;
- /*background: -moz-linear-gradient(#fff, #999);
- background: -webkit-linear-gradient(#fff, #999);
- background: -o-linear-gradient(#fff, #999);*/
- }
- ._gc-sensordata-close {
- background: #606061;
- color: #FFFFFF;
- line-height: 25px;
- position: absolute;
- right: -12px;
- text-align: center;
- top: -10px;
- width: 24px;
- text-decoration: none;
- font-weight: bold;
- -webkit-border-radius: 12px;
- -moz-border-radius: 12px;
- border-radius: 12px;
- -moz-box-shadow: 1px 1px 3px #000;
- -webkit-box-shadow: 1px 1px 3px #000;
- box-shadow: 1px 1px 3px #000;
- }
- ._gc-sensordata-close:hover {
- background: #00d9ff;
- }
- ._gc-sensordata-btn {
- color: #fff;
- background-color: #337ab7;
- border-color: #2e6da4;
- display: inline-block;
- margin-bottom: 0;
- font-weight: 400;
- text-align: center;
- white-space: nowrap;
- vertical-align: middle;
- -ms-touch-action: manipulation;
- touch-action: manipulation;
- cursor: pointer;
- background-image: none;
- border: 1px solid transparent;
- border-top-color: transparent;
- border-right-color: transparent;
- border-bottom-color: transparent;
- border-left-color: transparent;
- padding: 6px 12px;
- font-size: 14px;
- line-height: 1.42857143;
- border-radius: 4px;
- }
- `
- jQuery("#_gc-sensordata_styles").remove();
- let styleSheet = document.createElement("style")
- styleSheet.type = "text/css"
- styleSheet.id = "_gc-sensordata_styles"
- styleSheet.innerText = styles
- document.head.appendChild(styleSheet);
- }
- }
- getGCSensors();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement