WME E87 Inconsistent direction

Solves the inconsistent direction problem

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         WME E87 Inconsistent direction
// @name:uk      WME 🇺🇦 E87 Inconsistent direction
// @name:ru      WME 🇺🇦 E87 Inconsistent direction
// @version      0.2.2
// @description  Solves the inconsistent direction problem
// @description:uk Дозволяє вирішувати проблему різнонаправлених сегментів
// @description:ru Позволяет решить проблему разнонаправленных сегментов
// @license      MIT License
// @author       Anton Shevchuk
// @namespace    https://greasyfork.org/users/227648-anton-shevchuk
// @supportURL   https://github.com/AntonShevchuk/wme-template/issues
// @match        https://*.waze.com/editor*
// @match        https://*.waze.com/*/editor*
// @exclude      https://*.waze.com/user/editor*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAYqXpUWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYAAHja7ZtZlhu7smT/MYoaQqAHhoN2rZpBDb+2AcxOSt1zdPN9PqWSZDKC6Nzd3MwBmvX//u82/4d/xedkQswl1ZQe/oUaqmu8KM/9186jfcJ5PP/C6xJ/f3nfvF9wvOV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ICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgIAo8P3hwYWNrZXQgZW5kPSJ3Ij8+lrIRmQAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd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1ZUipSGoDnYaF+JifzMccZRUVFRUVFRUVFRUVlwfIbL4zT3SPCFmYAAAAASUVORK5CYII=
// @grant        none
// @require      https://update.greasyfork.org/scripts/389765/1090053/CommonUtils.js
// @require      https://update.greasyfork.org/scripts/450160/1704233/WME-Bootstrap.js
// @require      https://update.greasyfork.org/scripts/450221/1691071/WME-Base.js
// @require      https://update.greasyfork.org/scripts/450320/1688694/WME-UI.js
// ==/UserScript==

/* jshint esversion: 8 */

/* global require */
/* global $, jQuery */
/* global I18n */
/* global WMEBase */
/* global WMEUI, WMEUIHelper, WMEUIHelperPanel, WMEUIHelperModal, WMEUIHelperTab, WMEUIHelperFieldset */
/* global Container, Settings, SimpleCache, Tools  */
/* global Node$1, Segment, Venue, VenueAddress, WmeSDK */

