WME Fix UI

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

当前为 2016-05-30 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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/*
// @version             0.2
// @grant               none
// ==/UserScript==

(function()
{
// global variables
var wmefu_version = "0.2";
var applyCount = 0;
var wmefuinit = 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
	addGlobalStyle('.olControlPanZoomBarFU { left: 10px; top: 9px; }');

	// 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" title="Move zoom bar" /> ' +
			'<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 += '<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">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;


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

		getId('_cbMoveZoomBar').checked = options[1];
	} else {
		getId('_cbMoveZoomBar').checked = true;
	}

	// 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;

			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();
}

function moveZoomBar() {
	var wmap = getId('WazeMap');
	var WMETBZLI = getId('WMETB_ZoomLevelIndicator');
	var zoombar;
	var reportPanel = getId('panel-container');
	
	if (_cbMoveZoomBar.checked) {
		zoomBar = getElementsByClassName('olControlPanZoomBar', wmap)[0];
		if (zoomBar) zoomBar.className = zoomBar.className.replace( /(?:^|\s)olControlPanZoomBar(?!\S)/g , 'olControlPanZoomBarFU' );
		if (reportPanel) {
			reportPanel.style.left = "70px";
			reportPanel.style.position = "absolute";
		}
		if (WMETBZLI) { 
			WMETBZLI.style.left = "50px";
			WMETBZLI.style.right = "";
		}
	} else {
		zoomBar = getElementsByClassName('olControlPanZoomBarFU', wmap)[0];
		if (zoomBar) zoomBar.className = zoomBar.className.replace( /(?:^|\s)olControlPanZoomBarFU(?!\S)/g , 'olControlPanZoomBar' );
		if (reportPanel) {
			reportPanel.style.left = "";
			reportPanel.style.position = "";
		}
		if (WMETBZLI) { 
			WMETBZLI.style.left = "";
			WMETBZLI.style.right = "50px";
		}
	}
}

//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);

})();