WME Reminders

Create reminders in the Waze Map Editor.

  1. // // ==UserScript==
  2. // @name WME Reminders
  3. // @namespace WazeDev
  4. // @version 2021.01.15.001
  5. // @description Create reminders in the Waze Map Editor.
  6. // @author MapOMatic
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @license GNU GPLv3
  9. // @contributionURL https://github.com/WazeDev/Thank-The-Authors
  10. // @require https://gf.qytechs.cn/scripts/24851-wazewrap/code/WazeWrap.js
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. /* global WazeWrap */
  15. /* global $ */
  16. /* global GM_info */
  17.  
  18. const SCRIPT_NAME = GM_info.script.name;
  19. const SCRIPT_VERSION = GM_info.script.version;
  20. const TAB_BUTTON_TEXT = 'Reminders';
  21. const ALARM_NAME_PLACEHOLDER = '-- alarm name here --';
  22. const SETTINGS_STORE_NAME = 'wmeReminders';
  23. const DEFAULT_ALARM_NAME = 'This is your alarm.';
  24.  
  25. let _settings = {};
  26. let _alarmTimeInput;
  27. let _alarmNameInput;
  28. let _tabButton;
  29. let _timer;
  30.  
  31. function checkSettings(obj, defaultObj) {
  32. Object.keys(defaultObj).forEach(key => {
  33. if (!obj.hasOwnProperty(key)) {
  34. obj[key] = defaultObj[key];
  35. } else if (defaultObj[key] && (defaultObj[key].constructor === {}.constructor)) {
  36. checkSettings(obj[key], defaultObj[key]);
  37. }
  38. });
  39. }
  40.  
  41. function loadSettings() {
  42. const loadedSettings = $.parseJSON(localStorage.getItem(SETTINGS_STORE_NAME));
  43. const defaultSettings = {
  44. alarmTime: null,
  45. alarmName: null
  46. };
  47. if (loadedSettings) {
  48. _settings = loadedSettings;
  49. checkSettings(_settings, defaultSettings);
  50. } else {
  51. _settings = defaultSettings;
  52. }
  53. }
  54.  
  55. function saveSettings() {
  56. if (localStorage) {
  57. _settings.alarmTime = _alarmTimeInput.val();
  58. _settings.alarmName = _alarmNameInput.val();
  59. localStorage.setItem(SETTINGS_STORE_NAME, JSON.stringify(_settings));
  60. }
  61. }
  62.  
  63. function onTimeElapsed() {
  64. let alarmName = _alarmNameInput.val().trim();
  65. if (!alarmName.length) {
  66. alarmName = DEFAULT_ALARM_NAME;
  67. }
  68. WazeWrap.Alerts.info(SCRIPT_NAME, alarmName, true, false);
  69. resetAlarm();
  70. }
  71.  
  72.  
  73. function killTimer() {
  74. if (_timer) clearTimeout(_timer);
  75. }
  76.  
  77. function getTimeParts(timeStr) {
  78. const match = /(\d+):(\d+)/.exec(timeStr);
  79. if (match) {
  80. const [, hr, min] = match;
  81. return { hr, min };
  82. }
  83. return null;
  84. }
  85.  
  86. function getNewAlarmOffsetMs(timeParts) {
  87. const dtNow = new Date();
  88. const dtNew = dtNow.clone();
  89. dtNew.setHours(timeParts.hr, timeParts.min, 0, 0);
  90. if (dtNew < dtNow) {
  91. dtNew.addDays(1);
  92. }
  93. return dtNew - dtNow;
  94. }
  95.  
  96. function resetAlarm() {
  97. killTimer();
  98. const timeParts = getTimeParts(_alarmTimeInput.val());
  99. if (timeParts) {
  100. const alarmTimeOffset = getNewAlarmOffsetMs(timeParts);
  101. _timer = setTimeout(onTimeElapsed, alarmTimeOffset);
  102. }
  103. }
  104.  
  105. function onAlarmTimeInputChanged() {
  106. saveSettings();
  107. resetAlarm();
  108. }
  109.  
  110. function onAlarmNameInputChanged() {
  111. saveSettings();
  112. }
  113.  
  114. function initTabButton() {
  115. _tabButton = $(`a[href="#sidepanel-${TAB_BUTTON_TEXT.toLowerCase()}"]`);
  116. _tabButton.empty();
  117. _tabButton.append('<span class="fa fa-bell">');
  118. _tabButton.attr('title', SCRIPT_NAME);
  119. }
  120.  
  121. function initAlarmTimeInput() {
  122. _alarmTimeInput = $('#wmeRemindersAlarmTime');
  123. _alarmTimeInput.val(_settings.alarmTime);
  124. _alarmTimeInput.change(onAlarmTimeInputChanged);
  125. resetAlarm();
  126. }
  127.  
  128. function initAlarmNameInput() {
  129. _alarmNameInput = $('#wmeRemindersAlarmName');
  130. _alarmNameInput.change(onAlarmNameInputChanged);
  131. _alarmNameInput.val(_settings.alarmName);
  132. }
  133.  
  134. function initTab() {
  135. initTabButton();
  136. initAlarmTimeInput();
  137. initAlarmNameInput();
  138. }
  139.  
  140. function addTab() {
  141. const $content = $('<div>').append(
  142. $('<span>', { style: 'font-size:14px; font-weight:600' }).text(SCRIPT_NAME),
  143. $('<span>', { style: 'font-size:11px;margin-left:10px;color:#aaa;' }).text(SCRIPT_VERSION),
  144. $('<div>', { style: 'padding-top:4px;' }).append(
  145. $('<div>').append($('<span>').text('Alarm:')),
  146. $('<input>', { id: 'wmeRemindersAlarmTime', type: 'time' }),
  147. $('<input>', { id: 'wmeRemindersAlarmName', type: 'text', placeholder: ALARM_NAME_PLACEHOLDER })
  148. )
  149. );
  150. new WazeWrap.Interface.Tab(TAB_BUTTON_TEXT, $content.html(), initTab);
  151. }
  152.  
  153. function init() {
  154. loadSettings();
  155. addTab();
  156. }
  157.  
  158. function bootstrap() {
  159. if (WazeWrap.Ready) {
  160. init();
  161. } else {
  162. setTimeout(bootstrap, 250);
  163. }
  164. }
  165.  
  166. bootstrap();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址