Waze Mobile Enhancements

A userscript that makes the WME more useable in Firefox Mobile

目前為 2018-03-17 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Waze Mobile Enhancements
// @namespace   http://tomputtemans.com/
// @description A userscript that makes the WME more useable in Firefox Mobile
// @include     /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @version     0.1.0
// @grant       none
// ==/UserScript==

// Initialisation of the script, this will only run completely one time
function init(e) {
  if (e && e.user == null) {
    return;
  }
  // if you require certain features to be loaded, you can add them here
  if (typeof I18n === 'undefined' || typeof W === 'undefined' ||  typeof W.loginManager === 'undefined') {
    setTimeout(init, 200);
    return;
  }
  setModeChangeListener();
  performScript();
}

// Attempt to hook into the controller that can notify us whenever the editor's mode changes
function setModeChangeListener() {
  if (!W.app || !W.app.modeController) {
    setTimeout(setModeChangeListener, 400);
    return;
  }
  W.app.modeController.model.bind('change:mode', function(model, modeId) {
    if (modeId == 0) { // 0 = Default, 1 = Events
      performScript();
    }
  });
}

function performScript() {
  var viewportMeta = document.createElement('meta');
  viewportMeta.name = 'viewport';
  viewportMeta.content = 'width=device-width, initial-scale=1';
  document.head.appendChild(viewportMeta);
  var styleElement = document.createElement('style');
  document.head.appendChild(styleElement);
  var addRule = function(rule) {
    styleElement.sheet.insertRule(rule, 0);
  };
  // Login dialog modifications
  addRule('.modal-dialog-login { width: 100%; margin: 0 }');
  addRule('.modal-dialog-login .modal-content { width: 350px }');
  addRule('#login-popup { padding: 10px; width: auto }');
  addRule('#login-popup .login-popup-content { display: block }');
  addRule('#login-popup .login-form { padding: 15px; height: auto }');
  addRule('.modal-dialog-login .login-title { font-size: 19px }');
  // Hide a lot of stuff
  addRule('.login-popup-links, .language-select, .welcome-message p, .title-text, #links, #advanced-tools, .WazeControlMousePosition, #user-box { display: none }');
  // Set the default width to several objects so they don't stretch the page
  addRule('.show-sidebar .row-fluid .fluid-fixed, #editor-container { width: 100% }');
  addRule('#editor-container, #editor-container #map { min-width: auto }');
  // Adjust the sidebar and map so they appear on top of eachother
  addRule('.show-sidebar .row-fluid .fluid-fixed { margin-left: 0 }');
  addRule('.row-fluid #sidebar { width: auto }');
  addRule('.edit-area { display: flex; flex-direction: column-reverse }');
  addRule('#WazeMap { height: 40vh !important }');
  // Adjust toolbar
  addRule('.toolbar #search { width: 50px; min-width: auto }');
  addRule('#app-head aside #brand, .group-title { display: none }');
  addRule('.toolbar .toolbar-icon { position: relative; width: 30px }');
  var adjustToolbar = function() {
    if (!document.querySelector('#mode-switcher') || !document.querySelector('#edit-buttons')) {
      setTimeout(adjustToolbar, 100);
      return;
    }
    document.querySelector('#mode-switcher .short-title').textContent = 'Mode';
    /*document.querySelector('#edit-buttons .toolbar-button.waze-icon-save .item-icon').classList.add('fa', 'fa-save');
    document.querySelector('#edit-buttons .toolbar-button.waze-icon-redo .item-icon').classList.add('fa', 'fa-repeat');
    document.querySelector('#edit-buttons .toolbar-button.waze-icon-undo .item-icon').classList.add('fa', 'fa-undo');*/
  };
  adjustToolbar();
  //addRule('#edit-buttons .toolbar-button .item-icon { display: block; top: 8px; position: relative }');
  //addRule('#edit-buttons .toolbar-button .menu-title { display: none }');
  addRule('#edit-buttons .toolbar-button { padding: 0 5px }');
  addRule('#edit-buttons .toolbar-submenu { margin-right: 0 }');
  addRule('#toolbar .toolbar, #search, #edit-buttons { min-width: auto }');
}

init();