WME Export Trajet

Export GPS point of your trajets.

当前为 2015-12-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name             WME Export Trajet
// @name:fr          WME Export Trajet
// @version          0.2
// @description      Export GPS point of your trajets.
// @description:fr   Export des coordonée GPS de vos trajet.
// @include          https://www.waze.com/editor/*
// @include          https://www.waze.com/*/editor/*
// @include          https://editor-beta.waze.com/*
// @author           seb-d59
// @copyright        seb-d59 - 2015
// @namespace https://greasyfork.org/users/6419
// ==/UserScript==


//function WMEExpT_Injected(){

// valable sans injection....
  var WMEExpT_Version = GM_info.script.version;
  var WMEExpT_Name = GM_info.script.name;

//var WMEExpT_Version = 0.2;
//var WMEExpT_Name = "WME Export Trajet";

var WMEExpT = {};
var icon_export="iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3w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gApQAaoUoAIMSC7WA/M2vPFVk2zSseYCYD8b3vimCeB4rxHrAmC/G94EEe4Sn4zRJPK3RrbhjWPVyJo5W6P2QNMNb3zVIvAAaNi6faHE1iqZ/nyNxm/UEhZ+/DhJcwAAAABJRU5ErkJggg==";
var lang={};  
WMEExpT.Trajets = {'list': {},'objects':{}};

var debug=true;

// *********************
// ** HELPER FUNCTION **
// *********************

function log(msg, obj)
{
    if (obj === undefined)
        console.log(WMEExpT_Name + " v" + WMEExpT_Version + " - " + msg);
    else if (debug) 
        console.debug(WMEExpT_Name + " v" + WMEExpT_Version + " - " + msg + " " ,obj);
}

function getId(node) {
    return document.getElementById(node);
}
function getElementsByClassName(classname, node) {
    node || (node = document.getElementsByTagName("body")[0]);
    for (var a = [], re = new RegExp("\\b" + classname + "\\b"), els = node.getElementsByTagName("*"), i = 0, j = els.length;i < j;i++) {
        re.test(els[i].className) && a.push(els[i]);
    }
    return a;
}
function getFunctionWithArgs(func, args) {
    return (
        function () {
            var json_args = JSON.stringify(args);
            return function() {
                var args = JSON.parse(json_args);
                func.apply(this, args);
            };
        }
    )();
}
function IsJsonString(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}
function saveOption(){
	localStorage.setItem('WMEExportTrajet', JSON.stringify(WMEExpT));
}


// *************
// **  INIT   **
// *************
function WMEExpT_bootstrap() {
    if (typeof unsafeWindow === "undefined") {
        unsafeWindow    = ( function () {
            var dummyElem = document.createElement('p');
            dummyElem.setAttribute('onclick', 'return window;');
            return dummyElem.onclick();
        }) ();
    }

    /* begin running the code! */
    log("starting");
    WMEExpT_init();
}


function WMEExpT_init(){
    // Waze object needed
    /*
    WMEExpTWaze = unsafeWindow.Waze;
    if(typeof(WMEExpTWaze) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - WMEExpTWaze : NOK"); }
        window.setTimeout(WMEExpT_init, 500);
        return;
    }
    WMEExpTMap = WMEExpTWaze.map;
    if(typeof(WMEExpTMap) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - WMEExpTmap : NOK"); }
        window.setTimeout(WMEExpT_init, 500);
        return;
    }
    
    WMEExpTModel = WMEExpTWaze.model;
    if(typeof(WMEExpTModel) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - WMEExpTModel DOM : NOK"); }
        window.setTimeout(WMEExpT_init, 500);
        return;
    }
    
    //    OpenLayers
    WMEExpTOpenLayers = unsafeWindow.OpenLayers; 
    if(typeof(WMEExpTOpenLayers) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - OpenLayers : NOK"); }
        window.setTimeout(WMEExpT_init, 500);
        return;
    }
    */
    //    Traductions
    WMEExpTI18n = unsafeWindow.I18n.locale;
    if(typeof(WMEExpTI18n) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - WMEExpTI18n : NOK"); }
        setTimeout(WMEExpT_init, 500);
        return;
    }
    //    Waze GUI needed
    
    WMEExpT_userInfo = getId("user-info");
    if(typeof(WMEExpT_userInfo) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - WMEExpT_userInfo : NOK"); }
        setTimeout(WMEExpT_init, 500);
        return;
    }
    WMEExpT_navTabs = getElementsByClassName("nav-tabs", WMEExpT_userInfo)[0];
    if(typeof(WMEExpT_navTabs) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - WMEExpT_navTabs : NOK"); }
        setTimeout(WMEExpT_init, 500);
        return;
    }
    WMEExpT_tabContent = getElementsByClassName("tab-content", WMEExpT_userInfo)[0];
    if(typeof(WMEExpT_tabContent) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - WMEExpT_tabContent : NOK"); }
        setTimeout(WMEExpT_init, 500);
        return;
    }
    
    WMEExpTDrives = getId("sidepanel-drives");
    if(typeof(WMEExpTDrives) === 'undefined'){
        if (debug) { console.error("WME Export Trajet - WMEExpTDrives : NOK"); }
        setTimeout(WMEExpT_Main, 1000);
        return;
    }

    /*
    if (typeof(localStorage.WMEExportTrajets) !== "undefined") {
        localStorage.removeItem("WMEExportTrajets");
    }     
    if (typeof(sessionStorage.WMEExportTrajets) !== "undefined") {
        sessionStorage.removeItem("WMEExportTrajets");
    }
    */
    
    
    
    //======================================================

    // Translation
    if (WMEExpTI18n  == "fr") {
        lang = new Array("Export","Selectionnez le trajet");
    }
    else {
        lang = new Array("Export","Select the Drive");
    }
    
    log("init ok");
    
    // Then running
    WMEExpT_css(); 
    
}