(function () {
  'use strict'

  // Script name, uses as unique index
  const NAME = 'E87'

  // Translations
  const TRANSLATION = {
    'en': {
      title: 'Direction →',
      description: 'Plugin WME E87 solves the inconsistent direction problem.<br/>Choose one or more segment to change direction.',
      buttons: {
        toggle: 'Change direction',
        forward: 'A → B',
        reverse: 'B → A',
      },
    },
    'uk': {
      title: 'Напрямки →',
      description: 'Плагін WME E87 для вирішення проблеми різно направлених вулиць.<br/>Оберіть один або декілька сегментів щоб застосувати зміни.',
      buttons: {
        toggle: 'Змінити напрямок',
        forward: 'A → B',
        reverse: 'B → A',
      },
    },
    'ru': {
      title: 'Направления →',
      description: 'Плагин WME E87 для решения проблемы разнонаправленных улиц.<br/>Выберите один или несколько сегментов, чтобы внести изменения.',
      buttons: {
        toggle: 'Изменить направление',
        forward: 'A → B',
        reverse: 'B → A',
      },
    }
  }

  WMEUI.addTranslation(NAME, TRANSLATION)

  const STYLE =
    '.lanes-tab div.e87 { border: 1px solid var(--hairline); border-radius: 6px; margin-bottom: 16px; padding: 8px 16px 18px; } ' +
    'button.waze-btn.e87 { background: #f2f4f7; border: 1px solid #ccc; margin: 2px; } ' +
    'button.waze-btn.e87:hover { background: #ffffff; transition: background-color 100ms linear; box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1), inset 0 0 100px 100px rgba(255, 255, 255, 0.3); } ' +
    'button.waze-btn.e87:focus { background: #f2f4f7; } ' +
    'button.e87-forward, button.e87-reverse { margin: 2px 8px; }' +
    'div.e87-container { display: flex; flex: auto; justify-content: space-evenly; } ' +
    'p.e87-info { border-top: 1px solid #ccc; color: #777; font-size: x-small; margin-top: 15px; padding-top: 10px; text-align: center; }' +
    '#sidebar p.e87-blue { background-color:#0057B8;color:white;height:32px;text-align:center;line-height:32px;font-size:24px;margin:0; }' +
    '#sidebar p.e87-yellow { background-color:#FFDD00;color:black;height:32px;text-align:center;line-height:32px;font-size:24px;margin:0; }'

  WMEUI.addStyle(STYLE)

  const BUTTONS = {
    toggle: {
      title: I18n.t(NAME).buttons.toggle,
      description: I18n.t(NAME).buttons.toggle,
      shortcut: null,
    },
  }

  // Default settings
  const SETTINGS = {}

  class E87 extends WMEBase {
    constructor (name, settings = null, buttons = null) {
      super(name, settings)

      this.initHelper()

      this.initTab()

      this.initPanel(buttons)
    }

    initHelper() {
      this.helper = new WMEUIHelper(this.name)
    }

    initTab() {
      /** @type {WMEUIHelperTab} */
      let tab = this.helper.createTab(
        I18n.t(this.name).title,
        {
          sidebar: this.wmeSDK.Sidebar,
          image: GM_info.script.icon
        }
      )
      tab.addText('description', I18n.t(this.name).description)
      tab.addText('info', '<a href="' + GM_info.scriptUpdateURL + '">' + GM_info.script.name + '</a> ' + GM_info.script.version)
      tab.addText('blue', 'made in')
      tab.addText('yellow', 'Ukraine')
      tab.inject()
    }

    /**
     * Init button for selection of the segment
     * @param buttons
     */
    initPanel (buttons) {
      /** @type {WMEUIHelperPanel} */
      this.panel = this.helper.createPanel(I18n.t(this.name).title)

      buttons.toggle.callback = (e) => {
        e.preventDefault()
        this.getSelectedSegments().forEach(
          segment => this.invert(segment)
        )
      }

      this.panel.addButtons(buttons)
    }

    /**
     * Handler for `segment.wme` event
     * @param {jQuery.Event} event
     * @param {HTMLElement} element
     * @param {Segment} model
     * @return {void}
     */
    onSegment (event, element, model) {
      // Skip for walking trails and blocked roads
      if ( this.wmeSDK.DataModel.Segments.isRoadTypeDrivable({ roadType: model.roadType })
        && this.wmeSDK.DataModel.Segments.hasPermissions({ segmentId: model.id })
      ) {
        element.prepend(this.panel.html())
      } else {
        // Remove the panel
        element.querySelector('div.form-group.e87')?.remove()
      }
    }

    /**
     * Handler for `segments.wme` event
     * @param {jQuery.Event} event
     * @param {HTMLElement} element
     * @param {Array} models
     * @return {void}
     */
    onSegments (event, element, models) {
      // Skip walking trails or locked roads
      if (models.filter((model) =>
        this.wmeSDK.DataModel.Segments.isRoadTypeDrivable({ roadType: model.roadType })
        && this.wmeSDK.DataModel.Segments.hasPermissions({ segmentId: model.id })
      ).length === 0) {
        // Remove the panel
        element.querySelector('div.form-group.e87')?.remove()
        return
      }

      let reversed = this.wmeSDK.DataModel.Segments.getReversedSegments({
        segmentIds: this.wmeSDK.Editing.getSelection().ids
      })

      if (reversed.length === models.length || reversed.length === 0) {
        // you can reverse all selected segments
        element.prepend(this.panel.html())
        return
      }

      let reversedIds = reversed.map((segment) => segment.id)

      let forward = models.filter((model) => reversedIds.indexOf(model.id) === -1)

      let forwardIds = forward.map((segment) => segment.id)

      if (forwardIds.length && reversedIds.length) {
        this.log('Inconsistent direction detected: forward = ' + forwardIds.length + ' backward = ' + reversedIds.length)

        let buttonToForward = document.createElement('button')
        buttonToForward.type = 'button'
        buttonToForward.title = I18n.t(NAME).buttons.toggle
        buttonToForward.className = 'waze-btn waze-btn-small waze-btn-white e87 e87-forward'
        buttonToForward.innerText = I18n.t(NAME).buttons.forward + ' (' + reversedIds.length + ')'
        buttonToForward.onclick = (e) => {
          e.preventDefault()
          reversed.forEach(el => this.invert(el))
          buttonToForward.innerText = I18n.t(NAME).buttons.forward + ' (0)'
          buttonToForward.disabled = true
        }
        let buttonToReverse = document.createElement('button')
        buttonToReverse.type = 'button'
        buttonToReverse.title = I18n.t(NAME).buttons.toggle
        buttonToReverse.className = 'waze-btn waze-btn-small waze-btn-white e87 e87-reverse'
        buttonToReverse.innerText = I18n.t(NAME).buttons.reverse + ' (' + forwardIds.length + ')'
        buttonToReverse.onclick = (e) => {
          e.preventDefault()
          forward.forEach(el => this.invert(el))
          buttonToReverse.innerText = I18n.t(NAME).buttons.reverse + ' (0)'
          buttonToReverse.disabled = true
        }

        this.container?.remove();

        this.container = document.createElement('div')
        this.container.className = 'e87-container'
        this.container.append(buttonToForward)
        this.container.append(buttonToReverse)

        $('wz-alert.sidebar-alert.inconsistent-direction-alert > div')
          .after(this.container)
      }
    }

    /**
     * Invert direction of the segment
     * @param {Segment} segment of the segment
     */
    invert (segment) {
      if (!this.wmeSDK.DataModel.Segments.hasPermissions({ segmentId: segment.id })) {
        this.log('Locked by higher rank')
        return
      }
      this.group('invert segment ' + segment.id)

      let isReverse = this.wmeSDK.DataModel.Segments.getReversedSegments({
        segmentIds: [segment.id]
      }).length > 0

      // setup and reverse geometry
      let attributes = {
        segmentId: segment.id,
        geometry: {
          type: "LineString",
          coordinates: segment.geometry.coordinates.slice().reverse()
        }
      }

      // reverse the Direction
      // direction: SegmentDirection: { A_TO_B: "A_TO_B"; B_TO_A: "B_TO_A"; TWO_WAY: "TWO_WAY" }
      if (!segment.isTwoWay) {
        if (segment.isAtoB) {
          attributes.direction = "B_TO_A"
        } else {
          attributes.direction = "A_TO_B"
        }
      }

      // exchange the Speed Limits
      if (segment.revSpeedLimit !== segment.fwdSpeedLimit) {
        attributes.fwdSpeedLimit = segment.revSpeedLimit
        attributes.revSpeedLimit = segment.fwdSpeedLimit
      }

      // exchange the Lanes' Info
      if (segment.fromLanesInfo || segment.toLanesInfo) {
        attributes.fromLanesInfo = segment.toLanesInfo
        attributes.toLanesInfo = segment.fromLanesInfo
      }

      this.wmeSDK.DataModel.Segments.updateSegment(attributes)

      this.groupEnd()
    }
  }

  $(document).on('bootstrap.wme', () => {
    new E87(NAME, SETTINGS, BUTTONS)
  })
})()