WME RTC Improvements

Adds several helpful features to RTC handling in the Waze Map Editor

目前为 2016-04-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name WME RTC Improvements
  3. // @description Adds several helpful features to RTC handling in the Waze Map Editor
  4. // @namespace vaindil
  5. // @version 1.0.2
  6. // @grant none
  7. // @include https://www.waze.com/editor/*
  8. // @include https://www.waze.com/*/editor/*
  9. // @include https://editor-beta.waze.com/editor/*
  10. // @include https://editor-beta.waze.com/*/editor/*
  11. // @exclude https://www.waze.com/user/*
  12. // @author vaindil
  13. // ==/UserScript==
  14.  
  15. function yoloswag() {
  16. try {
  17. var element = $('#sidebar');
  18. if ($(element).length) {
  19. letsAGo();
  20. } else {
  21. setTimeout(init, 1000);
  22. }
  23. } catch (err) {
  24. console.log("RTCENH - " + err);
  25. setTimeout(init, 1000);
  26. }
  27. }
  28.  
  29. yoloswag();
  30.  
  31. function letsAGo() {
  32. $(document).on('mouseover', 'div.add-closure-button.btn.btn-primary', function() {
  33. $(document).off('mouseover.RTCXdays');
  34. $(document).on('mouseover.RTCXdays', 'div.edit-closure.new', function() {
  35. justDewIt();
  36. $(document).off('mouseover.RTCXdays');
  37. });
  38. });
  39.  
  40. $(document).on('input.RTCXdaysfield keyup.RTCXdaysfield', 'input#expireinXdays', timeAndRelativeDimensionInSpace);
  41. $(document).on('click.RTCXdayscrash', 'div#RTCXdayscrash', ohNoes);
  42. }
  43.  
  44. function justDewIt() {
  45. $('div.edit-closure.new > form.form > div.checkbox').before(
  46. '<div class="form-group">' +
  47. '<label class="control-label">Expire in X days</label>' +
  48. '<div class="controls">' +
  49. '<input type="number" length="3" maxlength="4" class="form-control" id="expireinXdays" />' +
  50. '</div>' +
  51. '</div>'
  52. );
  53.  
  54. $('div.action-buttons').append(
  55. '<div class="btn btn-danger" id="RTCXdayscrash" style="float:right"><i class="fa fa-exclamation-triangle"></i>Crash</div>'
  56. );
  57.  
  58. $('input[name="closure_endDate"]').datepicker('remove');
  59. $('input[name="closure_endDate"]').datepicker({ format: 'yyyy-mm-dd', todayHighlight: true, autoclose: true });
  60. }
  61.  
  62. function timeAndRelativeDimensionInSpace() {
  63. var newdate = new Date();
  64. if ($('input[name="closure_startDate"]').val() !== '') {
  65. var p = $('input[name="closure_startDate"]').val().split('-');
  66. var y = parseInt(p[0], 10);
  67. var m = parseInt(p[1], 10);
  68. var d = parseInt(p[2], 10);
  69. if (isNaN(y) || isNaN(m) || isNaN(d))
  70. return;
  71.  
  72. newdate = new Date(y, m - 1, d);
  73. }
  74.  
  75. var v = parseInt($('#expireinXdays').val(), 10);
  76. if (isNaN(v))
  77. return;
  78.  
  79. newdate.setDate(newdate.getDate() + v);
  80. //var newmonth = ('0' + (newdate.getMonth() + 1)).slice(-2);
  81. //var newday = ('0' + (newdate.getDate())).slice(-2);
  82. //var newstring = newdate.getFullYear() + '-' + newmonth + '-' + newday;
  83. $('input[name="closure_endDate"]').datepicker('update', newdate);
  84. if ($('input[name="closure_endTime"]').val() === '')
  85. $('input[name="closure_endTime"]').timepicker('setTime', '05:00');
  86. }
  87.  
  88. function ohNoes() {
  89.  
  90. $('input[name="closure_reason"]').val('Crash');
  91.  
  92. var cur = new Date();
  93. cur.setHours(cur.getHours() + 2);
  94. $('input[name="closure_endDate"]').datepicker('update', cur);
  95. $('input[name="closure_endTime"]').timepicker('setTime', (('0' + cur.getHours()).slice(-2)) + ':' + (('0' + cur.getMinutes()).slice(-2)));
  96. }