WME Map Tiles Update

Show the last server update

当前为 2014-08-10 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        WME Map Tiles Update
// @version     0.61
// @description Show the last server update
// @namespace   Sebiseba
// @include     https://www.waze.com/editor/*
// @include     https://www.waze.com/*/editor/*
// @include     https://editor-beta.waze.com/*
// @grant       GM_xmlhttpRequest
// @copyright   Sebiseba 2014
// ==/UserScript==

WME_MUpdate_Version = GM_info.script.version;
	
/**
	Thanks to dummyd2 and Myriades for their help and optimizations
**/

/* helper function */

function getId(node) {
  return document.getElementById(node);
}

function getElementsByClassName(classname, node) {
  if(!node) node = document.getElementsByTagName("body")[0];
  var a = [];
  var re = new RegExp('\\b' + classname + '\\b');
  var els = node.getElementsByTagName("*");
  for (var i=0,j=els.length; i<j; i++)
    if (re.test(els[i].className)) a.push(els[i]);
  return a;
}

function translate_server(lang){
    var elt="", trad = new Array(
	"en","SERVEUR",
	"en-GB","SERVEUR",
	"es","SERVIDOR",
	"es-419","SERVIDOR",
	"fr","SERVER",
	"it","SERVER",
	"ru","сервер",
	"ja","サーバー",
	"he","שרת",
	"de","SERVER",
	"ro","SERVER",
	"tr","SUNUCU",
	"af","BEDIENER",
	"cs","SERVER",
	"ko","서버",
	"ms","SERVER",
	"pl","SERWER",
	"pt-BR","SERVIDOR",
	"pt-PT","SERVIDOR",
	"hu","SZERVER",
	"nl","SERVER",
	"sv","SERVER",
	"no","SERVER",
	"sk","SERVERA",
	"da","SERVER",
	"gl","GWEINYDDWR",
	"lt","SERVERIS",
	"zh","SERVER",
	"bg","СЪРВЪРА",
	"fi","SERVER",
	"hr","SERVER"
	);
	
    var i=-1;
	for(elt in trad){
   		i++;
		if (trad[elt]==lang){ 
            return trad[i+1];
        }
	}
    return "SERVER";
}

function translate(str) { 
  var UKdate=new Array('january','february','march','april','may','june','july','august','september','october','december');
  var FRdate=new Array('janvier','février','mars','avril','mai','juin','juillet','août','septembre','octobre','decembre');
    for (var i=0; i<UKdate.length; i++) { 
     str = str.toLowerCase().replace(UKdate[i], FRdate[i]); 
  } 
  return str; 
}

/* Bootstrap */

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

  /* begin running the code! */

    console.log("WME Map Tiles Update: " + WME_MUpdate_Version + " starting");
    MTUinit();
}

/* Verif */

function MTUinit(){
	// Waze object needed
	MTUWaze = unsafeWindow.Waze;
	if(typeof(MTUWaze) === 'undefined'){
        console.error("WME Map Tiles Update - MTUWaze : NOK");
		window.setTimeout(MTUinit, 500);
		return;
	}
 	MTUlocation = MTUWaze.location;
	if(typeof(MTUlocation) === 'undefined'){
        console.error("WME Map Tiles Update - MTUlocation : NOK");
		window.setTimeout(MTUinit, 500);
		return;
	}    
    //    Traductions
     MTUI18n = unsafeWindow.I18n;
    if(typeof(MTUI18n) === 'undefined'){
        console.error("WME Map Tiles Update - MTUI18n : NOK");
        setTimeout(MTUinit, 500);
        return;
    }  
	//	Waze GUI needed
   MTUhandle = getId('user-details');
    if(typeof(MTUhandle) === 'undefined'){
        console.error("WME Map Tiles Update - MTUhandle : NOK");
        setTimeout(MTUinit, 500);
        return;
    }
   MTUhandleClass = getElementsByClassName('points', MTUhandle)[0];
    if(typeof(MTUhandleClass) === 'undefined'){
        console.error("WME Map Tiles Update - MTUhandleClass : NOK");
        setTimeout(MTUinit, 500);
        return;
    }
    //	Then running
	MTUhandle.innerHTML = MTUhandle.innerHTML + "<div id='MTUpdate' style='margin-right:15px; margin-bottom:40px;  span-size:15px;'></div>";
    console.log("WME Map Tiles Update - Div container ok ");
	Back_Info();
}

