From 66cf50c97c7fd4eedca7a5913bc89f89806cf166 Mon Sep 17 00:00:00 2001 From: Paul Traina Date: Tue, 28 Feb 2017 16:42:45 -0800 Subject: [PATCH] Better UI hiding mechanism (uses Alt-H) --- plugins/hide-ui.user.js | 265 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 plugins/hide-ui.user.js diff --git a/plugins/hide-ui.user.js b/plugins/hide-ui.user.js new file mode 100644 index 000000000..838e516f5 --- /dev/null +++ b/plugins/hide-ui.user.js @@ -0,0 +1,265 @@ +// ==UserScript== +// @id iitc-plugin-hide-ui@insane210 +// @name IITC plugin: Hide UI +// @category Misc +// @version 0.1.0.@@DATETIMEVERSION@@ +// @namespace https://github.com/iitc-project/ingress-intel-total-conversion +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description [@@BUILDNAME@@-@@BUILDDATE@@] Hide user interface elements that you don't need or use the screenshot mode (Alt + H) to hide everything. +// @include https://www.ingress.com/intel* +// @include http://www.ingress.com/intel* +// @match https://www.ingress.com/intel* +// @match http://www.ingress.com/intel* +// @include https://www.ingress.com/mission/* +// @include http://www.ingress.com/mission/* +// @match https://www.ingress.com/mission/* +// @match http://www.ingress.com/mission/* +// @grant none +// ==/UserScript== + +@@PLUGINSTART@@ + +// PLUGIN START //////////////////////////////////////////////////////// + +// use own namespace for plugin +window.plugin.hideUI = function() {}; + +// store current state of screenshot mode +window.plugin.hideUI.ScreenshotMode = false; + +window.plugin.hideUI.options = {}; + + +// write settings to local storage +window.plugin.hideUI.saveSettings = function() { + localStorage.setItem('hideUI', JSON.stringify(window.plugin.hideUI.options)); +}; + + +// load settings from local storage +window.plugin.hideUI.loadSettings = function() { + // if settings not available, create new object with default values + if(localStorage.getItem('hideUI') === null) { + var options = { + // id: [boolean hidden, boolean changeable, boolean nested, string name], + portal_highlight_select: [false, true, false, 'Portal highlighter'], + leafletcontrols: [false, true, false, 'Map controls'], + zoom: [false, true, true, 'Zoom buttons'], + drawtools: [false, true, true, 'Drawtools'], + layer: [false, true, true, 'Map layer'], + sidebarwrapper: [false, false, false, 'Sidebar'], + playerstat: [false, true, true, 'Playerinfo'], + gamestat: [false, true, true, 'Global score'], + searchwrapper: [false, true, true, 'Search bar'], + portaldetails: [false, true, true, 'Portal details'], + redeem: [false, true, true, 'Passcode redeem'], + chatwrapper: [false, true, false, 'Chat'], + chatinput: [false, true, true, 'Chat input'], + updatestatus: [false, true, false, 'Status bar'], + bookmarkswrapper: [false, true, false, 'Bookmarks'], + }; + + localStorage.setItem('hideUI', JSON.stringify(options)); + }; + + window.plugin.hideUI.options = JSON.parse(localStorage.getItem('hideUI')); +}; + + +// reset settings back to default values +window.plugin.hideUI.resetSettings = function() { + localStorage.removeItem('hideUI'); + + window.plugin.hideUI.loadSettings(); + window.plugin.hideUI.applySettings(); + + window.plugin.hideUI.showOptions(); +}; + + + +// hide or show UI elements depending on settings +window.plugin.hideUI.applySettings = function() { + for(var id in window.plugin.hideUI.options) { + if(window.plugin.hideUI.options.hasOwnProperty(id)) { + var option = window.plugin.hideUI.options[id]; + + if(option.hasOwnProperty('0')) { + if(option[0] === true) { + $('#' + id).hide(); + + // if chatinput is hidden, move the chat down to the bottom + if(option[3] === 'Chat input') { + $('#chatwrapper').addClass('noinput'); + }; + + // move leaflet controls, when highlighter is hidden + if(option[3] === 'Portal highlighter') { + $('.leaflet-top.leaflet-left').css('padding-top', '0px'); + $('.leaflet-control-scale-line').css('margin-top','0px'); + }; + + } else { + // don't use show(), because it will block css classes to apply + $('#' + id).css('display', ''); + + // if chat is activated, make sure there are messages to display + if(option[3] === 'Chat') { + window.chat.needMoreMessages(); + }; + + // if chatinput is shown, move the chat back up + if(option[3] === 'Chat input') { + $('#chatwrapper').removeClass('noinput'); + }; + + // move leaflet controls, when highlighter is shown + if(option[3] === 'Portal highlighter') { + $('.leaflet-top.leaflet-left').css('padding-top', '20px'); + $('.leaflet-control-scale-line').css('margin-top','25px'); + }; + + }; + } + } + } +}; + + + +// switch screenshot mode on or off +window.plugin.hideUI.toggleScreenshotMode = function() { + if(window.plugin.hideUI.ScreenshotMode) { + $('#chatwrapper').show(); + $('#sidebarwrapper').show(); + $('#updatestatus').show(); + $('#bookmarkswrapper').show(); + $('#portal_highlight_select').show(); + $('#leafletcontrols').show(); + + // show dialogs + for(var id in window.DIALOGS) { + if(window.DIALOGS.hasOwnProperty(id)) { + $('#' + id).parent().show(); + } + } + + window.plugin.hideUI.applySettings(); + + window.plugin.hideUI.ScreenshotMode = false; + } else { + $('#chatwrapper').hide(); + $('#sidebarwrapper').hide(); + $('#updatestatus').hide(); + $('#bookmarkswrapper').hide(); + $('#portal_highlight_select').hide(); + $('#leafletcontrols').hide(); + + // hide dialogs + for(var id in window.DIALOGS) { + if(window.DIALOGS.hasOwnProperty(id)) { + $('#' + id).parent().hide(); + } + } + + window.plugin.hideUI.ScreenshotMode = true; + } +}; + + + +window.plugin.hideUI.showOptions = function() { + var html = '' + + '
' + + '
Always hide:
'; + + for(var id in window.plugin.hideUI.options) { + if(window.plugin.hideUI.options.hasOwnProperty(id)) { + // only show option if element/plugin is loaded + if($('#' + id).length) { + var option = window.plugin.hideUI.options[id]; + + if(option.hasOwnProperty('0')) { + html += '