WME HN Tool

Highlights un-nudged house numbers

目前为 2015-12-22 提交的版本。查看 最新版本

// ==UserScript==
// @name         	WME HN Tool
// @description		Highlights un-nudged house numbers
// @version      	1.20.1
// @author			SAR85
// @copyright		SAR85
// @license		 	CC BY-NC-ND
// @grant		 	none
// @include			https://www.waze.com/editor/*
// @include			https://www.waze.com/*/editor/*
// @include			https://editor-beta.waze.com/*
// @namespace		https://greasyfork.org/users/9321
// @require         https://greasyfork.org/scripts/9794-wlib/code/wLib.js?version=76145
// ==/UserScript==

/* global W */
/* global wLib */

(function () {
	var hnMarkerLayer,
		messageBar;
	function highlightUntouched(retryCount) {
		'use strict';
		var i, n, marker, hnMarkers;
		retryCount = retryCount || 0;
		hnMarkers = hnMarkerLayer.markers;
		if (hnMarkers.length === 0) {
			if (retryCount < 1000) {
				setTimeout(function () {
					highlightUntouched(++retryCount);
				}, 10);
			} else {
				console.debug('HN Tool: HN markers not found. Giving up.');
				return;
			}
		}
		for (i = 0, n = hnMarkers.length; i < n; i++) {
			marker = hnMarkers[i];
			if (marker.model && null === marker.model.updatedBy) {
				marker.icon.$div.find('.uneditable-number').css('background-color', '#FFAD85');
				marker.inputWrapper.css('background-color', '#FFAD85');
			}
		}
	}
	function checkForHNLayer() {
		'use strict';
		var layers = W.map.getLayersByName('houseNumberMarkers');
		if (layers.length > 0) {
			hnMarkerLayer = layers[0];
			highlightUntouched();
		}
	}
	function updateAlert() {
		'use strict';
		var hnVersion = '1.20.1',
			alertOnUpdate = true,
			versionChanges = 'WME Highlight HNs has been updated to ' + hnVersion + '.\n';
		versionChanges += 'Changes:\n';
		versionChanges += '[*]Highlighting is re-applied after editing HNs.\n';
		if (alertOnUpdate && window.localStorage && window.localStorage.hnVersion !== hnVersion) {
			window.localStorage.hnVersion = hnVersion;
			alert(versionChanges);
		}
	}
	function hnInit() {
		'use strict';
		W.map.events.register('addlayer', this, checkForHNLayer);
        W.vent.on('operationDone', checkForHNLayer);
		messageBar = new wLib.Interface.MessageBar({
			messagePrefix: 'WME HN Tool:'
		});
		console.debug('HN Tool: Initialized.');
		updateAlert();
	}
	function hnBootstrap(count) {
		'use strict';
		count = count || 0;
		if ('undefined' !== typeof wLib && 'undefined' !== typeof W &&
			'undefined' !== typeof W.map && 'undefined' !== typeof W.map.events &&
			'undefined' !== typeof W.map.events.register &&
            'undefined' !== typeof W.vent &&
            'undefined' !== typeof W.vent.on) {
			console.debug('HN Tool: Initializing...');
			window.setTimeout(hnInit, 100);
		} else if (count < 10) {
			console.debug('HN Tool: Bootstrap failed. Trying again...');
			window.setTimeout(function () {
				hnBootstrap(++count);
			}, 1000);
		} else {
			console.error('HN Tool: Bootstrap error.');
		}
	}
	console.debug('HN Tool: Bootstrap...');
	window.setTimeout(hnBootstrap, 100);
} ());