WME Highlight HNs

Highlights un-nudged house numbers

目前為 2015-05-26 提交的版本,檢視 最新版本

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

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

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

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

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