WME Bootstrap

Bootstrap library for custom Waze Map Editor scripts

2022-08-25 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyfork.org/scripts/450160/1085537/WME%20Bootstrap.js을(를) 사용하여 포함하는 라이브러리입니다.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         WME Bootstrap
// @namespace    https://greasyfork.org/users/227648-anton-shevchuk
// @version      0.0.2
// @description  Bootstrap library for custom Waze Map Editor scripts
// @license      MIT License
// @match        https://www.waze.com/editor*
// @match        https://www.waze.com/*/editor*
// @match        https://beta.waze.com/editor*
// @match        https://beta.waze.com/*/editor*
// @exclude      https://www.waze.com/user/editor*
// @exclude      https://beta.waze.com/user/editor*
// @icon         https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://anton.shevchuk.name&size=64
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

/* global W */

(function ($) {
  'use strict'

  const WMEEvents = 'https://greasyfork.org/scripts/450173-wme-events/code/WME-Events.js?version=1085533'
  const WMEClass = ''

  const APIHelper = 'https://greasyfork.org/scripts/389117-apihelper/code/APIHelper.js'
  const APIHelperUI = 'https://greasyfork.org/scripts/389577-apihelperui/code/APIHelperUI.js'
  const CommonUtils = 'https://greasyfork.org/scripts/389765-common-utils/code/CommonUtils.js'

  class Bootstrap {
    log (message) {
      console.log('%cBootstrap:%c ' + message, 'color: #0DAD8D; font-weight: bold', 'color: dimgray; font-weight: normal')
    }

    /**
     * Bootstrap it once!
     */
    init () {
      if (!window.WMEBootstrap) {
        window.WMEBootstrap = true
        this.check()
      }
    }

    /**
     * Check loading process
     * @param {int} max tries
     */
    check (tries = 100) {
      this.log('try to init')
      if (W &&
        W.map &&
        W.model &&
        W.model.countries.top &&
        W.loginManager.user
      ) {
          this
            .load()
            .then(() => $(document).trigger('bootstrap.wme'))
            .then(() => this.log('was initialized'))
            .catch((e) => this.log('loading failed', e))
      } else if (tries > 0) {
        tries--
        setTimeout(() => this.check(tries), 500)
      } else {
        this.log('initialization failed')
      }
    }

    load () {
      return Promise.all([
        $.getScript(WMEEvents),
        $.getScript(APIHelper),
        $.getScript(APIHelperUI),
        $.getScript(CommonUtils),
      ])
    }
  }

  new Bootstrap().init()

})(window.jQuery);