WME Highlight HNs

Highlights un-nudged house numbers

当前为 2015-04-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         	WME Highlight HNs
// @description		Highlights un-nudged house numbers
// @version      	0.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
// ==/UserScript==

/***************HN Highlighting***********************/
function highlightUntouched(hnMarkers) {
	var i,
	n,
	marker;

	for (i = 0, n = hnMarkers.length; i < n; i++) {
		marker = hnMarkers[i];
		//marker.model is undefined for a selected HN marker
		if ('undefined' !== typeof marker.model &&
			null === marker.model.updatedBy) {
			marker.icon.$div.find(".drag-handle").css("background-color", "red");
		}
	}
}
function checkForHN(intervalID) {
	var hnMarkers = W.appPresenter.sidebar.editPanel.typeToEditorClass
		.segment.houseNumbersControl.markerLayer.markers;
	if (hnMarkers.length > 0) {
		window.clearInterval(intervalID);
		highlightUntouched(hnMarkers);
	}
}
function hnInterval() {
	var count = 0,
	intervalID = window.setInterval(function () {
			console.debug('Checking for HN');
			//return ++count < 50 ? checkForHN(intervalID) : window.clearInterval(intervalID)
			if (++count < 50) {
				checkForHN(intervalID);
			} else {
				window.clearInterval(intervalID);
			}
		}, 100);
}

function updateAlert() {
	var hnVersion = "0.1",
		alertOnUpdate = true,
		versionChanges = 'WME Highlight HNs has been updated to ' + hnVersion + '.\n';
		versionChanges += 'Changes:\n';
		versionChanges += '[*]First release.\n';
	if (alertOnUpdate && window.localStorage && window.localStorage.hnVersion !== hnVersion) {
		window.localStorage.hnVersion = hnVersion;
		alert(versionChanges);
	}
}

function hnInit() {
	updateAlert();
	/* Event Listeners for HN Highlighting*/
	W.accelerators.events.register('editHouseNumbers', this, hnInterval);
	W.model.houseNumbers.events.register('objectschanged', this, hnInterval);
}

function hnBootstrap() {
	if ('undefined' !== typeof window.W &&
		('undefined' !== typeof W.accelerators) &&
		('undefined' !== typeof W.model.houseNumbers)) {
		console.log('HN Tool: Initializing...');
		window.setTimeout(hnInit, 100);
	} else {
		console.log('Bootstrap failed. Trying again...');
		window.setTimeout(function () {
			hnBootstrap();
		}, 1000);
	}
}
console.log('HN Tool: Bootstrap...');
window.setTimeout(hnBootstrap, 100);