WME Selection Panel Hider

Hides the selection panel

目前為 2015-04-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name          WME Selection Panel Hider
// @version       0.Test
// @description   Hides the selection panel
// @match         https://editor-beta.waze.com/*editor/*
// @match         https://www.waze.com/*editor/*
// @grant         none
// @author        JJohnston84
// @namespace     https://greasyfork.org/users/10332
// ==/UserScript==

(function()
{ 
  // Delay Init
  setTimeout(init, 654);
  Waze.loginManager.events.register("login", null, init);

  var hideButtonArea;
  var showButtonArea;
  var hasSelection;
  var suppressSelectionPanel;
  
  function init()
  {
    // Tab creation
    var editPanel = document.getElementById('edit-panel');
    var userPanel = document.getElementById('user-info');
    
    hideButtonArea = document.createElement("div");   
    var hidePanelButton = document.createElement('input');
    hidePanelButton.type = 'button';
    hidePanelButton.value = 'Hide Selection Panel';
    hidePanelButton.onclick = sphHideSelectionPanel;        
    hideButtonArea.appendChild(hidePanelButton);
    
    showButtonArea = document.createElement("div");
    var showPanelButton = document.createElement('input');
    showPanelButton.type = 'button';
    showPanelButton.value = 'Show Selection Panel';
    showPanelButton.onclick = sphShowSelectionPanel;        
    showButtonArea.appendChild(showPanelButton);
    
    editPanel.appendChild(hideButtonArea);
    userPanel.appendChild(showButtonArea);
    
    Waze.selectionManager.events.register("selectionchanged", null, sphSelectionChanged);
    sphUpdateVisibility();
  }
  
  function sphHideSelectionPanel()
  {
    suppressSelectionPanel = true;
    Waze.appPresenter.sidebar.editPanel.hide();
    Waze.appPresenter.sidebar.userTabs.show();
    sphUpdateVisibility();
  }
  
  function sphShowSelectionPanel()
  {
    suppressSelectionPanel = false;
    Waze.appPresenter.sidebar.editPanel.show();
    Waze.appPresenter.sidebar.userTabs.hide();
    sphUpdateVisibility();
  }
  
  function sphSelectionChanged()
  {
    hasSelection = Waze.selectionManager.hasSelectedItems();
    sphUpdateVisibility();
  }  
  
  function sphUpdateVisibility()
  {
    var canSeeShowButton = hasSelection && suppressSelectionPanel;
    var canSeeHideButton = hasSelection && !suppressSelectionPanel;
    
    hideButtonArea.style.display = canSeeHideButton ? 'block' : 'none';
    showButtonArea.style.display = canSeeShowButton ? 'block' : 'none';
  }
  
})();