WME Add Uturns from node

Add uturns from node

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==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();