WME Fix UI

Allows alterations to the WME UI to fix things screwed up or ignored by Waze

目前為 2016-06-08 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name                WME Fix UI
// @namespace           https://greasyfork.org/en/users/46070
// @description         Allows alterations to the WME UI to fix things screwed up or ignored by Waze
// @include             https://www.waze.com/editor/*
// @include             https://www.waze.com/*/editor/*
// @include             https://editor-beta.waze.com/*
// @exclude             https://www.waze.com/user/editor/*
// @supportURL          https://www.waze.com/forum/viewtopic.php?f=819&t=191178
// @version             0.5
// @grant               none
// ==/UserScript==

// Thanks to (in no particular order) Bellhouse, Twister-UK, Timbones, Dave2084, Rickzabel

(function()
{
// global variables
var wmefu_version = "0.5";
var applyCount = 0;
var wmefuinit = false;
var shrinkBlackBarActive = false;
var compressSegmentTabActive = false;

function initialiseFixUI() {
	if (wmefuinit) {
		return;
	}

	// go round again if map container isn't there yet
	if(!window.Waze.map)
	{
			window.console.log("WME FixUI: waiting for WME...");
			setTimeout(initialiseFixUI, 1000);
			return;
	}

	//create styles that will be used later

	// create tab contents
	var addon = document.createElement('section');
	addon.id = "wmefu-addon";
	var section = document.createElement('p');
	section.style.paddingTop = "0px";
	section.id = "fuContent";
	section.innerHTML  = '<b>UI Fixes</b><br>';
	section.innerHTML += '<input type="checkbox" id="_cbMoveZoomBar" /> ' +
			'<span title="Because nobody likes a pointless UI change that breaks your workflow, imposed by idiots who rarely use the editor and don\'t listen to feedback">Move zoom bar to left</span><br>';
	section.innerHTML += '<input type="checkbox" id="_cbHideUserInfo" /> ' +
			'<span title="Because we can earn points quicker without a massive chunk of space wasted on telling us how many we earnt up to yesterday">Hide user info in the side panel</span><br>';
	section.innerHTML += '<input type="checkbox" id="_cbShrinkBlackBar" /> ' +
			'<span title="Because we can\'t afford to waste screen space on stuff we didn\'t ask for and don\'t want">Shrink the black bar above the map</span><br>';
	section.innerHTML += '<input type="checkbox" id="_cbCompressSegmentTab" /> ' +
			'<span title="Because I\'m sick of having to scroll the side panel because of oversized fonts and wasted space">Compress the contents of the side panel</span><br>';
	section.innerHTML += '<input type="checkbox" id="_cbRestyleReports" /> ' +
			'<span title="Another UI element configured for developers with massive screens instead of normal users">Change formatting for report panels (UR/MP)</span><br>';
	section.innerHTML += '<br>';
	section.innerHTML += '<b><a href="https://greasyfork.org/en/scripts/20077-wme-fix-ui" target="_blank"><u>' +
			'WME Fix UI</u></a></b> &nbsp; v' + wmefu_version;

	addon.appendChild(section);

	// insert the content as a tab
	var userTabs = getId('user-info');
	var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
	var tabContent = getElementsByClassName('tab-content', userTabs)[0];

	if (typeof navTabs === "undefined") {
		console.log("WMEFU: not logged in - will initialise later");
		Waze.loginManager.on("login", initialiseFixUI);
		return;
	}
	newtab = document.createElement('li');
	newtab.innerHTML = '<a href="#sidepanel-FixUI" data-toggle="tab" title="Fix UI">FU</a>';
	navTabs.appendChild(newtab);

	addon.id = "sidepanel-FixUI";
	addon.className = "tab-pane";
	tabContent.appendChild(addon);


	// setup event handlers for user actions:
	getId('_cbMoveZoomBar').onclick = moveZoomBar;
	getId('_cbShrinkBlackBar').onclick = shrinkBlackBar;
	getId('_cbHideUserInfo').onclick = hideUserInfo;
	getId('_cbCompressSegmentTab').onclick = compressSegmentTab;
	getId('_cbRestyleReports').onclick = restyleReports;

	// restore saved settings
	if (localStorage.WMEFixUI) {
		console.log("WMEFU: loading options");
		options = JSON.parse(localStorage.WMEFixUI);

		getId('_cbMoveZoomBar').checked = options[1];
		getId('_cbShrinkBlackBar').checked = options[2];
		getId('_cbHideUserInfo').checked = options[3];
		getId('_cbCompressSegmentTab').checked = options[4];
		getId('_cbRestyleReports').checked = options[5];
	} else {
		getId('_cbMoveZoomBar').checked = true;
		getId('_cbShrinkBlackBar').checked = true;
		getId('_cbHideUserInfo').checked = true;
		getId('_cbCompressSegmentTab').checked = true;
		getId('_cbRestyleReports').checked = true;
	}

	if (W.loginManager.user.userName == 'iainhouse') {
		// Adds an extra checkbox so I can test segment panel changes easily
		var brand = getId('brand');
		extraCBSection = document.createElement('p');
		extraCBSection.innerHTML = '<input type="checkbox" id="_cbextraCBSection" />';
		brand.appendChild(extraCBSection);
		getId('_cbextraCBSection').onclick = FALSEcompressSegmentTab;
		_cbextraCBSection.checked = _cbCompressSegmentTab.checked;
	}

	// overload the WME exit function
	saveOptions = function() {
		if (localStorage) {
			console.log("WMEFU: saving options");
			var options = [];

			// preserve previous options which may get lost after logout
			if (localStorage.WMEFixUI)
				options = JSON.parse(localStorage.WMEFixUI);

			options[1] = getId('_cbMoveZoomBar').checked;
			options[2] = getId('_cbShrinkBlackBar').checked;
			options[3] = getId('_cbHideUserInfo').checked;
			options[4] = getId('_cbCompressSegmentTab').checked;
			options[5] = getId('_cbRestyleReports').checked;

			localStorage.WMEFixUI = JSON.stringify(options);
		}
	};
	window.addEventListener("beforeunload", saveOptions, false);

	// apply the settings
	setTimeout(applyAllSettings, 2000);
	
	wmefuinit = true;
	window.console.log("WMEFU: Initialised");
	}

function applyAllSettings() {
	applyCount += 1;
	if (applyCount < 5) {
		setTimeout(applyAllSettings, 2000);
	}
	moveZoomBar();
	shrinkBlackBar();
	hideUserInfo();
	compressSegmentTab();
	restyleReports();
}

function moveZoomBar() {
	var WMETBZLI = getId('WMETB_ZoomLevelIndicator');
	var reportPanel = getId('panel-container');
	
	reportPanel.style.position = "absolute";
	if (_cbMoveZoomBar.checked) {
		$(".olControlPanZoomBar").css({'left':10,'width':30,'right':""});
		if (reportPanel) {
			if (document.body.dir == "rtl") {
				reportPanel.style.right = "inherit";
			} else {
				reportPanel.style.left = "40px";
				if (WMETBZLI) {
					if( WMETBZLI.style.display != "none" ) reportPanel.style.left = "70px";
				}
			}
		}
		if (WMETBZLI) {
			WMETBZLI.style.left = "50px";
			WMETBZLI.style.right = "inherit";
		}
	} else {
		$(".olControlPanZoomBar").css({'left':"",'width':30,'right':10});
		if (reportPanel) {
			if (document.body.dir == "rtl") {
				reportPanel.style.right = "40px";
				if (WMETBZLI) {
					if( WMETBZLI.style.display != "none" ) reportPanel.style.right = "70px";
				}
			} else {
				reportPanel.style.left = "inherit";
			}
		}
		if (WMETBZLI) {
			WMETBZLI.style.left = "inherit";
			WMETBZLI.style.right = "50px";
		}
	}
}

function hideUserInfo() {
	var PSButton = getId('WMEPS_UIButton');
	var userbox = getId('user-box');
	// WME Panel Swap button - move it up off the tabs if user info is hidden
	if (_cbHideUserInfo.checked) {
		userbox.style.padding = '0px';
		$(".user-profile").css({'display':'none'});
		if (PSButton) PSButton.style.top = '-20px';
	} else {
		userbox.style.padding = '20px';
		$(".user-profile").css({'display':'block'});
		if (PSButton) PSButton.style.top = '10px';
	}
}

function shrinkBlackBar() {
	var wm = getId('WazeMap');
	if (_cbShrinkBlackBar.checked) {
		$(".topbar").css({'height':'20px','line-height':'20px','padding':'0 10px'});
		$(".topbar .location-info").css({'font-size':'12px'});
		if (!shrinkBlackBarActive) wm.style.height = (wm.offsetHeight + 10) + 'px';
	} else {
		$(".topbar").css({'height':'30px','line-height':'30px','padding':'0 10px'});
		$(".topbar .location-info").css({'font-size':'15px'});
		if (shrinkBlackBarActive) wm.style.height = (wm.offsetHeight - 10) + 'px';
	}
	shrinkBlackBarActive = _cbShrinkBlackBar.checked;
}

function FALSEcompressSegmentTab() {
	_cbCompressSegmentTab.checked = _cbextraCBSection.checked;
	compressSegmentTab();
}

function compressSegmentTab() {
	var ep=getId('edit-panel');
	if (_cbCompressSegmentTab.checked) {
		if (!compressSegmentTabActive) {
			// shrink address
			addGlobalStyle('#edit-panel .primary-street { font-size: 13px; line-height: 15px; }');
			addGlobalStyle('#edit-panel .address-edit-view .preview .address-edit-btn:not(.disabled) { background-color: yellow; }');
			addGlobalStyle('#edit-panel .segment .address-edit-view, .edit-panel .segment .address-edit-view { margin-bottom: 5px; }');
			//shrink tabs
			addGlobalStyle('#sidebar .nav-tabs li a { padding: 4px; }');
			addGlobalStyle('#sidebar .nav-tabs { margin-bottom: 5px; }');
			//reduce some vertical margins
			addGlobalStyle('#edit-panel .contents { padding-top: 0px; }');
			addGlobalStyle('#edit-panel .form-group { margin-bottom: 2px; line-height: 1; font-size: 11px; }');
			addGlobalStyle('#edit-panel .selection { margin-bottom: 5px; }');
			addGlobalStyle('#sidebar .side-panel-section:not(:last-child) { margin-bottom: 2px; }');
			addGlobalStyle('#sidebar .side-panel-section:not(:last-child)::after { margin-top: 5px; margin-bottom: 2px; }');
			addGlobalStyle('#edit-panel .control-label { margin-bottom: 1px; }');
			addGlobalStyle('#sidebar .controls-container { padding-top: 2px; }');
			addGlobalStyle('#edit-panel .segment .speed-limit label { margin-bottom: 0px }');
			addGlobalStyle('#edit-panel .more-actions { padding-top: 2px }');
			addGlobalStyle('#edit-panel .segment .speed-limit .direction-label, #edit-panel .segment .speed-limit .unit-label { line-height: 2.1em }');

			//shrink dropdown controls & buttons
			addGlobalStyle('#edit-panel button, #edit-panel select, #edit-panel .form-control { font-size: 11px; height: 22px; padding: 0px 12px; }');
			addGlobalStyle('#edit-panel .more-actions button:not(:last-of-type) { margin-bottom: 2px; }');
			//fit road property checkboxes on one line for all three (if text length allows)
			addGlobalStyle('#edit-panel .controls-container { display: inline-block; }');
			addGlobalStyle('#edit-panel .controls-container label { font-size: 12px; line-height: 18px; padding-left: 22px; }');
		 }
	} else {
		if (compressSegmentTabActive) {
			//enlarge address
			addGlobalStyle('#edit-panel .primary-street { font-size: 18px; line-height: 24px; }');
			addGlobalStyle('#edit-panel .address-edit-view .preview .address-edit-btn:not(.disabled) { background-color: inherit; }');
			addGlobalStyle('#edit-panel .segment .address-edit-view, .edit-panel .segment .address-edit-view { margin-bottom: 20px; }');
			//enlarge tabs
			addGlobalStyle('#sidebar .nav-tabs li a { padding: 5px 15px; }');
			addGlobalStyle('#sidebar .nav-tabs { margin-bottom: 20px; }');
			//restore vertical margins
			addGlobalStyle('#edit-panel .contents { padding-top: 20px }');
			addGlobalStyle('#edit-panel .form-group { margin-bottom: 10px; line-height: 1.43; font-size: 13px; }');
			addGlobalStyle('#edit-panel .selection { margin-bottom: 20px; }');
			addGlobalStyle('#sidebar .side-panel-section:not(:last-child) { margin-bottom: 21px; }');
			addGlobalStyle('#sidebar .side-panel-section:not(:last-child)::after { margin-top: 21px; margin-bottom: 21px; }');
			addGlobalStyle('#edit-panel .control-label { margin-bottom: 5px; }');
			addGlobalStyle('#sidebar .controls-container { padding-top: 7px; }');
			addGlobalStyle('#edit-panel .segment .speed-limit label { margin-bottom: 5px }');
			addGlobalStyle('#edit-panel .more-actions { padding-top: 10px }');
			addGlobalStyle('#edit-panel .segment .speed-limit .direction-label, #edit-panel .segment .speed-limit .unit-label { line-height: 2.5em }');
		
			//enlarge dropdown controls & buttons
			addGlobalStyle('#edit-panel button, #edit-panel select, #edit-panel .form-control { font-size: 13px; height: 32px; padding: 6px 12px; }');
			addGlobalStyle('#edit-panel .more-actions button:not(:last-of-type) { margin-bottom: 100px; }');
			//restore road property checkboxes to one line per item
			addGlobalStyle('#edit-panel .controls-container { display: inherit; }');
			addGlobalStyle('#edit-panel .controls-container label { font-size: inherit; line-height: inherit; padding-left: 25px; }');
		 }
	}
	//tweak required if Speedhelper script is installed
	addGlobalStyle('div[id^="spd_"] { line-height: 1.43 }');
	compressSegmentTabActive = _cbCompressSegmentTab.checked
}

function restyleReports() {
	var WMEFP = getId('WMEFP-UR-ALLPM');
	if (_cbRestyleReports.checked) {
		//do stuff
		addGlobalStyle('#panel-container .panel { font-size: 12px; line=height: 1; }');
		addGlobalStyle('#panel-container .problem-edit .header { padding: 5px 10px; line-height: 15px; }');
		addGlobalStyle('#panel-container .problem-edit .problem-data .title { line-height: 22px; }');
		if (WMEFP) WMEFP.style.top = '-2px'; //tweak Fancy permalink button
		addGlobalStyle('#panel-container .problem-edit .conversation.section .new-comment-form { padding: 5px; }');
		addGlobalStyle('#panel-container .problem-edit .conversation.section .new-comment-form textarea { resize: vertical; height: 110px; margin-bottom: 5px; padding: 3px 5px; font-size: 12px; }');
		addGlobalStyle('#panel-container .btn { height: 20px; padding: 0px 10px;}');
		addGlobalStyle('#panel-container .problem-edit .actions .content { padding: 2px 5px;}');
		addGlobalStyle('#panel-container .problem-edit .actions .controls-container label { margin-bottom: 2px; }');
	} else {
		//undo stuff
		addGlobalStyle('#panel-container .panel { font-size: inherit; line=height: inherit; }');
		addGlobalStyle('#panel-container .problem-edit .header { padding: 10px 15px; line-height: 21px; }');
		addGlobalStyle('#panel-container .problem-edit .problem-data .title { line-height: 40px; }');
		if (WMEFP) WMEFP.style.top = '10px'; //un-tweak Fancy permalink button
		addGlobalStyle('#panel-container .problem-edit .conversation.section .new-comment-form { padding: 15px 15px 10px 15px; }');
		addGlobalStyle('#panel-container .problem-edit .conversation.section .new-comment-form textarea { resize: none; height: 70px; margin-bottom: 10px; padding: 6px 10px; font-size: 13px; }');
		addGlobalStyle('#panel-container .btn { height: inherit; padding: 6px 20px;}');
		addGlobalStyle('#panel-container .problem-edit .actions .content { padding: 15px;}');
		addGlobalStyle('#panel-container .problem-edit .actions .controls-container label { margin-bottom: 12px; }');
	}
}

//Helper functions

function addGlobalStyle(css) {
	var head, style;
	head = document.getElementsByTagName('head')[0];
	if (!head) {
		return;
	}
	style = document.createElement('style');
	style.type = 'text/css';
	style.innerHTML = css;
	head.appendChild(style);
}

function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for (var i=0,j=els.length; i<j; i++)
		if (re.test(els[i].className)) a.push(els[i]);
	return a;
}

function getId(node) {
	return document.getElementById(node);
}

// Start it running
setTimeout(initialiseFixUI, 1000);

})();