WME HN Tool

Highlights un-nudged house numbers

当前为 2015-12-18 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         	WME HN Tool
// @description		Highlights un-nudged house numbers
// @version      	1.20
// @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) {
				console.debug('HN Tool: HN Markers not found. Retry #' + (retryCount + 1));
				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',
			alertOnUpdate = true,
			versionChanges = 'WME Highlight HNs has been updated to ' + hnVersion + '.\n';
		versionChanges += 'Changes:\n';
		versionChanges += '[*]Updated to work with new version of WME.\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);

		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) {
			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);
} ());