您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
A House Number script with its controls in the House Number mini-editor. It injects the next value in a sequence into each new HN; it also provides acclerators 'h', '1' ... '9' on the Add house number command.
当前为
/* global GM_info */ /* global W */ /* global Waze */ /* global I18n */ /* global unsafeWindow */ // ==UserScript== // @name WME Rapid House Numbers // @description A House Number script with its controls in the House Number mini-editor. It injects the next value in a sequence into each new HN; it also provides acclerators 'h', '1' ... '9' on the Add house number command. // @namespace http://compsol.cc // @version 1.6 // @include https://www.waze.com/*/editor* // @include https://www.waze.com/editor* // @include https://beta.waze.com/* // @exclude https://www.waze.com/*user/*editor/* // @author Kevin Greiner 2017 (kjg53) // @license MIT // ==/UserScript== (function() { var scriptName = GM_info.script.name; var version = GM_info.script.version; var oWaze=W; var oI18n=I18n; console.log(scriptName + ": Loading "); { var changeLog = [ {version: "1.0", message: ""}, {version: "1.1", message: "The changelog now handles missing entries."}, {version: "1.2", message: "Now does full reset when exiting House Number Editor."}, {version: "1.3", message: "Fixed typo in change log."}, {version: "1.4", message: "The accelerator key bindings are removed upon exiting the House Number editor."}, {version: "1.5", message: "The primary accelerator has been changed from 'a' to 'h'. The keys '1' .. '9' are now accelerators that create the next house number then incremment next by the value of the key."}, {version: "1.6", message: "Disabled numeric accelerators in text fields."} ]; var versionKey = scriptName.replace( /\s/g, "") + "Version"; var checkStorageKey = versionKey + 'Ck'; var secret = new Date().getTime(); window.localStorage.setItem(checkStorageKey, secret); if (window.localStorage.getItem(checkStorageKey) == secret) { var previousVersion = window.localStorage.getItem(versionKey); var i = 0; if (previousVersion) { try { while (changeLog[i++].version != previousVersion) {} } catch(e) { i = 0; } } var announcement = scriptName; while (i < changeLog.length) { var log = changeLog[i++]; var msg = "V" + log.version + ": " + log.message; announcement = announcement + "\n" + msg; } if (announcement != scriptName) { alert(announcement); window.localStorage.setItem(versionKey, version); } } } function rapidHN_bootstrap() { if (typeof unsafeWindow !== "undefined") { oWaze=unsafeWindow.W; oI18n=unsafeWindow.I18n; } if (typeof oWaze === "undefined" || typeof oWaze.map === "undefined" || typeof oWaze.selectionManager === "undefined" || typeof oI18n === "undefined" || typeof oI18n.translations === "undefined") { console.log(scriptName + " dependencies not ready. Waiting..."); setTimeout(rapidHN_bootstrap, 500); return; } setTimeout(initialize, 999); } function initialize() { var addHouseNumber; var observeHouseNumbersLayer; var oneTimeIncrement; var ZERO = '0'.charCodeAt(0); var ONE = '1'.charCodeAt(0); var NINE = '9'.charCodeAt(0); var LETTER_H = 'H'.charCodeAt(0); var ACCEL_TARGETS = 'div.rapidHN-control input,div.edit-area'; function cleanUpObserveHouseNumbersLayer() { if (observeHouseNumbersLayer !== undefined) { addHouseNumber.css('font-weight', 'normal'); addHouseNumber.css('color', 'inherit'); $('div.rapidHN-control').off('keydown', rapidAccelerator); $('div#rapidHN-interceptor').remove(); observeHouseNumbersLayer.disconnect(); observeHouseNumbersLayer = undefined; } } function rapidAccelerator(event) { if (!event.shiftKey && !event.altKey && !event.metaKey) { execute = false; if (event.target.localName != 'input' && ONE <= event.which && event.which <= NINE) { oneTimeIncrement = event.which - ZERO; execute = true; } else if (event.which == LETTER_H) { oneTimeIncrement = undefined; execute = true; } if (execute) { event.preventDefault(); event.stopImmediatePropagation(); $(event.target).on('change'); event.target.blur(); addHouseNumber.click(); } } } console.log(scriptName + " initializing."); var obs = new MutationObserver(function(mutations, observer) { var div = $('div#edit-buttons div'); var foundControls = $('.rapidHN-control', div); addHouseNumber = $('.add-house-number', div); if (addHouseNumber.length) { if (!foundControls.length) { addHouseNumber.after('<div class="toolbar-button rapidHN-control" style="float:left; padding-right: 3px"><span class="menu-title">Next #</span><input type="number" name="nextHN" id="rapidHN-next" style="margin: 3px; height:20px; width: 64px; text-align: right"></div>', '<div class="toolbar-button rapidHN-control" style="float:left"><span class="menu-title" style="text-align: right">Increment</span><input type="number" name="incrementHN" id="rapidHN-increment" value="4" style="margin: 3px; height:20px; width: 32px; text-align: right" step="1"></div>', '<img id="rapidHN-help" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAIAAADZrBkAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJgSURBVDhPbZPPa1NBEMdn9+3LS16S5lWql0qReLAg4rUqiDcP9uKpHqQHq4jWkyAi+CeIJxGFIiiI4LFWRS/Sk3gqij2oJIpFUWqal6YmeT/H776NxogDCbuz38+b2ZlZ0Wg0aNgqI2XLIhLZhilJqLXZzjYDG8I0oIhjWqondZ/hqXpiumoJRUk8BA+wbV4ZEU49ju6txqWcsLJoCdNWyLN71Z1jNiJv+H2yj4HpRrTrdpAyl2x9gFjMJDN4K8JCfDrrFOw+KfFDbogDRkkwAkCjywkLS4r1DqdMcOIIAsi02GC4z9yTCHEcCwxvBvR0xl2bL9bPFV/OFoGZI/xDBrHGNJ3Q3bexya0T0ZWDzqGd6vKLYP55sG+HvDSVgxMGAWQQA5Go9aNaUrQFDGdKUq2Z3loJF15Hi+9jeDxHppoiCCCDGIhEujVfq43llVj8EF1dDsKEHx7Pw3PtVehmicD0R33dUi1Hxf42kHDcPJo/MK4O3+9+76TKtD4zI5aodLVCicnjt8UpT42rB6vhyrfYVTo944cMYiAijkJ8wLnenSijN+aUooRHC6IdoN2sTO+yOJ/baXCxAJnEyCibTkxaP6NBrhs9fjNXWj7ptoKBE4KZSQtiIHpKvKyD22/0Copy2VBBcWa//aXNzz7GuCo8qFA3pvULuki+wbDCcP3o8J6FAFTWDE1ircvDeo3hfHfaGXPFYLhg2IwVxdfz+SMTcq2dNnt6pqKUsMAWThxB8O8oGxsdKeONtDq8VEvrvi5u1ZPTu2XFFXhNzf8+nD+Gq8ps8Iylsb5Mf2OM6Bc9JDhpKCzFQAAAAABJRU5ErkJggg==" style="margin-top: 13px"/>', '<div id="rapidHN-info" title="Rapid House Numbers">Set the next and increment fields to non-zero numbers to inject a house number as soon as the location is selected. The letters \'h\', \'1\' .. \'9\' will also be available as accelerators.</div>'); $("#rapidHN-info").dialog({autoOpen: false}); $("#rapidHN-help").click(function() { $("#rapidHN-info").dialog("open"); return false; }); var controls = $('div.rapidHN-control'); $('input', controls).on('change', function(event) { var active = true; $('input', controls).each(function() { if (active) { var i = parseInt($(this).val(), 10); active = !isNaN(i) && i !== 0; } }); if (active) { if (observeHouseNumbersLayer === undefined) { addHouseNumber.css('font-weight', 'bold'); addHouseNumber.css('color', '#2196f3'); observeHouseNumbersLayer = new MutationObserver(function(mutations, observer){ mutations.forEach(function(mutation) { var input = $('div.olLayerDiv.house-numbers-layer div.house-number div.content.active:not(".new") input.number'); if (input.val() === "") { var next = $('input#rapidHN-next'); var n = parseInt(next.val()); var i; if (oneTimeIncrement === undefined) { var inc = $('input#rapidHN-increment'); i = parseInt(inc.val()); } else { i = oneTimeIncrement; oneTimeIncrement = undefined; } input.val(n).change(); next.val(n + i); // Move focus from input field to WazeMap so that rapidHN-interceptor can catch the next input. // Also prevents accidental additions to the injected HN. $("div#WazeMap").focus(); } }); }); observeHouseNumbersLayer.observe( $('div.olLayerDiv.house-numbers-layer')[0], { childList:false, subtree:true, attributes: true }); } if ($('div#rapidHN-interceptor').length == 0) { $('div.rapidHN-control').on('keydown', rapidAccelerator); $('div#WazeMap').parent().append('<div id="rapidHN-interceptor" style="position: relative; width: 100%; height: 100%; z-index: 100">').on('keydown', rapidAccelerator); } } else { cleanUpObserveHouseNumbersLayer(); } }); } } else { cleanUpObserveHouseNumbersLayer(); } }); // have the observer observe for changes in children obs.observe( $('div#edit-buttons')[0], { childList:true, subtree:false }); console.log(scriptName + " initialized."); } rapidHN_bootstrap(); })();