WME Bootstrap

Bootstrap library for custom Waze Map Editor scripts

当前为 2022-08-25 提交的版本,查看 最新版本

此脚本不应直接安装,它是供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/450160/1085453/WME%20Bootstrap.js

  1. // ==UserScript==
  2. // @name WME Bootstrap
  3. // @namespace https://greasyfork.org/users/227648-anton-shevchuk
  4. // @version 0.0.1
  5. // @description Bootstrap library for custom Waze Map Editor scripts
  6. // @license MIT License
  7. // @match https://www.waze.com/editor*
  8. // @match https://www.waze.com/*/editor*
  9. // @match https://beta.waze.com/editor*
  10. // @match https://beta.waze.com/*/editor*
  11. // @exclude https://www.waze.com/user/editor*
  12. // @exclude https://beta.waze.com/user/editor*
  13. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://anton.shevchuk.name&size=64
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. /* jshint esversion: 6 */
  18.  
  19. /* global W */
  20.  
  21. (function ($) {
  22. 'use strict'
  23.  
  24. const APIHelper = 'https://greasyfork.org/scripts/389117-apihelper/code/APIHelper.js'
  25. const APIHelperUI = 'https://greasyfork.org/scripts/389577-apihelperui/code/APIHelperUI.js'
  26. const CommonUtils = 'https://greasyfork.org/scripts/389765-common-utils/code/CommonUtils.js'
  27.  
  28. const WMEEvents = ''
  29. const WMEClass = ''
  30.  
  31. class Bootstrap {
  32. log (message) {
  33. console.log('%cBootstrap:%c ' + message, 'color: #0DAD8D; font-weight: bold', 'color: dimgray; font-weight: normal')
  34. }
  35.  
  36. /**
  37. * Bootstrap it once!
  38. */
  39. init () {
  40. if (!window.WMEBootstrap) {
  41. window.WMEBootstrap = true
  42. this.check()
  43. }
  44. }
  45.  
  46. /**
  47. * Check
  48. * @param {int} tries
  49. */
  50. check (tries = 1) {
  51. this.log('attempt ' + tries)
  52. if (W &&
  53. W.map &&
  54. W.model &&
  55. W.model.countries.top &&
  56. W.loginManager.user
  57. ) {
  58. this
  59. .load()
  60. .then(() => $(document).trigger('bootstrap.wme'))
  61. .then(() => this.log('was initialized'))
  62. .catch(() => this.log('loading failed'))
  63. } else if (tries < 100) {
  64. tries++
  65. setTimeout(() => this.check(tries), 500)
  66. } else {
  67. this.log('initialization failed')
  68. }
  69. }
  70.  
  71. async load() {
  72. return Promise.all([
  73. $.getScript(APIHelper),
  74. $.getScript(APIHelperUI),
  75. $.getScript(CommonUtils),
  76. ])
  77. }
  78. }
  79.  
  80. new Bootstrap().init()
  81. })(window.jQuery)