// *************
// **  HTML   **
// *************

function WMEExpT_css() {
    var Scss = document.createElement("style");
    Scss.type = "text/css";
    var css =".CSETcontent {width:260px; margin-left:10px; box-shadow: 0 4px 10px #aaa;}";
    css +=".divl {float:left; text-align:center;}";
    css +=".divr {float:right; text-align:center;}";
    css +="#export {width:35px; height:22px;}";
    Scss.innerHTML = css;
    document.body.appendChild(Scss);    
    WMEExpT_html();
}


function WMEExpT_html() {
  var addon= document.createElement('div', "ExpT-cotent");
  var content = "<div style='float:left; margin-left:5px;'><b><a href='#' target='_blank'><u>"+ WMEExpT_Name +"</u></a></b> v"+ WMEExpT_Version +"</div><br>";
  content += "<div style='clear:both; padding-top:10px;'></div><div class='CSETcontent' >";
  content += "<div class='divl' style='width:240px; text-align:left;'><select id='selectTrajet' style='width:200px;'>";
  content +="<option value='0' id='0'>"+lang[1]+"</option>";
  content +="</select></div>";
  content += "<div class='divr' style='width:20px;'><a href='#' id='exportTrajet'><img style='width:20px;' title='"+ lang[0] +"' src='data:image/png;base64,"+ icon_export +"' /></a></div></div>";
  addon.innerHTML = content;
  WMEExpTDrives.appendChild(addon);  
  
  getId('selectTrajet').onfocus = updateTrajetsList;
  getId('selectTrajet').onchange = ExpTrajet;
  
}

function updateTrajetsList()
{
	var available_Trajets = getElementsByClassName('result session session-available');
  if(typeof(available_Trajets) === 'undefined'){
      if (debug) { console.error("WME Export Trajet - available_Trajets : NOK"); }
      return;
  }
  var selectTrajet = getId('selectTrajet');
	selectTrajet.options.length = 1;

    
	for (var i=0;i<available_Trajets.length;i++){
     
    var trajetID=  available_Trajets[i]['dataset'].id;
    var trajetDetail = available_Trajets[i].childNodes[1].childNodes[0].textContent;
    WMEExpT.Trajets.list[trajetID] = trajetDetail.replace(/,/g,'');
    
    var expTrOption = document.createElement('option');
	  var expTrText = document.createTextNode(WMEExpT.Trajets.list[trajetID]);
	  expTrOption.setAttribute('value','0');
	  expTrOption.setAttribute('id', trajetID);
	  expTrOption.appendChild(expTrText);
	  selectTrajet.appendChild(expTrOption);
  }

}

function ExpTrajet() {
  
  var selectTrajet = getId('selectTrajet');
  
  if (selectTrajet.selectedIndex <= 0)
    return;
    
	id = selectTrajet.options[selectTrajet.selectedIndex].id;
  
  if (id <= 0)
    return;

  if (!WMEExpT.Trajets.objects.hasOwnProperty(id)) {
  		
    var url = "https://www.waze.com/row-Descartes-live/app/Archive/Session?id="+id;
    
    RequestObject = window.ActiveXObject
                          // ? new ActiveXObject("Microsoft.XMLHTTP") 
                          ? new ActiveXObject("Msxml2.XMLHTTP") 
                         : new XMLHttpRequest();
    RequestObject.onreadystatechange = function()
    {   
    	if(RequestObject.readyState == 4) {
    		var resultRequest={};
        resultRequest = JSON.parse(RequestObject.responseText);
    		WMEExpT.Trajets.objects[id] = resultRequest.archiveSessions.objects[0];
    		log('New data download link ok: '+ WMEExpT.Trajets.list[id]+'; id= '+ id);
    		//log('WMEExpT.Trajets.objects['+id+'].data',WMEExpT.Trajets.objects[id].data);
    		getId('exportTrajet').setAttribute('download',  WMEExpT.Trajets.list[id]+ '.xml');
    		getId('exportTrajet').href='data:Application/octet-stream,' + encodeURIComponent(WMEExpT.Trajets.objects[id].data);
    		//getId('exportTrajet').href='data:application/octet-stream;charset=utf-8;' + WMEExpT.Trajets.objects[id].data;

      }
    };
	  RequestObject.open("GET", url,false); 
	  RequestObject.send(null);
	}else {
	  log('data download link ok: '+ WMEExpT.Trajets.list[id]+'; id= '+ id);
	  getId('exportTrajet').setAttribute('download',  WMEExpT.Trajets.list[id]+ '.xml');
		getId('exportTrajet').href='data:Application/octet-stream,' + encodeURIComponent(WMEExpT.Trajets.objects[id].data);
		//getId('exportTrajet').href='data:application/octet-stream;charset=utf-8;' + WMEExpT.Trajets.objects[id].data;

	}

}


/* begin running the code! */
WMEExpT_bootstrap    ();

/*}

var WMEExpT_Injected_script = document.createElement("script");
WMEExpT_Injected_script.textContent = '' + WMEExpT_Injected.toString() + ' \n' + 'WMEExpT_Injected();';
WMEExpT_Injected_script.setAttribute("type", "application/javascript");
document.body.appendChild(WMEExpT_Injected_script);
*/