WME Highlight HNs

Highlights un-nudged house numbers

当前为 2015-05-26 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

function highlightUntouched(hnMarkers) {
	'use strict';
	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', "#3399FF");
			//marker.input.css('color', '#3399FF');
			marker.inputWrapper.css('background-color', '#FF9900');
		}
	}
}

function checkHNs() {
	'use strict';
	var count = 0,
		check = function () {
			console.debug('Checking for HN');
			var hnMarkers = W.appPresenter.sidebar.editPanel.typeToEditorClass
				.segment.houseNumbersControl.markerLayer.markers;
			if (hnMarkers.length > 0) {
				return highlightUntouched(hnMarkers);
			} else if (++count < 50) {
				window.setTimeout(check, 100);
			} else {
				console.error('Error reading HNs');
			}
		};
	return check();
}

function updateAlert() {
	'use strict';
	var hnVersion = '0.2',
		alertOnUpdate = true,
		versionChanges = 'WME Highlight HNs has been updated to ' + hnVersion + '.\n';
	versionChanges += 'Changes:\n';
	versionChanges += '[*]Possible fix for issue with detecting house numbers.\n';
	versionChanges += '[*]Changed style of highlighting for un-nudged house numbers.\n';
	if (alertOnUpdate && window.localStorage && window.localStorage.hnVersion !== hnVersion) {
		window.localStorage.hnVersion = hnVersion;
		alert(versionChanges);
	}
}

function hnInit() {
	'use strict';
	var houseNumberControl = W.appPresenter.sidebar.editPanel.typeToEditorClass.segment.houseNumbersControl,
		wRender = houseNumberControl.render;

	houseNumberControl.render = function () {
		wRender.call(houseNumberControl);
		checkHNs();
	}

	console.debug('HN Tool: Initialized.');
	updateAlert();
}

function hnBootstrap() {
	if (undefined !== typeof W && undefined !== typeof W.accelerators &&
		W.appPresenter && W.appPresenter.sidebar && W.appPresenter.sidebar.editPanel && 
	    W.appPresenter.sidebar && W.appPresenter.sidebar.editPanel && 
	    W.appPresenter.sidebar.editPanel.typeToEditorClass && 
	    W.appPresenter.sidebar.editPanel.typeToEditorClass.segment &&
	    undefined !== typeof W.appPresenter.sidebar.editPanel.typeToEditorClass.segment.houseNumbersControl) {
		console.debug('HN Tool: Initializing...');
		window.setTimeout(hnInit, 100);
	} else {
		console.debug('Bootstrap failed. Trying again...');
		window.setTimeout(function () {
			hnBootstrap();
		}, 1000);
	}
}

console.debug('HN Tool: Bootstrap...');
window.setTimeout(hnBootstrap, 100);