WME Add Uturns from node

Add uturns from node

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         WME Add Uturns from node
// @version      0.1
// @description  Add uturns from node
// @author       ixxvivxxi
// @include      https://www.waze.com/editor/*
// @include      https://www.waze.com/*/editor/*
// @include      https://editor-beta.waze.com/editor/*
// @include      https://editor-beta.waze.com/*/editor/*
// @grant        none
// @namespace    https://greasyfork.org/ru/scripts/16950-wme-add-uturns-from-node

// ==/UserScript==

function Uturns_bootstrap()
{
	var bGreasemonkeyServiceDefined = false;

	try
	{
		if ("object" === typeof Components.interfaces.gmIGreasemonkeyService)
		{
			bGreasemonkeyServiceDefined = true;
		}
	}
	catch (err)
	{
		//Ignore.
	}
	if ( "undefined" === typeof unsafeWindow  ||  ! bGreasemonkeyServiceDefined)
	{
		unsafeWindow    = ( function ()
		{
			var dummyElem   = document.createElement('p');
			dummyElem.setAttribute ('onclick', 'return window;');
			return dummyElem.onclick ();
		} ) ();
	}
	/* begin running the code! */
	setTimeout(startUturns,999);
}
function startUturns() {

    Waze.selectionManager.events.register("selectionchanged", null, showButton);
    var wazeActionModifyConnection= require("Waze/Action/ModifyConnection")
  

    function showButton() {
        if(Waze.selectionManager.selectedItems.length == 0 || Waze.selectionManager.selectedItems.length > 1) return;
        if(Waze.selectionManager.selectedItems[0].model.type == "node") {

           $('.side-panel-section:first-child').append('<button id="addUturns" class="btn btn-default">add uturns</button>');
        }

    }

  $('#sidebar').on('click', '#addUturns', function(event) {
      var node = Waze.selectionManager.selectedItems[0].model;
      var segIDs = node.attributes.segIDs;
      
      for (var i = 0; i < segIDs.length; i++) {
          var segment = Waze.model.segments.objects[segIDs[i]];
          
          if (segment.attributes.fromNodeID == node.attributes.id) {
              console.log('А', segment.attributes.id);
              
              segment.attributes.fromConnections[segment.attributes.id] = true;
              Waze.model.actionManager.add(new wazeActionModifyConnection(segment.attributes.id, segment.getFromNode(), segment.attributes.id,segment.getFromNode()));
          } else {
              console.log('B', segment.attributes.id);
              segment.attributes.toConnections[segment.attributes.id] = true;
              Waze.model.actionManager.add(new wazeActionModifyConnection(segment.attributes.id, segment.getToNode(), segment.attributes.id, segment.getToNode()));
          }

      }

  });


}

Uturns_bootstrap();