WME HN Tool

Highlights un-nudged house numbers

目前為 2015-12-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
} ());