/* Script */

function Back_Info() {
    // Detect Country Server (World/US/Israel)
 	var MTUenv = MTUlocation.code;
    console.info("WME Map Tiles Update - Serveur : " + MTUenv);
    var url = '';
    switch(MTUenv){
        case "row":
            url = "http://status.waze.com/category/main/international-tile-updates/";
            break;
        case 'usa':
            url = "http://status.waze.com/category/main/north-america-tile-updates/";
            break;
        case 'il':
            url = "http://status.waze.com/category/main/israel-tile-updates/";
            break;
    }
    
    //Request
    if(url.length > 0){
        var ret = GM_xmlhttpRequest( {
			method:		"GET",
			url:		url,
			headers:	{ "Accept": "text/xml" },
        	onerror:    function(r) { console.log("WME Map Tiles Update: Error: " + r); },
        	onload:		function(r) { 
            	// Last update
            	var MTUposStart = r.responseText.indexOf("successfully-updated-to-");
                var MTUposEnd = r.responseText.indexOf("vcard");
                var MTULastUpdate = r.responseText.substring(MTUposStart,MTUposEnd);
            	var MTUDate = MTULastUpdate.split(new RegExp("[ /;]+", "g"));
            	var MTUlastdate = MTUDate[0].substring(24);
            	var MTUdate = MTUlastdate.split('-');
            
            	// When
            	var MTUpos2 = MTULastUpdate.indexOf("datetime"); 
            	var MTUDate2 = MTULastUpdate	.substring(MTUpos2).split(new RegExp("[>;]+", "g"));
            	MTUDate2 = MTUDate2[1].split(new RegExp("[<;]+", "g"));
            	var MTUdate2 = MTUDate2[0].split(' ');
            
				// Detect Language
				var MTULang = MTUI18n.locale;
				console.info("WME Map Tiles Update - Langue: " + MTULang);
				
   				// add to User Details panel

				if (MTULang == "fr") { var serv=translate_server(MTULang), txt1 ="Mis &agrave; jour jusqu'au", txt2="Fait le", date1=MTUdate[1] + " " + translate(MTUdate[0]) + " " + MTUdate[2], date2=MTUdate2[1].replace(',','') + " " + translate(MTUdate2[0]) + " " + MTUdate2[2]; }
            	else { var serv=translate_server(MTULang), txt1 ="Last update", txt2="Performed", date1=MTUdate[0] + " " + MTUdate[1] + ", " + MTUdate[2], date2=MTUdate2[0] + " " + MTUdate2[1] + " " + MTUdate2[2]; }
                    getId('MTUpdate').innerHTML = "<div style='float:left;'><b>" + serv + " : </b>" + MTUI18n.translations[MTULang].envs[MTUenv] +" </div>";
                	getId('MTUpdate').innerHTML = getId('MTUpdate').innerHTML + "<div style='float:right; display: inline;'> " + txt1 + " : <span style='color: #59899e; span-size:13px;'><a href='" + url + "' target='_blank' /><b>" + date1 + "</b></a></span></div>";
                getId('MTUpdate').innerHTML = getId('MTUpdate').innerHTML + "<div style='float:right; display: inline;'> " + txt2 + " : <span style='color: #59899e; span-size:13px;'><a href='" + url + "' target='_blank' /><b>" + date2 + "</b></a><br /></span></div><div style='clear:both;'></div>"; 
        	}
		} );
    }
    setTimeout(Back_Info, 1000*60*60);
}

/* begin running the code! */

MTUpdate_bootstrap();