WME GetNodeID

Gives NodeID of selected segments

目前為 2015-05-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name                WME GetNodeID
// @namespace           Fafa114
// @description         Gives NodeID of selected segments
// @include             https://www.waze.com/editor/*
// @include             https://www.waze.com/*/editor/*
// @version             0.2
// @grant               na
// ==/UserScript==

if ('undefined' == typeof __RTLM_PAGE_SCOPE_RUN__) {
	(function page_scope_runner() {
		var my_src = "(" + page_scope_runner.caller.toString() + ")();"; // If we're _not_ already running in the page, grab the full source of this script.

		// Create a script node holding this script, plus a marker that lets us know we are running in the page scope (not the Greasemonkey sandbox).
		// Note that we are intentionally *not* scope-wrapping here.
		var script = document.createElement('script');
		script.setAttribute("type", "text/javascript");
		script.textContent = "var __RTLM_PAGE_SCOPE_RUN__ = true;\n" + my_src;

		// Insert the script node into the page, so it will run, and immediately remove it to clean up.  Use setTimeout to force execution "outside" of the user script scope completely.
		setTimeout(function() {
			document.body.appendChild(script);
			document.body.removeChild(script);
		}, 0);
	})();
	return; // Stop running, because we know Greasemonkey actually runs us in an anonymous wrapper.
}

function bootstrap(){
	if (typeof(unsafeWindow) === "undefined"){
		unsafeWindow = ( function () {
			var dummyElem = document.createElement('p');
			dummyElem.setAttribute('onclick', 'return window;');
			return dummyElem.onclick();
		}) ();
	}
	/* begin running the code! */
	setTimeout(init, 700);
}

function NodesID() {
	var Nbr = Waze.selectionManager.selectedItems.length;
	var NbrSeg = 0;
	var Texte = "";
	var Mem = [];
	if (Nbr > 0) {
        for(i = 0; i<Nbr; i++){ 
        	if (Waze.selectionManager.selectedItems[i].model.type == "segment") { 
				var TrouveFrom = false;
				var TrouveTo = false;
				for(u = 0; u<Mem.length; u++){
					if (Waze.selectionManager.selectedItems[i].model.attributes.fromNodeID == Mem[u]){
						TrouveFrom = true;
					}
					if (Waze.selectionManager.selectedItems[i].model.attributes.toNodeID == Mem[u]){
						TrouveTo = true;
					}
				}
				if (TrouveFrom == false){
					Mem[Mem.length] = Waze.selectionManager.selectedItems[i].model.attributes.fromNodeID;
					if (i == 0){
						Texte = Waze.selectionManager.selectedItems[i].model.attributes.fromNodeID;
					}else{
						Texte = Texte + ', ' + Waze.selectionManager.selectedItems[i].model.attributes.fromNodeID;
					}
				}
				if (TrouveTo == false){
					Mem[Mem.length] = Waze.selectionManager.selectedItems[i].model.attributes.toNodeID;
					Texte = Texte + ', ' + Waze.selectionManager.selectedItems[i].model.attributes.toNodeID;
				}
				NbrSeg++;
			}
		}
        if (NbrSeg > 0) {
			segeditgen = document.getElementById("segment-edit-general");
			segextra = document.getElementById("segment-extra-details");
			if (!segextra) {
				segextra = document.createElement('div');
				segextra.id = 'segment-extra-details';
				segeditgen.appendChild(segextra);
			}

			segextra.innerHTML = '<div{width:20px;}><B>WME GetNodeID</B><br>Segment(s) sélectionné(s) : ' + NbrSeg + '<br><br>Liste des IDs de Noeuds:<br><wbr>' + Texte + '</wbr></div>';
			$("#sidebar").animate({ scrollTop: $("#sidebar").offset().top + 5000 }, 1); //5000 pour être sûr d'être tout en bas...
    	}
  	}
  	return true;
}

function init(){
	Waze = unsafeWindow.Waze;
	if(typeof(Waze) == 'undefined'){
		window.setTimeout(init, 700);
		return;
	}
	Waze.selectionManager.events.register("selectionchanged", null, NodesID);
	NodesID(); // exécution de la fonction dès le lancement du script pour fonctionnement avec un permalink
}

bootstrap();