WME City Name Marker

Add keyboard keys ESC and Enter. Auto click on icon edit and selected city name (for editors 5+).

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         WME City Name Marker
// @description  Add keyboard keys ESC and Enter. Auto click on icon edit and selected city name (for editors 5+).
// @namespace    https://greasyfork.org/scripts/27502-wme-city-name-marker
// @include      https://*waze.com/*editor*
// @exclude      https://*waze.com/*user/editor*
// @grant        none
// @author       Alexash
// @version      0.5.1
// ==/UserScript==

$('#sidebar').on('keyup', 'input.city-name', function(event) {

    if (event.keyCode == 13)
    {
        applyClick();

        if (false) {
            saveClick();
        }
    }

    if (event.keyCode == 27) {
        $('button.cancel-button').click();
    }
});

$('#sidebar').on('focus', 'input.city-name', function() {
    $(this).select();
});

$('#WazeMap').on('mouseup', '.city-name-marker', function() {

	setTimeout(function() {
        $('.preview').attr('style','display: none;');
        $('.attributes-form.inner-form').attr('style','display: block;');
        $('input.city-name').select();
    }, 0);

});

function applyClick()
{
        $('button.save-button').click();
}

function saveClick()
{
        setTimeout(function() {
            $('.toolbar-button.waze-icon-save.ItemInactive').click();
        }, 1000);
}


$('#sidebar').bind('keydown', 'input.city-name', function(e) {

    if (e.ctrlKey && (e.which == 83)) {
        e.preventDefault();

        applyClick();
        saveClick();

    return false;
  }
});

function toggleCitiesNames()
{
	var layer_cities = $('#layer-switcher-group_cities');
    var layer_city_names = $('#layer-switcher-item_city_names');

	if (!(layer_cities.prop('checked') && layer_city_names.prop('checked')))
	{
		if (layer_cities.prop('checked'))
		{
			layer_cities.click();
		}

		if (layer_city_names.prop('checked'))
		{
			layer_city_names.click();
		}

	}

    layer_cities.click();
    layer_city_names.click();
}

function wmeCNM_Init()
{
    I18n.translations[I18n.locale].keyboard_shortcuts.groups['default'].members.WME_city_name_marker_layer = "Toggle Cities with Names";
    Waze.accelerators.addAction("WME_city_name_marker_layer", {group: 'default'});
    Waze.accelerators.events.register("WME_city_name_marker_layer", null, toggleCitiesNames);
    Waze.accelerators._registerShortcuts({ 'm' : "WME_city_name_marker_layer"});
}

function wmeCNM_bootstrap()
{
    setTimeout(wmeCNM_Init, 1000);
}

wmeCNM_bootstrap();