Fix Gaia updater CDATA extraction

This commit is contained in:
2022-02-07 23:14:22 +01:00
parent b9a63caa2a
commit ff403d2cdb

View File

@@ -3,7 +3,7 @@
// @namespace https://greasyfork.org/users/583371 // @namespace https://greasyfork.org/users/583371
// @description Allow the user to upload multiple files at once and more than 1000 waypoints // @description Allow the user to upload multiple files at once and more than 1000 waypoints
// @grant none // @grant none
// @version 3.1.1 // @version 3.1.2
// @author Franzz // @author Franzz
// @license GNU GPLv3 // @license GNU GPLv3
// @match https://www.gaiagps.com/map/* // @match https://www.gaiagps.com/map/*
@@ -213,12 +213,18 @@ gpxParser.prototype.parse = function (gpxstring) {
gpxParser.prototype.getElementValue = function(parent, needle){ gpxParser.prototype.getElementValue = function(parent, needle){
let elem = parent.querySelector(needle); let elem = parent.querySelector(needle);
if(elem != null){ if(elem != null){
return elem.innerHTML != undefined ? elem.innerHTML : elem.childNodes[0].data; //Get value (in case of CDATA)
let sValue = (elem.innerHTML != undefined && elem.innerHTML.substring(0, 8) != '<![CDATA') ? elem.innerHTML : elem.childNodes[0].data;
//If decoded HTML, re-encode
if(sValue.substr(0, 4)== '&lt;') sValue = $('<div>').html(sValue).text();
//Strip HTML tags & trim value
return $('<div>').html(sValue).text().trim();
} }
return elem; return elem;
}; };
/** /**
* Search the value of a direct child XML DOM element * Search the value of a direct child XML DOM element
* *
@@ -252,6 +258,10 @@ class Gaia {
static get API() { return Gaia.URL+'/api/objects'; } static get API() { return Gaia.URL+'/api/objects'; }
constructor() { constructor() {
this.reset();
}
reset() {
this.asFiles = []; this.asFiles = [];
this.aoWaypoints = []; this.aoWaypoints = [];
this.aoTracks = []; this.aoTracks = [];
@@ -260,6 +270,7 @@ class Gaia {
} }
setLayout() { setLayout() {
this.reset();
/* FIXME: adapts on GaiaGPS upgrade */ /* FIXME: adapts on GaiaGPS upgrade */
let $InputButton = $('a[href="https://help.gaiagps.com/hc/en-us/articles/360052763513"]').parent().find('button'); let $InputButton = $('a[href="https://help.gaiagps.com/hc/en-us/articles/360052763513"]').parent().find('button');
@@ -389,7 +400,7 @@ class Gaia {
this.asFolders[oFileReader.name] = {}; this.asFolders[oFileReader.name] = {};
if(iCount == this.asFiles.length) { if(iCount == this.asFiles.length) {
this.progress.total = this.aoTracks.length + this.aoWaypoints.length + this.asFiles.length * 2; //2 extra actions per file: Create folder + Assign objects to folder this.progress.total = this.aoTracks.length + this.aoWaypoints.length + this.asFiles.length; //extra action per file: Create folder
this.createFolders(); this.createFolders();
} }
}; };
@@ -718,40 +729,42 @@ class Gaia {
static getIconName(sGarminName) { static getIconName(sGarminName) {
var asMapping = { var asMapping = {
'Trail Head': 'trailhead', 'Bridge': 'bridge',
'Water Source': 'water-24.png', 'Campground': 'campsite-24',
'Truck': 'car-24.png', 'Car': 'car-24',
'Post Office': 'resupply', 'Cemetery': 'cemetery-24',
'Flag, Blue': 'blue-pin-down.png', 'Church': 'ghost-town',
'Car': 'car-24.png', 'City (Capitol)': 'city-24',
'Flag, Red': 'red-pin-down.png', 'Convenience Store': 'market',
'Campground': 'campsite-24.png',
'Flag, Green': 'green-pin.png',
'Powerline': 'petroglyph',
'Shopping Center': 'cafe-24.png',
'Lodging': 'lodging-24.png',
'Water Hydrant': 'red-pin-down.png',
'Drinking Water': 'potable-water', 'Drinking Water': 'potable-water',
'Toll Booth': 'ranger-station', 'Flag, Blue': 'blue-pin-down',
'Summit': 'peak', 'Flag, Green': 'green-pin',
'Park': 'park-24.png', 'Flag, Red': 'red-pin-down',
'Forest': 'forest', 'Forest': 'forest',
'Cemetery': 'cemetery-24.png', 'Ground Transportation': 'car-24',
'Bridge': 'dam-24.png', 'Lodging': 'lodging-24',
'Restaurant': 'restaurant-24.png', 'Park': 'park-24',
'Pharmacy': 'hospital-24',
'Picnic Area': 'picnic', 'Picnic Area': 'picnic',
'Residence': 'city-24.png', 'Post Office': 'resupply',
'City (Capitol)': 'city-24.png', 'Powerline': 'petroglyph',
'Ski Resort': 'skiing-24.png', 'Residence': 'building-24',
'Restroom': 'toilets-24.png', 'Restaurant': 'restaurant-24',
'Ground Transportation': 'car-24.png', 'Restroom': 'toilets-24',
'Church': 'ghost-town' 'Shopping Center': 'market',
'Ski Resort': 'skiing-24',
'Summit': 'peak',
'Toll Booth': 'ranger-station',
'Trail Head': 'known-route',
'Truck': 'car-24',
'Water Source': 'water-24'
}; };
return (sGarminName in asMapping)?asMapping[sGarminName]:'red-pin-down.png'; return (sGarminName in asMapping)?asMapping[sGarminName]:'red-pin-down';
} }
} }
console.log('Loading GaiaGps Uploader 3.1.1'); console.log('Loading GaiaGps Uploader '+GM_info.script.version);
let oGaia = new Gaia(); let oGaia = new Gaia();
MutationObserver = window.MutationObserver || window.WebKitMutationObserver; MutationObserver = window.MutationObserver || window.WebKitMutationObserver;